tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Basic patch for passing W9X short DOS paths to TCC.


From: Dave Dodge
Subject: Re: [Tinycc-devel] Basic patch for passing W9X short DOS paths to TCC.
Date: Tue, 14 Apr 2009 13:13:48 -0400
User-agent: Mutt/1.5.17 (2008-05-15)

On Tue, Apr 14, 2009 at 12:21:50PM +0100, lostgallifreyan wrote:
> "Charlie Gordon" <address@hidden> wrote:

> >Also more importantly, do not pass char arguments to
> >tolower/toupper and islower/isupper functions.  'char' may be
> >signed whereas these functions expect an int parameter with a value
> >among those of type unsigned char or EOF.

> As the variable isn't assigned any negative values it's not going to
> be an issue,

If the filename string contains any high-valued characters, such as
accented letters, then accessing it with a char* might produce a
negative char value, and passing that to isupper/islower can be a
problem.

> Actually I forgot the unsigned char bit but even so, it compiled
> without error or warning and it worked.

I think you've mentioned you're new to C, in which case you need to
understand that "compiled without error or warning and it worked"
doesn't mean very much.  C has the concept of "undefined behavior",
which basically means the compiler is allowed to quietly accept the
code but there are no constraints on what it actually does when you
run it.  It might even produce the expected result for some inputs.

Passing a value outside the range of unsigned char (or EOF) to a
function such as isupper is an example of something that produces
undefined behavior.  The program might implicitly cast it to unsigned
char, or change it to 0, or corrupt memory, or crash, or quietly erase
the hard drive and set the printer on fire.  While some of these
actions are perhaps more likely than others, all of them are a correct
result as far as C is concerned.

For example given a blatantly undefined bit of code such as:

  isupper(-20)

gcc does not give a warning, even with -pedantic, -Wall, and -Wextra.
Whatever it actually does when you run it, there is no guarantee that
it will do the same thing in any other C compiler (including other
versions of gcc).

                                                  -Dave Dodge




reply via email to

[Prev in Thread] Current Thread [Next in Thread]