[Buildroot] [PATCH 05/11] dialog: Patch incorrect use of toupper()
Thomas De Schampheleire
patrickdepinguin at gmail.com
Thu Apr 10 08:40:51 UTC 2014
Hi,
On Fri, Apr 4, 2014 at 8:45 AM, Arnout Vandecappelle <arnout at mind.be> wrote:
> On 03/04/14 23:32, Yann E. MORIN wrote:
>> Paul, All,
>>
>> On 2014-04-03 23:01 +0200, Paul Cercueil spake thusly:
>>> On some platforms (e.g. MIPS), the "char" type is signed by default.
>>> The problem is that toupper() takes an int as argument: a signed
>>> char then gets sign-extended to 32bit, which causes an assertion
>>> failure as toupper() verifies that its argument fits in 8 bits.
>>
>> I could not vefrify the assertion that MIPS has signed chars.
>
> I think char is signed on all platforms. At least, it is on all
> platforms I regularly use.
This is not correct.
MIPS and x86 have signed char as default, while ARM and PPC have
unsigned char by default.
Take into account that the compiler can be told to switch the default,
using -fsigned-char or -funsigned-char.
>>
>> However, this change is still corect, since it makes it explicit that we
>> want an unsigned char.
>
> But then we should change all the packages that use toupper and
> tolower... (and also isdigit and isalnum and ...).
>
> Basically, if toupper() asserts in this case, it's a bug in the
> toolchain, not in the package.
I wouldn't classify it as a bug in the toolchain, but rather as an
unfortunate API choice in toupper and friends, or alternatively as an
unfortunate failing of the C specification to explicitly define 'char'
as being signed or unsigned.
Best regards,
Thomas
More information about the buildroot
mailing list