User: Password:
|
|
Subscribe / Log in / New account

Language misfeature

Language misfeature

Posted Jun 22, 2011 22:19 UTC (Wed) by dgm (subscriber, #49227)
In reply to: Language misfeature by samroberts
Parent article: A hole in crypt_blowfish

All is fine and well with both signed and unsigned chars, for as long as you only use them to store chars. This "miss-feature" is only troublesome when you start to do arithmetic with chars, which most library functions do not.

So, if you plan to do arithmetic on characters, better cast them to int or unsigned char, or whatever type has the properties you need for your operations.


(Log in to post comments)

Language misfeature

Posted Jun 23, 2011 4:18 UTC (Thu) by eru (subscriber, #2753) [Link]

This "miss-feature" is only troublesome when you start to do arithmetic with chars, which most library functions do not.

Not just arithmetic. Even indexing an array with a char value will bite the unwary.

Language misfeature

Posted Jun 23, 2011 8:48 UTC (Thu) by kris.shannon (subscriber, #45828) [Link]

Array indexing is pointer arithmetic

Language misfeature

Posted Jun 23, 2011 12:13 UTC (Thu) by dgm (subscriber, #49227) [Link]

I assume you mean comparing the value of characters, taken as numbers. That's arithmetic too.

Language misfeature

Posted Jun 23, 2011 15:27 UTC (Thu) by jani (subscriber, #74547) [Link]

ctype.h functions don't seem like arithmetic, but for the parameter:

"In all cases c is an int, the value of which must be representable as an unsigned char or must equal the value of the macro EOF. If the argument has any other value, the behaviour is undefined."


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds