Jump to content

[patch][7157] in8 config files (debug build only)


Guest mcben

Recommended Posts

nothing really bad but in MS-Studio-debug builds you may run in an assert if you use special chars in mangos.conf (for example 'äá' as db-password)

fix:

commit 1418d8d6e6be9d409e58fd6ec7dcb7419b1b7ccb
Author: McBen <[email protected]>
Date:   Tue Nov 25 13:16:19 2008 +0100

   fixed config file parsing

diff --git a/src/shared/Config/dotconfpp/dotconfpp.cpp b/src/shared/Config/dotconfpp/dotconfpp.cpp
index 6000874..e5c6e87 100644
--- a/src/shared/Config/dotconfpp/dotconfpp.cpp
+++ b/src/shared/Config/dotconfpp/dotconfpp.cpp
@@ -138,7 +138,7 @@ int DOTCONFDocument::cleanupLine(char * line)
            quoted = !quoted;
            ++line; continue;
        }
-        if(isspace(*line) && !quoted){
+        if(isspace((unsigned char)*line) && !quoted){
            *bg++ = 0;
            if(strlen(start)){

@@ -154,7 +154,7 @@ int DOTCONFDocument::cleanupLine(char * line)
                words.push_back(word);
            }
            start = bg;
-            while(isspace(*++line)) {}
+            while(isspace((unsigned char)(*++line))) {}

            continue;
        } 

Link to comment
Share on other sites

Not sure that is proper fix. As i read isspace can be propertly used only for isascii(ch)==true cases.

Anyway cast arg to explicit "unsigned char" can break build at platforms where char type is signed by default.

As i understand cast to "unsigned char" prevent extending sign bit to high part of int.Possible same result (skip negative values) possible just by adding isascii check in appropriate form before isspace check? can you check line variant?

Link to comment
Share on other sites

As i read isspace can be propertly used only for isascii(ch)==true cases
That's not correct. It can also check if an extend (8-bit) char is a 'space' based on the locale settings. ...(something I just learned too :) )

a comment for 'ctype' function from: http://en.wikipedia.org/wiki/Ctype.h

In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined.

...

The correct way to use char arguments is to first cast them to unsigned char.

An 'isascii' check is a possible alternative (doesn't assert on <0) since locales aren't setup anyway.

So something like the following could be a option

-        if(isspace(*line) && !quoted){
+        if(isascii(*line) && isspace(*line) && !quoted){
...
-            while(isspace(*++line)) {}
+            ++line; 
+            while(isascii(*line) && isspace(*line)) {++line;}

Link to comment
Share on other sites

Thank you for link :)

The correct way to use char arguments is to first cast them to unsigned char.

Meaning same as

As i understand cast to "unsigned char" prevent extending sign bit to high part of int.

if char == singled char then

int32 i = (char)(-1) will be -1 (sing bit extended for all high bits of int) (0xFFFFFFFF)

but

int32 i = (unsigned char)(-1) will be 256 (0x000000FF)

And this meaning that your original patch is correct. :)

In [7157] Thank you :)

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use