Hm, finally subscribed here, forgot to... Anyway, I'm using klibc in udev and have added some needed functions (like ftruncate and vsyslog). Should I post the patches here before commiting them to the cvs tree? Also, it looks like ctype.h has a off-by-one bug. isspace(' ') returns 0 right now, but if you change the function from: __ctype_inline int isspace(int __c) { return __ctypes[__c+1] & __ctype_space; */ } to __ctype_inline int isspace(int __c) { return __ctypes[__c] & __ctype_space; */ } things start working again :) In looking at the __ctypes[] array, it is 0 based, so all of the +1 array changes in ctype.h should be removed. Or am I missing something here? I can also check in this change if no one minds. thanks, greg k-h
Greg KH wrote:> Hm, finally subscribed here, forgot to... > > Anyway, I'm using klibc in udev and have added some needed functions > (like ftruncate and vsyslog). Should I post the patches here before > commiting them to the cvs tree? >That would be a good idea.> Also, it looks like ctype.h has a off-by-one bug. isspace(' ') returns > 0 right now, but if you change the function from: > > __ctype_inline int isspace(int __c) > { > return __ctypes[__c+1] & __ctype_space; */ > } > > to > __ctype_inline int isspace(int __c) > { > return __ctypes[__c] & __ctype_space; */ > } > > things start working again :)>> In looking at the __ctypes[] array, it is 0 based, so all of the +1 > array changes in ctype.h should be removed. Or am I missing something > here?> Yes, the first element should be -1 == EOF. However, the array starts: const unsigned char __ctypes[257] = { 0, /* EOF */ 0, /* control character */ 0, /* control character */ 0, /* control character */ 0, /* control character */ 0, /* control character */ 0, /* control character */ 0, /* control character */ __ctype_space, /* BS */ ... there is one too few of the middle lines; I'll check that in right away. -hpa
On Tue, 2003-11-11 at 23:14, Greg KH wrote:> Anyway, I'm using klibc in udev and have added some needed functions > (like ftruncate and vsyslog). Should I post the patches here before > commiting them to the cvs tree?Nah. If you have commit access, fire away.> I can also check in this change if no one minds.Sounds good. Thanks. <b
On Tue, 11 Nov 2003, Greg KH wrote:> __ctype_inline int isspace(int __c) > { > return __ctypes[__c+1] & __ctype_space; */ > }Side remark: Is this supposed to crash if one passes an __c outside the allowed range (ie < -1 || >= sizeof(__ctypes) - 1)?. My understanding of the man page is that it should return 0, not "undefined behavior". --Kai
Kai Germaschewski wrote:> On Tue, 11 Nov 2003, Greg KH wrote: > > >>__ctype_inline int isspace(int __c) >>{ >> return __ctypes[__c+1] & __ctype_space; */ >>} > > > Side remark: Is this supposed to crash if one passes an __c outside the > allowed range (ie < -1 || >= sizeof(__ctypes) - 1)?. My understanding of > the man page is that it should return 0, not "undefined behavior". >Quoth POSIX: "The c argument is an int, the value of which the application shall ensure is a character representable as an unsigned char or equal to the value of the macro EOF. If the argument has any other value, the behavior is undefined." -hpa
Seemingly Similar Threads
- [PATCH] fix off-by-one correction in ctypes
- read.table problem on Linux/Alpha (seg faults caused by isspace(R_EOF)) (PR#303)
- Non-standard conformant usage of ctype functions
- [Bug 377] New: Reduce compiler warnings. Use unsigned args to the ctype.h is*() macros.
- [PATCH] mllib: Add isspace, triml, trimr and trim functions.