Re: [PATCH v2 3/8] tools: Add directory checker for updates

Alyssa Ross
2025-11-14T13:08:47Z

[-- Attachment #1: Type: text/plain, Size: 1241 bytes --]

Demi Marie Obenour <demiobenour@gmail.com> writes:

> On 11/13/25 13:01, Alyssa Ross wrote:
>> Demi Marie Obenour <demiobenour@gmail.com> writes:
>>
>>> On 11/13/25 08:21, Alyssa Ross wrote:
>>>> Demi Marie Obenour <demiobenour@gmail.com> writes:
>>>>
>>>>> + if (entry->d_name[0] == '.')
>>>>> + if (len == 1 || (len == 2 && entry->d_name[1] == '.'))
>>>>> + continue;
>>>>> + unsigned char c = (unsigned char)entry->d_name[0];
>>>>> + if (!((c >= 'A' && c <= 'Z') ||
>>>>> + (c >= 'a' && c <= 'z')))
>>>>> + errx(EXIT_FAILURE, "Filename must begin with an ASCII letter");
>>>>
>>>> Would the comparison not be valid without the cast?
>>>
>>> It would be in this case, but the subsequent cast to int in the error
>>> path assumes that the cast was done. Signed characters are much
>>> trickier and casting to unsigned makes the code easier to reason about.
>>
>> Is it safe to assume 'A' etc. are representable and comparable as
>> unsigned values? (I'm sure it is in practice, but I'd like it if I
>> could be confident this is being done strictly correctly.)
>
> I don't know if the C standard requires it, but we assume it.

Is it a safe assumption, at least on all Linux architectures?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]