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

Demi Marie Obenour
2025-11-14T18:37:40Z

[-- Attachment #1.1.1: Type: text/plain, Size: 1446 bytes --]

On 11/14/25 08:08, Alyssa Ross wrote:
> 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?

I believe this assumption is hard-coded into GCC and Clang, so it's
pretty safe.
--
Sincerely,
Demi Marie Obenour (she/her/hers)

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 7253 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]