一个关于微软的_toupper的bug!

32 篇文章 0 订阅

最近在使用  _toupper 这个函数时,发现了一个微软的一个非常低级的bug,带入如下:

 

char toUpper = _toupper('t');
 char upper = _toupper('T');

 

结果确是: toUpper is T, upper is 4.

看来, _toupper这个函数的实现可能比较笨,只要是传进来,就直接进行减0x20操作,不管你传的是否是小写。

 

 

MSDN的帮助如下:

int toupper(
   int c 
);
int _toupper(
   int c 
);
int towupper(
   wint_t c 
);
int _toupper_l(
   int c ,
   _locale_t locale
);
int _towupper_l(
   wint_t c ,
   _locale_t locale
);

c

Character to convert.

locale

Locale to use.

Each of these routines converts a copy of c, if possible, and returns the result.

If c is a wide character for which iswlower is nonzero and there is a corresponding wide character for which iswupper is nonzero, towupper returns the corresponding wide character; otherwise, towupper returns c unchanged.

There is no return value reserved to indicate an error.

In order for toupper to give the expected results, __isascii and islower must both return nonzero.

 

也没有说使用的注意事项。 可以看出,这应该是一个bug! 希望看到此文章的人,能够注意这个函数,以防用错!

Linux 系统的说明很清楚,APP应该保证传入的是大写字母。 NAME _toupper - transliterate lowercase characters to uppercase SYNOPSIS #include int _toupper(int c); DESCRIPTION The _toupper() macro shall be equivalent to toupper() except that the application shall ensure that the argument c is a lowercase letter.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值