Skip to content
Permalink
Browse files Browse the repository at this point in the history
Release "3.0.7": Fix toPrecision bug "stack overflow #4".
FossilOrigin-Name: 6c7f0c37027d7f890b57cb38f776af39b8f81f03e60ceeb0a231a1d21e24b5de
  • Loading branch information
pmacdona committed Apr 13, 2020
1 parent 5408a6d commit 430ea27
Show file tree
Hide file tree
Showing 20 changed files with 62 additions and 62 deletions.
4 changes: 2 additions & 2 deletions src/jsi.h
Expand Up @@ -4,7 +4,7 @@

#define JSI_VERSION_MAJOR 3
#define JSI_VERSION_MINOR 0
#define JSI_VERSION_RELEASE 6
#define JSI_VERSION_RELEASE 7

#define JSI_VERSION (JSI_VERSION_MAJOR + ((Jsi_Number)JSI_VERSION_MINOR/100.0) + ((Jsi_Number)JSI_VERSION_RELEASE/10000.0))

Expand Down Expand Up @@ -213,7 +213,7 @@ typedef enum {
JSI_DBI_NO_MUTEX =0x0004, /* Disable mutex. */
JSI_DBI_FULL_MUTEX =0x0008, /* Use full mutex. */

JSI_MAX_NUMBER_STRING=50,
JSI_MAX_NUMBER_STRING=100,
JSI_BUFSIZ=8192

} Jsi_Enums; /* Debugging is easier with enums than #define. */
Expand Down
14 changes: 7 additions & 7 deletions src/jsiCmds.c
Expand Up @@ -845,7 +845,7 @@ Jsi_RC jsi_PkgDumpInfo(Jsi_Interp *interp, const char *name, Jsi_Value **ret) {
Jsi_ObjInsert(interp, nobj, "name", Jsi_ValueNewStringDup(interp, name), 0);
Jsi_ObjInsert(interp, nobj, "version", Jsi_ValueNewNumber(interp, ptr->version), 0);
Jsi_ObjInsert(interp, nobj, "lastReq", Jsi_ValueNewNumber(interp, ptr->lastReq), 0);
char buf[200];
char buf[JSI_MAX_NUMBER_STRING*2];
jsi_VersionNormalize(ptr->version, buf, sizeof(buf));
Jsi_ObjInsert(interp, nobj, "verStr", Jsi_ValueNewStringDup(interp, buf), 0);
const char *cp = (ptr->loadFile?ptr->loadFile:"");
Expand Down Expand Up @@ -1192,7 +1192,7 @@ static Jsi_RC SysGetEnvCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this
Jsi_Value *vres;
Jsi_Obj *ores = Jsi_ObjNew(interp);
Jsi_Value *nnv;
char *val, nam[200];
char *val, nam[JSI_BUFSIZ/2];
//Jsi_ObjIncrRefCount(interp, ores);
vres = Jsi_ValueMakeObject(interp, NULL, ores);
//Jsi_IncrRefCount(interp, vres);
Expand Down Expand Up @@ -2700,7 +2700,7 @@ static Jsi_RC DebugAddCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
}
if (bp.line<=0 && !bp.func)
return Jsi_LogError("bad number");
char nbuf[100];
char nbuf[JSI_MAX_NUMBER_STRING];
bp.id = ++interp->debugOpts.breakIdx;
bp.enabled = 1;
snprintf(nbuf, sizeof(nbuf), "%d", bp.id);
Expand All @@ -2718,7 +2718,7 @@ static Jsi_RC DebugRemoveCmd_(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_t
if (interp->breakpointHash)
{
int num;
char nbuf[100];
char nbuf[JSI_MAX_NUMBER_STRING];
if (Jsi_GetIntFromValue(interp, val, &num) != JSI_OK)
return Jsi_LogError("bad number");

Expand Down Expand Up @@ -2766,7 +2766,7 @@ static Jsi_RC DebugInfoCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this
return Jsi_HashKeysDump(interp, interp->breakpointHash, ret, 0);
Jsi_Value *val = Jsi_ValueArrayIndex(interp, args, 0);
int num;
char nbuf[100];
char nbuf[JSI_MAX_NUMBER_STRING];
if (Jsi_GetIntFromValue(interp, val, &num) != JSI_OK)
return Jsi_LogError("bad number");

Expand Down Expand Up @@ -3800,7 +3800,7 @@ static Jsi_RC SysVerConvertCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_
Jsi_Value *flag = Jsi_ValueArrayIndex(interp, args, 1);
if (!val) goto bail;
if (Jsi_ValueIsNumber(interp, val)) {
char buf[200];
char buf[JSI_MAX_NUMBER_STRING*2];
Jsi_Number n;
if (Jsi_GetNumberFromValue(interp, val, &n) != JSI_OK)
goto bail;
Expand Down Expand Up @@ -3953,7 +3953,7 @@ static Jsi_RC SysTimesCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
if (bv)
interp->timesStart = now;
else {
char buf[100];
char buf[JSI_MAX_NUMBER_STRING];
snprintf(buf, sizeof(buf), " (times = %.6f sec)\n", (now-interp->timesStart));
Jsi_Puts(interp, jsi_Stderr, buf, -1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/jsiCode.c
Expand Up @@ -436,7 +436,7 @@ void jsi_code_decode(Jsi_Interp *interp, jsi_OpCode *op, int currentip, char *bu
if (_JSICASTINT(op->op) < 0 || op->op >= OP_LASTOP) {
snprintf(buf, bsiz, "Bad opcode[%d] at %d", op->op, currentip);
}
char nbuf[100];
char nbuf[JSI_MAX_NUMBER_STRING];
snprintf(nbuf, sizeof(nbuf), "%d#%d", currentip, op->Line);
snprintf(buf, bsiz, "%-8s %s ", nbuf, jsi_op_names[op->op]);

Expand Down
22 changes: 11 additions & 11 deletions src/jsiEval.c
Expand Up @@ -287,23 +287,23 @@ static Jsi_RC jsi_logic_less(Jsi_Interp* interp, int i1, int i2) {

static const char *jsi_evalprint(Jsi_Value *v)
{
static char buf[100];
static char buf[JSI_MAX_NUMBER_STRING];
if (!v)
return "nil";
if (v->vt == JSI_VT_NUMBER) {
snprintf(buf, 100, "NUM:%" JSI_NUMGFMT " ", v->d.num);
snprintf(buf, sizeof(buf), "NUM:%" JSI_NUMGFMT " ", v->d.num);
} else if (v->vt == JSI_VT_BOOL) {
snprintf(buf, 100, "BOO:%d", v->d.val);
snprintf(buf, sizeof(buf), "BOO:%d", v->d.val);
} else if (v->vt == JSI_VT_STRING) {
snprintf(buf, 100, "STR:'%s'", v->d.s.str);
snprintf(buf, sizeof(buf), "STR:'%s'", v->d.s.str);
} else if (v->vt == JSI_VT_VARIABLE) {
snprintf(buf, 100, "VAR:%p", v->d.lval);
snprintf(buf, sizeof(buf), "VAR:%p", v->d.lval);
} else if (v->vt == JSI_VT_NULL) {
snprintf(buf, 100, "NULL");
snprintf(buf, sizeof(buf), "NULL");
} else if (v->vt == JSI_VT_OBJECT) {
snprintf(buf, 100, "OBJ:%p", v->d.obj);
snprintf(buf, sizeof(buf), "OBJ:%p", v->d.obj);
} else if (v->vt == JSI_VT_UNDEF) {
snprintf(buf, 100, "UNDEFINED");
snprintf(buf, sizeof(buf), "UNDEFINED");
}
return buf;
}
Expand Down Expand Up @@ -403,7 +403,7 @@ static void jsiDumpInstr(Jsi_Interp *interp, jsi_Pstate *ps, Jsi_Value *_this,
jsi_TryList *trylist, jsi_OpCode *ip, Jsi_OpCodes *opcodes)
{
int i;
char buf[200];
char buf[JSI_MAX_NUMBER_STRING*2];
jsi_code_decode(interp, ip, ip - opcodes->codes, buf, sizeof(buf));
Jsi_Printf(interp, jsi_Stderr, "%p: %-30.200s : THIS=%s, STACK=[", ip, buf, jsi_evalprint(_this));
for (i = 0; i < interp->framePtr->Sp; ++i) {
Expand Down Expand Up @@ -1538,7 +1538,7 @@ Jsi_RC jsi_evalcode_sub(jsi_Pstate *ps, Jsi_OpCodes *opcodes,
break;
}
int bval = 0;
char nbuf[100];
char nbuf[JSI_MAX_NUMBER_STRING];
Jsi_Value *vv;
Jsi_Obj *obj = v->d.obj;
if (!cp) {
Expand Down Expand Up @@ -2155,7 +2155,7 @@ Jsi_RC jsi_evalcode(jsi_Pstate *ps, Jsi_Func *func, Jsi_OpCodes *opcodes,
Jsi_IncrRefCount(interp, fargs);
rc = jsi_evalcode_sub(ps, opcodes, scope, fargs, _this, *vret);
Jsi_DecrRefCount(interp, fargs);
if (interp->didReturn == 0 && !interp->exited) {
if (interp->didReturn == 0 && !interp->exited && rc == JSI_OK) {
if ((interp->evalFlags&JSI_EVAL_RETURN)==0)
Jsi_ValueMakeUndef(interp, vret);
/*if (interp->framePtr->Sp != oldSp) //TODO: at some point after memory refs???
Expand Down
2 changes: 1 addition & 1 deletion src/jsiFilesys.c
Expand Up @@ -1177,7 +1177,7 @@ const char *jsi_GetHomeDir(Jsi_Interp *interp) {

if ((str = getenv("HOME")) == NULL) {
struct passwd pwd, *pw;
char buf[20000];
char buf[JSI_BUFSIZ*3];
if (getpwuid_r(getuid(), &pwd, buf, sizeof(buf), &pw) == 0 && pw->pw_dir)
str = pw->pw_dir;
}
Expand Down
6 changes: 3 additions & 3 deletions src/jsiFunc.c
Expand Up @@ -189,7 +189,7 @@ const char *jsiFuncInfo(Jsi_Interp *interp, Jsi_DString *dStr, Jsi_Func* func, J
Jsi_RC jsi_ArgTypeCheck(Jsi_Interp *interp, int typ, Jsi_Value *arg, const char *p1,
const char *p2, int index, Jsi_Func *func, bool isdefault) {
Jsi_RC rc = JSI_OK;
char idxBuf[200];
char idxBuf[JSI_MAX_NUMBER_STRING*2];
idxBuf[0] = 0;
if (func && arg->vt == JSI_VT_UNDEF && !interp->typeCheck.noundef && index>0 && !isdefault && !(typ&JSI_TT_UNDEFINED)) {
snprintf(idxBuf, sizeof(idxBuf), " arg %d", index);
Expand Down Expand Up @@ -295,7 +295,7 @@ Jsi_RC jsi_StaticArgTypeCheck(Jsi_Interp *interp, int atyp, const char *p1, cons
Jsi_DString dStr = {};
const char *exp = jsi_typeName(interp, typ, &dStr);
const char *vtyp = jsi_TypeName(interp, (Jsi_ttype)atyp);
char idxBuf[200];
char idxBuf[JSI_MAX_NUMBER_STRING*2];
idxBuf[0] = 0;
if (index>0)
snprintf(idxBuf, sizeof(idxBuf), " arg %d", index);
Expand Down Expand Up @@ -339,7 +339,7 @@ Jsi_RC jsi_RunFuncCallCheck(Jsi_Interp *interp, Jsi_Func *func, int argc, const
if (ss==NULL && spec == NULL)
return JSI_OK;
int i, minArgs, maxArgs, mis = 0, varargs = 0;
char nbuf[100];
char nbuf[JSI_MAX_NUMBER_STRING];
if (func->type == FC_BUILDIN) {
varargs = (spec->maxArgs<0);
maxArgs = spec->maxArgs + func->callflags.bits.addargs;
Expand Down
2 changes: 1 addition & 1 deletion src/jsiHash.c
Expand Up @@ -623,7 +623,7 @@ static Jsi_Value *jsi_hashFmtKey(Jsi_MapEntry* h, struct Jsi_MapOpts *opts, int
void *key = Jsi_HashKeyGet(hPtr);
if (opts->keyType == JSI_KEYS_ONEWORD)
return Jsi_ValueNewNumber(opts->interp, (Jsi_Number)(intptr_t)key);
char nbuf[100];
char nbuf[JSI_MAX_NUMBER_STRING];
snprintf(nbuf, sizeof(nbuf), "%p", key);
return Jsi_ValueNewStringDup(opts->interp, nbuf);
}
Expand Down
6 changes: 3 additions & 3 deletions src/jsiInterp.c
Expand Up @@ -700,7 +700,7 @@ static Jsi_RC jsi_InterpDelete(Jsi_Interp *interp, void *ptr) {

Jsi_Interp* Jsi_Main(Jsi_InterpOpts *opts)
{
int rc = 0;
Jsi_RC rc = JSI_OK;
Jsi_Interp* interp = NULL;
int argc = 0, first = 1;
char **argv = NULL;
Expand Down Expand Up @@ -929,7 +929,7 @@ Jsi_Interp* Jsi_Main(Jsi_InterpOpts *opts)
}
if (jsi_deleted) //TODO: rationalize jsi_deleted, jsi_exitCode, etc
return jsi_DoExit(rc==JSI_EXIT?NULL:interp, jsi_exitCode);
if (rc == 0) {
if (rc == JSI_OK) {
/* Skip output from an ending semicolon which evaluates to undefined */
Jsi_Value *ret = Jsi_ReturnValue(interp);
if (!Jsi_ValueIsType(interp, ret, JSI_VT_UNDEF)) {
Expand All @@ -940,7 +940,7 @@ Jsi_Interp* Jsi_Main(Jsi_InterpOpts *opts)
}
} else {
if (!interp->parent && !interp->isHelp)
fputs("ERROR\n", stderr);
fprintf(stderr, "ERROR: %s\n", interp->errMsgBuf);
return jsi_DoExit(interp, 1);
}

Expand Down
2 changes: 1 addition & 1 deletion src/jsiJSON.c
Expand Up @@ -6,7 +6,7 @@

static void jsonNewDString(Jsi_Interp *interp, Jsi_DString *dStr, const char* str, int len)
{
char buf[100], *dp = buf;
char buf[JSI_MAX_NUMBER_STRING], *dp = buf;
const char *cp = str;
int ulen;

Expand Down
4 changes: 2 additions & 2 deletions src/jsiMySql.c
Expand Up @@ -1169,7 +1169,7 @@ static void mdbDeleteCmd(MySqlObj *jdb)
*/
static void mdbEvalSetColumnJSON(MyDbEvalContext *p, int iCol, Jsi_DString *dStr) {
Jsi_Interp *interp = p->jdb->interp;
char nbuf[200];
char nbuf[JSI_MAX_NUMBER_STRING];
MysqlPrep *prep = p->prep;
SqlFieldResults *field = prep->fieldResult+iCol;
if (field->isnull) {
Expand Down Expand Up @@ -1219,7 +1219,7 @@ static void mdbEvalSetColumnJSON(MyDbEvalContext *p, int iCol, Jsi_DString *dStr

static void mdbEvalSetColumn(MyDbEvalContext *p, int iCol, Jsi_DString *dStr) {
//Jsi_Interp *interp = p->jdb->interp;
char nbuf[200];
char nbuf[JSI_MAX_NUMBER_STRING];
MysqlPrep *prep = p->prep;
SqlFieldResults *field = prep->fieldResult+iCol;
Jsi_Interp *interp = p->jdb->interp;
Expand Down
10 changes: 5 additions & 5 deletions src/jsiNumber.c
Expand Up @@ -123,7 +123,7 @@ static Jsi_RC NumberConstructor(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *
static Jsi_RC NumberToFixedCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
char buf[100];
char buf[JSI_MAX_NUMBER_STRING+1];
int prec = 0, skip = 0;
Jsi_Number num;
Jsi_Value *v;
Expand All @@ -141,14 +141,14 @@ static Jsi_RC NumberToFixedCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_
static Jsi_RC NumberToPrecisionCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
char buf[100];
char buf[JSI_MAX_NUMBER_STRING*2];
int prec = 0, skip = 0;
Jsi_Number num;
Jsi_Value *v;
ChkStringN(_this, funcPtr, v);
if (Jsi_GetIntFromValue(interp, Jsi_ValueArrayIndex(interp, args, skip), &prec) != JSI_OK)
return JSI_ERROR;
if (prec<=0) return JSI_ERROR;
if (prec<=0 || prec>JSI_MAX_NUMBER_STRING) return Jsi_LogError("precision must be between 1 and %d", JSI_MAX_NUMBER_STRING);
Jsi_GetDoubleFromValue(interp, v, &num);
snprintf(buf, sizeof(buf),"%.*" JSI_NUMFFMT, prec, num);
if (num<0)
Expand All @@ -163,7 +163,7 @@ static Jsi_RC NumberToPrecisionCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Valu
static Jsi_RC NumberToExponentialCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
char buf[100];
char buf[JSI_MAX_NUMBER_STRING+1];
int prec = 0, skip = 0;
Jsi_Number num;
Jsi_Value *v;
Expand Down Expand Up @@ -191,7 +191,7 @@ static Jsi_RC NumberToExponentialCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Va
static Jsi_RC NumberToStringCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
char buf[500];
char buf[JSI_MAX_NUMBER_STRING+1];
int radix = 10, skip = 0, argc = Jsi_ValueGetLength(interp, args);
Jsi_Number num;
Jsi_Value *v;
Expand Down
2 changes: 1 addition & 1 deletion src/jsiOptions.c
Expand Up @@ -1876,7 +1876,7 @@ static Jsi_RC jsi_BitfieldToValue(Jsi_Interp *interp, Jsi_OptionSpec* spec, Jsi_
if (JSI_OK != jsi_EnumToValue(interp, eSpec, outValue, outStr, (void*)&nval, flags))
return JSI_ERROR;
} else if (outStr) {
char obuf[100];
char obuf[JSI_MAX_NUMBER_STRING];
snprintf(obuf, sizeof(obuf), "%" PRId64, inum);
Jsi_DSAppend(outStr, obuf, NULL);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/jsiPstate.c
Expand Up @@ -239,8 +239,8 @@ int jsi_PstateSetFile(jsi_Pstate *ps, Jsi_Channel fp, int skipbang)
l->d.fp = fp;
Jsi_Rewind(ps->interp, fp);
if (skipbang) {
char buf[1000];
if (Jsi_Gets(ps->interp, fp, buf, 1000) && (buf[0] != '#' || buf[1] != '!')) {
char buf[JSI_BUFSIZ];
if (Jsi_Gets(ps->interp, fp, buf, sizeof(buf)) && (buf[0] != '#' || buf[1] != '!')) {
Jsi_Rewind(ps->interp, fp);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/jsiRegexp.c
Expand Up @@ -162,7 +162,7 @@ Jsi_RC Jsi_RegExpMatch(Jsi_Interp *interp, Jsi_Value *pattern, const char *v, in
int r = regexec(reg, v, 1, &pos, regexec_flags);

if (r >= REG_BADPAT) {
char buf[100];
char buf[JSI_MAX_NUMBER_STRING];

regerror(r, reg, buf, sizeof(buf));
return Jsi_LogError("error while matching pattern: %s", buf);
Expand Down
10 changes: 5 additions & 5 deletions src/jsiSqlite.c
Expand Up @@ -1395,7 +1395,7 @@ static void jsiSqlFunc(sqlite3_context *context, int argc, sqlite3_value**argv)

bool b;
if( rc != JSI_OK) {
char buf[250];
char buf[JSI_BUFSIZ];
snprintf(buf, sizeof(buf), "error in function: %.200s", p->zName);
sqlite3_result_error(context, buf, -1);

Expand Down Expand Up @@ -1760,7 +1760,7 @@ static void dbEvalRowInfo(
*/
static void dbEvalSetColumnJSON(DbEvalContext *p, int iCol, Jsi_DString *dStr) {
Jsi_Interp *interp = p->jdb->interp;
char nbuf[200];
char nbuf[JSI_MAX_NUMBER_STRING];

sqlite3_stmt *pStmt = p->pPreStmt->pStmt;

Expand Down Expand Up @@ -1810,7 +1810,7 @@ static void dbEvalSetColumnJSON(DbEvalContext *p, int iCol, Jsi_DString *dStr) {

static void dbEvalSetColumn(DbEvalContext *p, int iCol, Jsi_DString *dStr) {
Jsi_Interp *interp = p->jdb->interp;
char nbuf[200];
char nbuf[JSI_MAX_NUMBER_STRING];

sqlite3_stmt *pStmt = p->pPreStmt->pStmt;

Expand Down Expand Up @@ -2560,7 +2560,7 @@ static void dbOutputQuotedString(Jsi_DString *dStr, const char *z) {
*/
static void dbOutputHexBlob(Jsi_DString *dStr, const void *pBlob, int nBlob){
int i;
char out[100], *zBlob = (char *)pBlob;
char out[JSI_MAX_NUMBER_STRING], *zBlob = (char *)pBlob;
Jsi_DSAppend(dStr, "X'", NULL);
for(i=0; i<nBlob; i++){ snprintf(out, sizeof(out),"%02x",zBlob[i]&0xff);Jsi_DSAppend(dStr, out, NULL); }
Jsi_DSAppend(dStr, "'", NULL);
Expand Down Expand Up @@ -4393,7 +4393,7 @@ static int jsi_DbQuery(Jsi_Db *jdb, Jsi_CDataDb *dbopts, const char *query)

DbEvalContext sEval = {};
int insert = 0, replace = 0, update = 0;
char nbuf[100], *bPtr;
char nbuf[JSI_MAX_NUMBER_STRING], *bPtr;
#ifdef JSI_DB_DSTRING_SIZE
JSI_DSTRING_VAR(dStr, JSI_DB_DSTRING_SIZE);
#else
Expand Down
4 changes: 2 additions & 2 deletions src/jsiString.c
Expand Up @@ -724,7 +724,7 @@ static Jsi_RC StringReplaceCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_
int match = regexec(regex, p, MAX_SUBREGEX, pmatch, regexec_flags);

if (match >= REG_BADPAT) {
char buf[100];
char buf[JSI_MAX_NUMBER_STRING];

regerror(match, regex, buf, sizeof(buf));
Jsi_LogError("error while matching pattern: %s", buf);
Expand Down Expand Up @@ -895,7 +895,7 @@ static Jsi_RC StringSearchCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_t
return JSI_OK;
}
if (r >= REG_BADPAT) {
char buf[100];
char buf[JSI_MAX_NUMBER_STRING];

regerror(r, reg, buf, sizeof(buf));
Jsi_LogError("error while matching pattern: %s", buf);
Expand Down

0 comments on commit 430ea27

Please sign in to comment.