From: andy Date: Mon, 25 Aug 2008 16:53:34 +0000 (+0000) Subject: Fix typing error with fgetc in readln(). On most boxes, this would X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e55f55cd3e82e869937322de888721445af079b9;p=simgear.git Fix typing error with fgetc in readln(). On most boxes, this would cause a spurious EOF when there was a 0xff in the stream. But on PPC, char is unsigned (for reasons known only to IBM) and it would loop forever. --- diff --git a/simgear/nasal/iolib.c b/simgear/nasal/iolib.c index c08296a9..16d31338 100644 --- a/simgear/nasal/iolib.c +++ b/simgear/nasal/iolib.c @@ -143,7 +143,7 @@ static naRef f_open(naContext c, naRef me, int argc, naRef* args) // frees buffer before tossing an error static int getcguard(naContext ctx, FILE* f, void* buf) { - char c; + int c; naModUnlock(); c = fgetc(f); naModLock(); if(ferror(f)) { naFree(buf); @@ -159,8 +159,8 @@ static naRef f_readln(naContext ctx, naRef me, int argc, naRef* args) { naRef result; struct naIOGhost* g = argc==1 ? ioghost(args[0]) : 0; - int i=0, sz = 128; - char c, *buf; + int i=0, sz = 128, c, c2; + char *buf; if(!g || g->type != &naStdIOType) naRuntimeError(ctx, "bad argument to readln()"); buf = naAlloc(sz); @@ -168,7 +168,7 @@ static naRef f_readln(naContext ctx, naRef me, int argc, naRef* args) c = getcguard(ctx, g->handle, buf); if(c == EOF || c == '\n') break; if(c == '\r') { - char c2 = getcguard(ctx, g->handle, buf); + c2 = getcguard(ctx, g->handle, buf); if(c2 != EOF && c2 != '\n') if(EOF == ungetc(c2, g->handle)) break;