Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #19006

Re: Floating point support not loaded

From Eric Sosman <esosman@ieee-dot-org.invalid>
Newsgroups comp.lang.c
Subject Re: Floating point support not loaded
Date 2012-03-24 14:27 -0400
Organization A noiseless patient Spider
Message-ID <jkl3m3$s8j$1@dont-email.me> (permalink)
References <58a3b95c-55ea-4d4c-9da0-4c837348b5d0@12g2000vba.googlegroups.com> <jkkdb0$v8g$1@dont-email.me> <9a135814-206f-482c-a3f0-6e199b690b31@l7g2000vbw.googlegroups.com> <2ce3e2be-5693-4766-847b-363c75ac22fd@i2g2000vbv.googlegroups.com>

Show all headers | View raw


On 3/24/2012 1:51 PM, lolzy@live.nl wrote:
> /*
>   * Encode a string according to http://tools.ietf.org/html/rfc3986#section-2.1.
> */
> void urlEncode(char *string)
> {
> 	float test = sqrt(9);

     I guess this ensures the presence of floating-point support.
Seems like there ought to be a more direct way, though: possibly
a compiler or linker command-line option or something of that kind.

> 	int i = 0;
> 	char *buf = KhSafeMalloc(((strlen(string) * 3) + 1) * sizeof(char)),
> *end = buf;
>
> 	while (string[i] != '\0')
> 	{
> 		if ((unsigned char) isalnum(string[i]) || string[i] == '-' ||

     Not quite: `isalnum((unsigned char)string[i])' is what you want.

     Here's the deal: In the dim mists of prehistory, the people who
invented what has become <ctype.h> thought it would be a good idea if
the functions could be applied not only to `char' values, but to any
value one might read from an input stream.  A `char' value read by
the getc() function or any of its relatives is always non-negative,
making it easy to distinguish actual input from the special, negative
EOF value that means "no input: finished or failed."  So that's what
the isxxx() functions require for their arguments: Either the negative
EOF value or a non-negative `char' value.

     There are several problems with this scheme.  The one that's of
concern here is that `char' itself is unsigned on some systems, but
signed on others.  The "basic execution character set" values are
all non-negative (6.2.5p3), but additional characters may be positive
or negative: Try a few like âĕïòú and you might see negative values.
To avoid this issue, getc() and friends return actual characters as
the values they would have if converted to `unsigned char' and then
stored in an `int'.

     But if you pluck a `char' value from a string, you might wind
up with a negative value (for some characters on some systems).
If you feed this value to isxxx() or toxxx() you are asking for
trouble: The *only* valid negative argument value for these functions
is EOF, and the behavior is undefined if you pass some other negative
value (7.4p1).  On many systems these "functions" are implemented as
macros that use the argument as an array index, and you'll wind up
indexing into the never-never-land that lies before the array, with
unpredictable consequences.  It's unfortunate, but in the name of
"backward compatibility" it's too late to change.

> string[i] == '_' || string[i] == '.' || string[i] == '~')
> 			*end++ = string[i];
> 		else if (string[i] == ' ')
> 			*end++ = '+';
> 		else
> 			end += sprintf(end, "%%%.2X", string[i]);
>
> 		++i;
> 	}
>
> 	*end = '\0';
> 	strcpy(string, buf);
> 	free(buf);
> }
>
>
> 'float test = sqrt(9)' did the trick :-)


-- 
Eric Sosman
esosman@ieee-dot-org.invalid

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Floating point support not loaded lolzy@live.nl - 2012-03-24 03:04 -0700
  Re: Floating point support not loaded Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-03-24 04:15 -0700
  Re: Floating point support not loaded Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-03-24 08:05 -0400
    Re: Floating point support not loaded lolzy@live.nl - 2012-03-24 10:15 -0700
      Re: Floating point support not loaded lolzy@live.nl - 2012-03-24 10:51 -0700
        Re: Floating point support not loaded Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-03-24 14:27 -0400
        Re: Floating point support not loaded Keith Thompson <kst-u@mib.org> - 2012-03-24 14:34 -0700
          Re: Floating point support not loaded Markus Wichmann <nullplan@gmx.net> - 2012-03-26 10:29 +0200
            Re: Floating point support not loaded James Kuyper <jameskuyper@verizon.net> - 2012-03-26 06:48 -0400
              Re: Floating point support not loaded Markus Wichmann <nullplan@gmx.net> - 2012-03-26 13:31 +0200
                Re: Floating point support not loaded James Kuyper <jameskuyper@verizon.net> - 2012-03-26 08:42 -0400

csiph-web