I wrote:
> Plib's behavior in the lines touched by this patch is platform
> independent.

And this bit of the patch is just flat wrong.  The original version
finds the first "_" in the string and nul-terminates it at that
location.  The "fixed" code it a complete no-op.

-               char *p = strrchr(fname,'_');
+       char *dupfname = strdup( fname);
+       char *p = strrchr( dupfname,'_');
     if (p != 0) {
       *p = '\0';

The confusion seems to be that Microsoft declared strchr() as taking
and returning a const pointer.  Which is broken, because strchr()
returns a pointer into the *same* memory it got.  The constness needs
to be synchronized between the pointers, which is outside the
capabilities of the C language.  So programmers have to choose between
a slightly "unsafe" function that drops const and one that requires a
cast to use with a non-const string.

Instead of adding the cast, you have copied the *whole* string to a
new buffer, terminated that one instead of the original string, and
then dropped it on the floor leaving the original string untouched.

Andy



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to