Kompatibilitaets-Fix negative ids.

This commit is contained in:
Enno Rehling 2008-04-27 11:58:14 +00:00
parent ddcbce5092
commit 3a5873a0f6
3 changed files with 12 additions and 6 deletions

View File

@ -33,6 +33,7 @@
#include <util/unicode.h>
/* libc includes */
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <wctype.h>
@ -216,7 +217,7 @@ read_groups(struct storage * store, faction * f)
ally * a;
variant fid;
fid.i = store->r_id(store);
if (fid.i<0) break;
if (fid.i<=0) break;
if (store->version<STORAGE_VERSION && fid.i==0) break;
a = malloc(sizeof(ally));
*pa = a;

View File

@ -31,11 +31,15 @@ atoi36(const char * str)
{
/* cannot use strtol, becuase invalid strings will cause crash */
const unsigned char * s = (const unsigned char *)str;
int i = 0;
int i = 0, sign = 1;
assert(s);
if(!(*s)) return 0;
while(isspace(*(unsigned char*)s)) ++s;
if (*s == '-') {
sign = -1;
++s;
}
while(isalnum(*(unsigned char*)s)) {
if (isupper(*(unsigned char*)s)) i = i*36 + (*s)-'A' + 10;
else if (islower(*(unsigned char*)s)) i=i*36 + (*s)-'a' + 10;
@ -45,7 +49,7 @@ atoi36(const char * str)
++s;
}
if (i<0) return 0;
return i;
return i * sign;
}
const char*

View File

@ -12,14 +12,15 @@ end
test_locales()
local now = os.clock()
read_game("566.dat", "binary")
--read_game("566", "text")
--read_game("566.dat", "binary")
read_game("566.txt", "text")
--write_game("566.txt", "text")
local elapsed = os.clock() - now
print(elapsed)
-- text: 50.574
-- bin0: 19.547
-- bin1: 18.953
write_game("566.dat", "binary")
--write_game("566.dat", "binary")
io.stdin:read("*line")