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

Language misfeature

Language misfeature

Posted Jun 22, 2011 20:47 UTC (Wed) by daney (subscriber, #24551)
In reply to: Language misfeature by eru
Parent article: A hole in crypt_blowfish

You can always do:

#include <stdint.h>

And use uint8_t (or int8_t) instead of char.


(Log in to post comments)

Language misfeature

Posted Jun 22, 2011 21:49 UTC (Wed) by samroberts (guest, #46749) [Link]

Only if you ignore or suppress sign mismatch warnings (but doing so can also lead to this kind of bug), or code entirely in your own world, never using string literals (the type of "xx" is defined to be "char*") or exchanging data with library functions accepting or returning char*.

Language misfeature

Posted Jun 22, 2011 22:19 UTC (Wed) by dgm (subscriber, #49227) [Link]

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.

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