qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-trivial] [Qemu-devel] [PATCH for-2.10] Use qemu_tolower() and


From: Eric Blake
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH for-2.10] Use qemu_tolower() and qemu_toupper(), not tolower() and toupper()
Date: Thu, 20 Jul 2017 14:04:20 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

On 07/20/2017 01:57 PM, Richard Henderson wrote:
> On 07/20/2017 08:48 AM, Eric Blake wrote:
>> On 07/20/2017 01:26 PM, Richard Henderson wrote:
>>> On 07/20/2017 06:31 AM, Peter Maydell wrote:
>>>> gdbstub.c:914:13: warning: array subscript has type 'char'
>>>>
>>>> This reflects the fact that toupper() and tolower() give
>>>> undefined behaviour if they are passed a value that isn't
>>>> a valid 'unsigned char' or EOF.
>>>
>>> Not saying we shouldn't use qemu_tolower etc, but this statement is not
>>> true at all.  Officially, the argument to toupper and tolower is type
>>> int.
>>
>> Correct. Officially, the argument to toupper is an int, but
>> range-constrained to the set of ints that represent either EOF or an
>> unsigned char value.
> 
> Please show me that language in C11 (or any other version).

POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/toupper.html

> For toupper(): [CX] [Option Start]  The functionality described on this 
> reference page is aligned with the ISO C standard. Any conflict between the 
> requirements described here and the ISO C standard is unintentional. This 
> volume of POSIX.1-2008 defers to the ISO C standard. [Option End]
> 
> The toupper() [CX] [Option Start]  and toupper_l() [Option End]  functions 
> have as a domain a type int, the value of which is representable as an 
> unsigned char or the value of EOF. If the argument has any other value, the 
> behavior is undefined.

So POSIX is claiming it is a C99 requirement.

And I found this in C11:

7.4 Character handling <ctype.h>
1 The header <ctype.h> declares several functions useful for classifying
and mapping
characters. 198) In all cases the argument is an int, the value of which
shall be
representable as an unsigned char or shall equal the value of the macro
EOF. If the
argument has any other value, the behavior is undefined.


-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]