Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Eric Sosman <esosman@ieee-dot-org.invalid> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Floating point support not loaded |
| Date | 2012-03-24 08:05 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <jkkdb0$v8g$1@dont-email.me> (permalink) |
| References | <58a3b95c-55ea-4d4c-9da0-4c837348b5d0@12g2000vba.googlegroups.com> |
On 3/24/2012 6:04 AM, lolzy@live.nl wrote:
> Good day!
>
>
> When I use this function, I get the following output:
>
> runtime error R6002
> - floating point support not loaded
This sounds very much like Question 14.13 on the comp.lang.c
Frequently Asked Questions (FAQ) page at <http://www.c-faq.com/>,
although it may be different in detail. That's a reasonable place
to start, anyhow.
Your code has other problems, though. I've spotted a few:
>
> Note:
> - safeMalloc() is a safe function with error handling.
> - sizeof(string)>= sizeof(buf) (so no overflows)
>
>
>
> /*
> * Encode a string according to http://tools.ietf.org/html/rfc3986#section-2.1.
> */
> void urlEncode(char *string)
> {
> int i = 0;
> char *buf = safeMalloc(((strlen(string) * 3) + 1) * sizeof(char));
> buf[0] = '\0';
You probably won't need this (see below).
> while (string[i] != '\0')
> {
> if (isalnum(string[i]) || string[i] == '-' || string[i] == '_' ||
> string[i] == '.' || string[i] == '~' || string[i] == ' ')
Use `isalnum( (unsigned char)string[i] )' as the first part of
the test. Otherwise you're likely to get into trouble when dealing
with "exotic" characters on systems where `char' is signed.
> {
> if (string[i] == ' ') string[i] = '+';
It might have been smoother to treat the space character as a
case of its own. As things stand, you're making a special test to
include it in this case, and then making another test to give it
special treatment. (General principle: If you find yourself writing
two tests for the same condition, consider whether rearranging to
eliminate one test would lead to simpler code.)
> sprintf(buf, "%s%c", buf, string[i]);
Here's where the really serious trouble begins: "If copying
takes place between objects that overlap, the behavior is undefined"
(section 7.21.6.6 paragraph 2 of the C Standard). In this instance,
the code tries to copy from `buf' to `buf', and since `buf' clearly
overlaps itself there's no telling what might happen. One remedy
might be to append the new material without copying the old:
sprintf(buf + strlen(buf), "%c", string[i]);
To my taste, though, that's a lot of machinery just to copy a single
character from one place to another! If I were writing the code, I
think I'd maintain a second pointer like `char *end;' whose job is
to point just after the last character deposited in `buf'. It would
start out equal to `buf' and would advance as characters were
appended. Using such a pointer, you could replace this line with
*end++ = string[i];
... which I think you'll agree is a much "lighter-weight" solution.
Note that this copies only one character, meaning that `buf' will
not have a '\0' at the end -- but that's all right, because you
don't need `buf' to hold a well-formed string until you've finished
converting all of `string'.
> }
> else
> {
> sprintf(buf, "%s%%%.2X", buf, string[i]);
Same problem with overlap, with similar solutions. In this
case it's probably easier to let sprintf() take care of the hex
conversion, so you'd have
end += sprintf(end, "%%%.2X", string[i]);
> }
>
> ++i;
> }
If you're using the `end' pointer as I suggest, at this point
you need to supply a '\0' to ensure a well-formed string before
calling strcpy() on it:
*end = '\0';
> strcpy(string, buf);
> free(buf);
> }
--
Eric Sosman
esosman@ieee-dot-org.invalid
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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