1
0
Fork 0

don't truncate strings output by print() to 1024 bytes. This was apparently

done for performance reasons, but print() should be able to output any
valid string, and when SG_LOG uses strings and streams already, then we
can use that here, too. (Not discussed with Andy yet.)
This commit is contained in:
mfranz 2007-01-28 12:16:37 +00:00
parent 98aa76ad33
commit 978b7145b1

View file

@ -232,24 +232,15 @@ static naRef f_setprop(naContext c, naRef me, int argc, naRef* args)
// make sure it appears. Is there better way to do this? // make sure it appears. Is there better way to do this?
static naRef f_print(naContext c, naRef me, int argc, naRef* args) static naRef f_print(naContext c, naRef me, int argc, naRef* args)
{ {
#define BUFLEN 1024 string buf;
char buf[BUFLEN + 1];
buf[BUFLEN] = 0; // extra nul to handle strncpy brain damage
buf[0] = 0; // Zero-length in case there are no arguments
char* p = buf;
int buflen = BUFLEN;
int n = argc; int n = argc;
for(int i=0; i<n; i++) { for(int i=0; i<n; i++) {
naRef s = naStringValue(c, args[i]); naRef s = naStringValue(c, args[i]);
if(naIsNil(s)) continue; if(naIsNil(s)) continue;
strncpy(p, naStr_data(s), buflen); buf += naStr_data(s);
p += naStr_len(s);
buflen = BUFLEN - (p - buf);
if(buflen <= 0) break;
} }
SG_LOG(SG_GENERAL, SG_ALERT, buf); SG_LOG(SG_GENERAL, SG_ALERT, buf);
return naNil(); return naNum(buf.length());
#undef BUFLEN
} }
// fgcommand() extension function. Executes a named command via the // fgcommand() extension function. Executes a named command via the