ref: 3e3c382a0c8ccc2bec4a581115fc8a86f174d87e
parent: 7c7a9cd78f339b754cc3d6a8d97b2b71845c7024
author: Tor Andersson <tor.andersson@artifex.com>
date: Wed Apr 27 12:26:00 EDT 2016
Avoid using 'unsigned int'. Mixing signed and unsigned ints is just a plain headache.
--- a/jsarray.c
+++ b/jsarray.c
@@ -2,40 +2,40 @@
#include "jsvalue.h"
#include "jsbuiltin.h"
-unsigned int js_getlength(js_State *J, int idx)
+int js_getlength(js_State *J, int idx)
{
- unsigned int len;
+ int len;
js_getproperty(J, idx, "length");
- len = js_touint32(J, -1);
+ len = js_tointeger(J, -1);
js_pop(J, 1);
return len;
}
-void js_setlength(js_State *J, int idx, unsigned int len)
+void js_setlength(js_State *J, int idx, int len)
{
js_pushnumber(J, len);
- js_setproperty(J, idx < 0 ? idx - 1: idx, "length");
+ js_setproperty(J, idx < 0 ? idx - 1 : idx, "length");
}
-int js_hasindex(js_State *J, int idx, unsigned int i)
+int js_hasindex(js_State *J, int idx, int i)
{
char buf[32];
return js_hasproperty(J, idx, js_itoa(buf, i));
}
-void js_getindex(js_State *J, int idx, unsigned int i)
+void js_getindex(js_State *J, int idx, int i)
{
char buf[32];
js_getproperty(J, idx, js_itoa(buf, i));
}
-void js_setindex(js_State *J, int idx, unsigned int i)
+void js_setindex(js_State *J, int idx, int i)
{
char buf[32];
js_setproperty(J, idx, js_itoa(buf, i));
}
-void js_delindex(js_State *J, int idx, unsigned int i)
+void js_delindex(js_State *J, int idx, int i)
{
char buf[32];
js_delproperty(J, idx, js_itoa(buf, i));
@@ -43,7 +43,7 @@
static void jsB_new_Array(js_State *J)
{
- unsigned int i, top = js_gettop(J);
+ int i, top = js_gettop(J);
js_newarray(J);
@@ -65,8 +65,8 @@
static void Ap_concat(js_State *J)
{
- unsigned int i, top = js_gettop(J);
- unsigned int n, k, len;
+ int i, top = js_gettop(J);
+ int n, k, len;
js_newarray(J);
n = 0;
@@ -90,8 +90,8 @@
char * volatile out = NULL;
const char *sep;
const char *r;
- unsigned int seplen;
- unsigned int k, n, len;
+ int seplen;
+ int k, n, len;
len = js_getlength(J, 0);
@@ -142,7 +142,7 @@
static void Ap_pop(js_State *J)
{
- unsigned int n;
+ int n;
n = js_getlength(J, 0);
@@ -158,8 +158,8 @@
static void Ap_push(js_State *J)
{
- unsigned int i, top = js_gettop(J);
- unsigned int n;
+ int i, top = js_gettop(J);
+ int n;
n = js_getlength(J, 0);
@@ -175,7 +175,7 @@
static void Ap_reverse(js_State *J)
{
- unsigned int len, middle, lower;
+ int len, middle, lower;
len = js_getlength(J, 0);
middle = len / 2;
@@ -182,7 +182,7 @@
lower = 0;
while (lower != middle) {
- unsigned int upper = len - lower - 1;
+ int upper = len - lower - 1;
int haslower = js_hasindex(J, 0, lower);
int hasupper = js_hasindex(J, 0, upper);
if (haslower && hasupper) {
@@ -203,7 +203,7 @@
static void Ap_shift(js_State *J)
{
- unsigned int k, len;
+ int k, len;
len = js_getlength(J, 0);
@@ -228,7 +228,7 @@
static void Ap_slice(js_State *J)
{
- unsigned int len, s, e, n;
+ int len, s, e, n;
double sv, ev;
js_newarray(J);
@@ -248,7 +248,7 @@
js_setindex(J, -2, n);
}
-static int compare(js_State *J, unsigned int x, unsigned int y, int *hasx, int *hasy, int hasfn)
+static int compare(js_State *J, int x, int y, int *hasx, int *hasy, int hasfn)
{
const char *sx, *sy;
int c;
@@ -286,7 +286,7 @@
static void Ap_sort(js_State *J)
{
- unsigned int len, i, k;
+ int len, i, k;
int hasx, hasy, hasfn;
len = js_getlength(J, 0);
@@ -315,8 +315,8 @@
static void Ap_splice(js_State *J)
{
- unsigned int top = js_gettop(J);
- unsigned int len, start, del, add, k;
+ int top = js_gettop(J);
+ int len, start, del, add, k;
double f;
js_newarray(J);
@@ -367,8 +367,8 @@
static void Ap_unshift(js_State *J)
{
- unsigned int i, top = js_gettop(J);
- unsigned int k, len;
+ int i, top = js_gettop(J);
+ int k, len;
len = js_getlength(J, 0);
@@ -393,7 +393,7 @@
static void Ap_toString(js_State *J)
{
- unsigned int top = js_gettop(J);
+ int top = js_gettop(J);
js_pop(J, top - 1);
Ap_join(J);
}
--- a/jsbuiltin.c
+++ b/jsbuiltin.c
@@ -31,7 +31,7 @@
static void jsB_parseInt(js_State *J)
{
const char *s = js_tostring(J, 1);
- int radix = js_isdefined(J, 2) ? js_toint32(J, 2) : 10;
+ int radix = js_isdefined(J, 2) ? js_tointeger(J, 2) : 10;
double sign = 1;
double n;
char *e;
--- a/jsbuiltin.h
+++ b/jsbuiltin.h
@@ -18,7 +18,7 @@
void jsB_propn(js_State *J, const char *name, double number);
void jsB_props(js_State *J, const char *name, const char *string);
-typedef struct js_Buffer { unsigned int n, m; char s[64]; } js_Buffer;
+typedef struct js_Buffer { int n, m; char s[64]; } js_Buffer;
static void js_putc(js_State *J, js_Buffer **sbp, int c)
{
@@ -29,7 +29,7 @@
sb->m = sizeof sb->s;
*sbp = sb;
} else if (sb->n == sb->m) {
- sb = js_realloc(J, sb, (sb->m *= 2) + offsetof(js_Buffer, s));
+ sb = js_realloc(J, sb, (sb->m *= 2) + soffsetof(js_Buffer, s));
*sbp = sb;
}
sb->s[sb->n++] = c;
--- a/jscompile.c
+++ b/jscompile.c
@@ -89,7 +89,7 @@
static int addnumber(JF, double value)
{
- unsigned int i;
+ int i;
for (i = 0; i < F->numlen; ++i)
if (F->numtab[i] == value)
return i;
@@ -103,7 +103,7 @@
static int addstring(JF, const char *value)
{
- unsigned int i;
+ int i;
for (i = 0; i < F->strlen; ++i)
if (!strcmp(F->strtab[i], value))
return i;
@@ -125,7 +125,7 @@
jsC_error(J, ident, "redefining 'eval' is not allowed in strict mode");
}
if (reuse || J->strict) {
- unsigned int i;
+ int i;
for (i = 0; i < F->varlen; ++i) {
if (!strcmp(F->vartab[i], name)) {
if (reuse)
@@ -144,7 +144,7 @@
static int findlocal(JF, const char *name)
{
- unsigned int i;
+ int i;
for (i = F->varlen; i > 0; --i)
if (!strcmp(F->vartab[i-1], name))
return i;
@@ -318,6 +318,7 @@
checkdup(J, F, head, kv);
switch (kv->type) {
+ default: /* impossible */ break;
case EXP_PROP_VAL:
cexp(J, F, kv->b);
emit(J, F, OP_INITPROP);
@@ -795,6 +796,7 @@
do {
prev = node, node = node->parent;
switch (node->type) {
+ default: /* impossible */ break;
case STM_WITH:
emit(J, F, OP_ENDWITH);
break;
--- a/jscompile.h
+++ b/jscompile.h
@@ -122,23 +122,23 @@
const char *name;
int script;
int lightweight;
- unsigned int arguments;
- unsigned int numparams;
+ int arguments;
+ int numparams;
js_Instruction *code;
- unsigned int codecap, codelen;
+ int codecap, codelen;
js_Function **funtab;
- unsigned int funcap, funlen;
+ int funcap, funlen;
double *numtab;
- unsigned int numcap, numlen;
+ int numcap, numlen;
const char **strtab;
- unsigned int strcap, strlen;
+ int strcap, strlen;
const char **vartab;
- unsigned int varcap, varlen;
+ int varcap, varlen;
const char *filename;
int line, lastline;
--- a/jsdate.c
+++ b/jsdate.c
@@ -405,7 +405,7 @@
static void jsB_new_Date(js_State *J)
{
- unsigned int top = js_gettop(J);
+ int top = js_gettop(J);
js_Object *obj;
double t;
--- a/jsdump.c
+++ b/jsdump.c
@@ -188,6 +188,7 @@
js_Ast *kv = list->a;
assert(list->type == AST_LIST);
switch (kv->type) {
+ default: break;
case EXP_PROP_VAL:
pexpi(d, COMMA, kv->a);
ps(": ");
@@ -649,6 +650,7 @@
pc('(');
ps(astname[node->type]);
switch (node->type) {
+ default: break;
case AST_IDENTIFIER: pc(' '); ps(node->string); break;
case EXP_IDENTIFIER: pc(' '); ps(node->string); break;
case EXP_STRING: pc(' '); pstr(node->string); break;
@@ -713,7 +715,7 @@
{
js_Instruction *p = F->code;
js_Instruction *end = F->code + F->codelen;
- unsigned int i;
+ int i;
printf("%s(%d)\n", F->name, F->numparams);
if (F->lightweight) printf("\tlightweight\n");
--- a/jserror.c
+++ b/jserror.c
@@ -46,7 +46,7 @@
static int jsB_ErrorX(js_State *J, js_Object *prototype)
{
- unsigned int top = js_gettop(J);
+ int top = js_gettop(J);
js_pushobject(J, jsV_newobject(J, JS_CERROR, prototype));
if (top > 1) {
js_pushstring(J, js_tostring(J, 1));
--- a/jsfunction.c
+++ b/jsfunction.c
@@ -6,7 +6,7 @@
static void jsB_Function(js_State *J)
{
- unsigned int i, top = js_gettop(J);
+ int i, top = js_gettop(J);
js_Buffer *sb = NULL;
const char *body;
js_Ast *parse;
@@ -50,7 +50,7 @@
{
js_Object *self = js_toobject(J, 0);
char *s;
- unsigned int i, n;
+ int i, n;
if (!js_iscallable(J, 0))
js_typeerror(J, "not a function");
@@ -101,7 +101,7 @@
static void Fp_call(js_State *J)
{
- unsigned int i, top = js_gettop(J);
+ int i, top = js_gettop(J);
if (!js_iscallable(J, 0))
js_typeerror(J, "not a function");
@@ -114,8 +114,8 @@
static void callbound(js_State *J)
{
- unsigned int top = js_gettop(J);
- unsigned int i, fun, args, n;
+ int top = js_gettop(J);
+ int i, fun, args, n;
fun = js_gettop(J);
js_currentfunction(J);
@@ -137,8 +137,8 @@
static void constructbound(js_State *J)
{
- unsigned int top = js_gettop(J);
- unsigned int i, fun, args, n;
+ int top = js_gettop(J);
+ int i, fun, args, n;
fun = js_gettop(J);
js_currentfunction(J);
@@ -159,8 +159,8 @@
static void Fp_bind(js_State *J)
{
- unsigned int i, top = js_gettop(J);
- unsigned int n;
+ int i, top = js_gettop(J);
+ int n;
if (!js_iscallable(J, 0))
js_typeerror(J, "not a function");
--- a/jsgc.c
+++ b/jsgc.c
@@ -55,7 +55,7 @@
static void jsG_markfunction(js_State *J, int mark, js_Function *fun)
{
- unsigned int i;
+ int i;
fun->gcmark = mark;
for (i = 0; i < fun->funlen; ++i)
if (fun->funtab[i]->gcmark != mark)
--- a/jsi.h
+++ b/jsi.h
@@ -49,10 +49,11 @@
#endif
#endif
-#define nelem(a) (sizeof (a) / sizeof (a)[0])
+#define soffsetof(x,y) ((int)offsetof(x,y))
+#define nelem(a) (int)(sizeof (a) / sizeof (a)[0])
-void *js_malloc(js_State *J, unsigned int size);
-void *js_realloc(js_State *J, void *ptr, unsigned int size);
+void *js_malloc(js_State *J, int size);
+void *js_realloc(js_State *J, void *ptr, int size);
void js_free(js_State *J, void *ptr);
typedef struct js_Regexp js_Regexp;
@@ -73,7 +74,7 @@
#define JS_TRYLIMIT 64 /* exception stack size */
#define JS_GCLIMIT 10000 /* run gc cycle every N allocations */
-/* instruction size -- change to unsigned int if you get integer overflow syntax errors */
+/* instruction size -- change to int if you get integer overflow syntax errors */
typedef unsigned short js_Instruction;
/* String interning */
@@ -95,7 +96,7 @@
void js_loadeval(js_State *J, const char *filename, const char *source);
js_Regexp *js_toregexp(js_State *J, int idx);
-int js_isarrayindex(js_State *J, const char *str, unsigned int *idx);
+int js_isarrayindex(js_State *J, const char *str, int *idx);
int js_runeat(js_State *J, const char *s, int i);
int js_utfptrtoidx(const char *s, const char *p);
const char *js_utfidxtoptr(const char *s, int i);
@@ -159,7 +160,7 @@
int line;
/* lexer state */
- struct { char *text; unsigned int len, cap; } lexbuf;
+ struct { char *text; int len, cap; } lexbuf;
int lexline;
int lexchar;
int lasttoken;
--- a/jsintern.c
+++ b/jsintern.c
@@ -14,7 +14,7 @@
static js_StringNode *jsS_newstringnode(js_State *J, const char *string, const char **result)
{
int n = strlen(string);
- js_StringNode *node = js_malloc(J, offsetof(js_StringNode, string) + n + 1);
+ js_StringNode *node = js_malloc(J, soffsetof(js_StringNode, string) + n + 1);
node->left = node->right = &jsS_sentinel;
node->level = 1;
memcpy(node->string, string, n + 1);
--- a/jsmath.c
+++ b/jsmath.c
@@ -96,7 +96,7 @@
static void Math_max(js_State *J)
{
- unsigned int i, n = js_gettop(J);
+ int i, n = js_gettop(J);
double x = -INFINITY;
for (i = 1; i < n; ++i) {
double y = js_tonumber(J, i);
@@ -114,7 +114,7 @@
static void Math_min(js_State *J)
{
- unsigned int i, n = js_gettop(J);
+ int i, n = js_gettop(J);
double x = INFINITY;
for (i = 1; i < n; ++i) {
double y = js_tonumber(J, i);
--- a/jsobject.c
+++ b/jsobject.c
@@ -135,7 +135,7 @@
{
js_Object *obj;
js_Property *ref;
- unsigned int k;
+ int k;
int i;
if (!js_isobject(J, 1))
@@ -292,7 +292,7 @@
{
js_Object *obj;
js_Property *ref;
- unsigned int k;
+ int k;
int i;
if (!js_isobject(J, 1))
--- a/json.c
+++ b/json.c
@@ -182,7 +182,7 @@
static void fmtarray(js_State *J, js_Buffer **sb, const char *gap, int level)
{
- unsigned int n, k;
+ int n, k;
char buf[32];
n = js_getlength(J, -1);
--- a/jsparse.c
+++ b/jsparse.c
@@ -50,7 +50,7 @@
fprintf(stderr, "\n");
}
-static js_Ast *jsP_newnode(js_State *J, int type, js_Ast *a, js_Ast *b, js_Ast *c, js_Ast *d)
+static js_Ast *jsP_newnode(js_State *J, enum js_AstType type, js_Ast *a, js_Ast *b, js_Ast *c, js_Ast *d)
{
js_Ast *node = js_malloc(J, sizeof *node);
@@ -89,7 +89,7 @@
return head;
}
-static js_Ast *jsP_newstrnode(js_State *J, int type, const char *s)
+static js_Ast *jsP_newstrnode(js_State *J, enum js_AstType type, const char *s)
{
js_Ast *node = jsP_newnode(J, type, 0, 0, 0, 0);
node->string = s;
@@ -96,7 +96,7 @@
return node;
}
-static js_Ast *jsP_newnumnode(js_State *J, int type, double n)
+static js_Ast *jsP_newnumnode(js_State *J, enum js_AstType type, double n)
{
js_Ast *node = jsP_newnode(J, type, 0, 0, 0, 0);
node->number = n;
@@ -879,7 +879,7 @@
static unsigned int touint32(double d)
{
- return toint32(d);
+ return (unsigned int)toint32(d);
}
static int jsP_setnumnode(js_Ast *node, double x)
@@ -906,6 +906,7 @@
if (a) {
x = node->a->number;
switch (node->type) {
+ default: break;
case EXP_NEG: return jsP_setnumnode(node, -x);
case EXP_POS: return jsP_setnumnode(node, x);
case EXP_BITNOT: return jsP_setnumnode(node, ~toint32(x));
@@ -914,6 +915,7 @@
if (b) {
y = node->b->number;
switch (node->type) {
+ default: break;
case EXP_MUL: return jsP_setnumnode(node, x * y);
case EXP_DIV: return jsP_setnumnode(node, x / y);
case EXP_MOD: return jsP_setnumnode(node, fmod(x, y));
--- a/jsparse.h
+++ b/jsparse.h
@@ -125,7 +125,7 @@
struct js_Ast
{
- int type;
+ enum js_AstType type;
int line;
js_Ast *parent, *a, *b, *c, *d;
double number;
--- a/jsproperty.c
+++ b/jsproperty.c
@@ -231,7 +231,7 @@
static int itshadow(js_State *J, js_Object *top, js_Object *bot, const char *name)
{
- unsigned int k;
+ int k;
while (top != bot) {
js_Property *prop = lookup(top->properties, name);
if (prop && !(prop->atts & JS_DONTENUM))
@@ -249,7 +249,7 @@
js_Object *obj = top;
js_Iterator *tail = NULL;
char buf[32];
- unsigned int k;
+ int k;
#define ITADD(x) \
js_Iterator *node = js_malloc(J, sizeof *node); \
@@ -297,7 +297,7 @@
const char *jsV_nextiterator(js_State *J, js_Object *io)
{
- unsigned int k;
+ int k;
if (io->type != JS_CITERATOR)
js_typeerror(J, "not an iterator");
while (io->u.iter.head) {
@@ -316,16 +316,16 @@
/* Walk all the properties and delete them one by one for arrays */
-void jsV_resizearray(js_State *J, js_Object *obj, unsigned int newlen)
+void jsV_resizearray(js_State *J, js_Object *obj, int newlen)
{
char buf[32];
const char *s;
- unsigned int k;
+ int k;
if (newlen < obj->u.a.length) {
if (obj->u.a.length > obj->count * 2) {
js_Object *it = jsV_newiterator(J, obj, 1);
while ((s = jsV_nextiterator(J, it))) {
- k = jsV_numbertouint32(jsV_stringtonumber(J, s));
+ k = jsV_numbertointeger(jsV_stringtonumber(J, s));
if (k >= newlen && !strcmp(s, jsV_numbertostring(J, buf, k)))
jsV_delproperty(J, obj, s);
}
--- a/jsregexp.c
+++ b/jsregexp.c
@@ -29,7 +29,7 @@
void js_RegExp_prototype_exec(js_State *J, js_Regexp *re, const char *text)
{
- unsigned int i;
+ int i;
int opts;
Resub m;
--- a/jsrun.c
+++ b/jsrun.c
@@ -29,7 +29,7 @@
js_throw(J);
}
-void *js_malloc(js_State *J, unsigned int size)
+void *js_malloc(js_State *J, int size)
{
void *ptr = J->alloc(J->actx, NULL, size);
if (!ptr)
@@ -37,7 +37,7 @@
return ptr;
}
-void *js_realloc(js_State *J, void *ptr, unsigned int size)
+void *js_realloc(js_State *J, void *ptr, int size)
{
ptr = J->alloc(J->actx, ptr, size);
if (!ptr)
@@ -52,7 +52,7 @@
js_String *jsV_newmemstring(js_State *J, const char *s, int n)
{
- js_String *v = js_malloc(J, offsetof(js_String, p) + n + 1);
+ js_String *v = js_malloc(J, soffsetof(js_String, p) + n + 1);
memcpy(v->p, s, n);
v->p[n] = 0;
v->gcmark = 0;
@@ -103,9 +103,9 @@
void js_pushstring(js_State *J, const char *v)
{
- unsigned int n = strlen(v);
+ int n = strlen(v);
CHECKSTACK(1);
- if (n <= offsetof(js_Value, type)) {
+ if (n <= soffsetof(js_Value, type)) {
char *s = STACK[TOP].u.shrstr;
while (n--) *s++ = *v++;
*s = 0;
@@ -117,10 +117,10 @@
++TOP;
}
-void js_pushlstring(js_State *J, const char *v, unsigned int n)
+void js_pushlstring(js_State *J, const char *v, int n)
{
CHECKSTACK(1);
- if (n <= offsetof(js_Value, type)) {
+ if (n <= soffsetof(js_Value, type)) {
char *s = STACK[TOP].u.shrstr;
while (n--) *s++ = *v++;
*s = 0;
@@ -252,7 +252,7 @@
return jsV_tonumber(J, stackidx(J, idx));
}
-double js_tointeger(js_State *J, int idx)
+int js_tointeger(js_State *J, int idx)
{
return jsV_numbertointeger(jsV_tonumber(J, stackidx(J, idx)));
}
@@ -433,10 +433,10 @@
/* Property access that takes care of attributes and getters/setters */
-int js_isarrayindex(js_State *J, const char *str, unsigned int *idx)
+int js_isarrayindex(js_State *J, const char *str, int *idx)
{
char buf[32];
- *idx = jsV_numbertouint32(jsV_stringtonumber(J, str));
+ *idx = jsV_numbertointeger(jsV_stringtonumber(J, str));
sprintf(buf, "%u", *idx);
return !strcmp(buf, str);
}
@@ -455,7 +455,7 @@
static int jsR_hasproperty(js_State *J, js_Object *obj, const char *name)
{
js_Property *ref;
- unsigned int k;
+ int k;
if (obj->type == JS_CARRAY) {
if (!strcmp(name, "length")) {
@@ -528,13 +528,13 @@
{
js_Value *value = stackidx(J, -1);
js_Property *ref;
- unsigned int k;
+ int k;
int own;
if (obj->type == JS_CARRAY) {
if (!strcmp(name, "length")) {
double rawlen = jsV_tonumber(J, value);
- unsigned int newlen = jsV_numbertouint32(rawlen);
+ int newlen = jsV_numbertointeger(rawlen);
if (newlen != rawlen)
js_rangeerror(J, "array length");
jsV_resizearray(J, obj, newlen);
@@ -602,7 +602,7 @@
int atts, js_Value *value, js_Object *getter, js_Object *setter)
{
js_Property *ref;
- unsigned int k;
+ int k;
if (obj->type == JS_CARRAY) {
if (!strcmp(name, "length"))
@@ -663,7 +663,7 @@
static int jsR_delproperty(js_State *J, js_Object *obj, const char *name)
{
js_Property *ref;
- unsigned int k;
+ int k;
if (obj->type == JS_CARRAY) {
if (!strcmp(name, "length"))
@@ -920,10 +920,10 @@
J->E = J->envstack[--J->envtop];
}
-static void jsR_calllwfunction(js_State *J, unsigned int n, js_Function *F, js_Environment *scope)
+static void jsR_calllwfunction(js_State *J, int n, js_Function *F, js_Environment *scope)
{
js_Value v;
- unsigned int i;
+ int i;
jsR_savescope(J, scope);
@@ -942,10 +942,10 @@
jsR_restorescope(J);
}
-static void jsR_callfunction(js_State *J, unsigned int n, js_Function *F, js_Environment *scope)
+static void jsR_callfunction(js_State *J, int n, js_Function *F, js_Environment *scope)
{
js_Value v;
- unsigned int i;
+ int i;
scope = jsR_newenvironment(J, jsV_newobject(J, JS_COBJECT, NULL), scope);
@@ -986,7 +986,7 @@
jsR_restorescope(J);
}
-static void jsR_callscript(js_State *J, unsigned int n, js_Function *F, js_Environment *scope)
+static void jsR_callscript(js_State *J, int n, js_Function *F, js_Environment *scope)
{
js_Value v;
@@ -1003,9 +1003,9 @@
jsR_restorescope(J);
}
-static void jsR_callcfunction(js_State *J, unsigned int n, unsigned int min, js_CFunction F)
+static void jsR_callcfunction(js_State *J, int n, int min, js_CFunction F)
{
- unsigned int i;
+ int i;
js_Value v;
for (i = n; i < min; ++i)
--- a/jsstate.c
+++ b/jsstate.c
@@ -7,7 +7,7 @@
#include <assert.h>
-static void *js_defaultalloc(void *actx, void *ptr, unsigned int size)
+static void *js_defaultalloc(void *actx, void *ptr, int size)
{
if (size == 0) {
free(ptr);
@@ -14,8 +14,8 @@
return NULL;
}
if (!ptr)
- return malloc(size);
- return realloc(ptr, size);
+ return malloc((size_t)size);
+ return realloc(ptr, (size_t)size);
}
static void js_defaultpanic(js_State *J)
@@ -103,7 +103,7 @@
js_error(J, "cannot allocate storage for file contents: '%s'", filename);
}
- t = fread(s, 1, n, f);
+ t = fread(s, 1, (size_t)n, f);
if (t != n) {
js_free(J, s);
fclose(f);
@@ -177,7 +177,7 @@
js_State *J;
assert(sizeof(js_Value) == 16);
- assert(offsetof(js_Value, type) == 15);
+ assert(soffsetof(js_Value, type) == 15);
if (!alloc)
alloc = js_defaultalloc;
--- a/jsstring.c
+++ b/jsstring.c
@@ -99,8 +99,8 @@
static void Sp_concat(js_State *J)
{
- unsigned int i, top = js_gettop(J);
- unsigned int n;
+ int i, top = js_gettop(J);
+ int n;
char * volatile out;
const char *s;
@@ -283,7 +283,7 @@
static void S_fromCharCode(js_State *J)
{
- unsigned int i, top = js_gettop(J);
+ int i, top = js_gettop(J);
Rune c;
char *s, *p;
@@ -309,7 +309,7 @@
{
js_Regexp *re;
const char *text;
- unsigned int len;
+ int len;
const char *a, *b, *c, *e;
Resub m;
@@ -379,7 +379,7 @@
js_Regexp *re;
const char *source, *s, *r;
js_Buffer *sb = NULL;
- unsigned int n, x;
+ int n, x;
Resub m;
source = js_tostring(J, 0);
@@ -545,13 +545,13 @@
{
js_Regexp *re;
const char *text;
- unsigned int limit, len, k;
+ int limit, len, k;
const char *p, *a, *b, *c, *e;
Resub m;
text = js_tostring(J, 0);
re = js_toregexp(J, 1);
- limit = js_isdefined(J, 2) ? js_touint32(J, 2) : 1 << 30;
+ limit = js_isdefined(J, 2) ? js_tointeger(J, 2) : 1 << 30;
js_newarray(J);
len = 0;
@@ -604,8 +604,8 @@
{
const char *str = js_tostring(J, 0);
const char *sep = js_tostring(J, 1);
- unsigned int limit = js_isdefined(J, 2) ? js_touint32(J, 2) : 1 << 30;
- unsigned int i, n;
+ int limit = js_isdefined(J, 2) ? js_tointeger(J, 2) : 1 << 30;
+ int i, n;
js_newarray(J);
--- a/jsvalue.c
+++ b/jsvalue.c
@@ -7,7 +7,7 @@
#define JSV_ISSTRING(v) (v->type==JS_TSHRSTR || v->type==JS_TMEMSTR || v->type==JS_TLITSTR)
#define JSV_TOSTRING(v) (v->type==JS_TSHRSTR ? v->u.shrstr : v->type==JS_TLITSTR ? v->u.litstr : v->type==JS_TMEMSTR ? v->u.memstr->p : "")
-double jsV_numbertointeger(double n)
+int jsV_numbertointeger(double n)
{
double sign = n < 0 ? -1 : 1;
if (isnan(n)) return 0;
@@ -33,7 +33,7 @@
unsigned int jsV_numbertouint32(double n)
{
- return jsV_numbertoint32(n);
+ return (unsigned int)jsV_numbertoint32(n);
}
short jsV_numbertoint16(double n)
@@ -128,10 +128,10 @@
}
}
-const char *js_itoa(char *out, unsigned int a)
+const char *js_itoa(char *out, int a)
{
char buf[32], *s = out;
- unsigned int i = 0;
+ int i = 0;
while (a) {
buf[i++] = (a % 10) + '0';
a /= 10;
@@ -283,8 +283,8 @@
case JS_TNUMBER:
p = jsV_numbertostring(J, buf, v->u.number);
if (p == buf) {
- unsigned int n = strlen(p);
- if (n <= offsetof(js_Value, type)) {
+ int n = strlen(p);
+ if (n <= soffsetof(js_Value, type)) {
char *s = v->u.shrstr;
while (n--) *s++ = *p++;
*s = 0;
@@ -394,7 +394,7 @@
js_pushobject(J, obj);
}
-void js_newcfunction(js_State *J, js_CFunction cfun, const char *name, unsigned int length)
+void js_newcfunction(js_State *J, js_CFunction cfun, const char *name, int length)
{
js_Object *obj = jsV_newobject(J, JS_CCFUNCTION, J->Function_prototype);
obj->u.c.name = name;
@@ -415,7 +415,7 @@
}
/* prototype -- constructor */
-void js_newcconstructor(js_State *J, js_CFunction cfun, js_CFunction ccon, const char *name, unsigned int length)
+void js_newcconstructor(js_State *J, js_CFunction cfun, js_CFunction ccon, const char *name, int length)
{
js_Object *obj = jsV_newobject(J, JS_CCFUNCTION, J->Function_prototype);
obj->u.c.name = name;
--- a/jsvalue.h
+++ b/jsvalue.h
@@ -82,7 +82,7 @@
int extensible;
js_Property *properties;
js_Property *head, **tailp; /* for enumeration */
- unsigned int count; /* number of properties, for array sparseness check */
+ int count; /* number of properties, for array sparseness check */
js_Object *prototype;
union {
int boolean;
@@ -89,10 +89,10 @@
double number;
struct {
const char *string;
- unsigned int length;
+ int length;
} s;
struct {
- unsigned int length;
+ int length;
} a;
struct {
js_Function *function;
@@ -102,7 +102,7 @@
const char *name;
js_CFunction function;
js_CFunction constructor;
- unsigned int length;
+ int length;
} c;
js_Regexp r;
struct {
@@ -156,9 +156,9 @@
js_Object *jsV_toobject(js_State *J, js_Value *v);
void jsV_toprimitive(js_State *J, js_Value *v, int preferred);
-const char *js_itoa(char buf[32], unsigned int a);
+const char *js_itoa(char buf[32], int a);
double js_stringtofloat(const char *s, char **ep);
-double jsV_numbertointeger(double n);
+int jsV_numbertointeger(double n);
int jsV_numbertoint32(double n);
unsigned int jsV_numbertouint32(double n);
short jsV_numbertoint16(double n);
@@ -178,7 +178,7 @@
js_Object *jsV_newiterator(js_State *J, js_Object *obj, int own);
const char *jsV_nextiterator(js_State *J, js_Object *iter);
-void jsV_resizearray(js_State *J, js_Object *obj, unsigned int newlen);
+void jsV_resizearray(js_State *J, js_Object *obj, int newlen);
/* jsdump.c */
void js_dumpobject(js_State *J, js_Object *obj);
--- a/main.c
+++ b/main.c
@@ -22,7 +22,7 @@
static void jsB_print(js_State *J)
{
- unsigned int i, top = js_gettop(J);
+ int i, top = js_gettop(J);
for (i = 1; i < top; ++i) {
const char *s = js_tostring(J, i);
if (i > 1) putchar(' ');
@@ -34,7 +34,7 @@
static void jsB_write(js_State *J)
{
- unsigned int i, top = js_gettop(J);
+ int i, top = js_gettop(J);
for (i = 1; i < top; ++i) {
const char *s = js_tostring(J, i);
if (i > 1) putchar(' ');
--- a/mujs.h
+++ b/mujs.h
@@ -26,7 +26,7 @@
typedef struct js_State js_State;
-typedef void *(*js_Alloc)(void *memctx, void *ptr, unsigned int size);
+typedef void *(*js_Alloc)(void *memctx, void *ptr, int size);
typedef void (*js_Panic)(js_State *J);
typedef void (*js_CFunction)(js_State *J);
typedef void (*js_Finalize)(js_State *J, void *p);
@@ -119,12 +119,12 @@
void js_delproperty(js_State *J, int idx, const char *name);
void js_defaccessor(js_State *J, int idx, const char *name, int atts);
-unsigned int js_getlength(js_State *J, int idx);
-void js_setlength(js_State *J, int idx, unsigned int len);
-int js_hasindex(js_State *J, int idx, unsigned int i);
-void js_getindex(js_State *J, int idx, unsigned int i);
-void js_setindex(js_State *J, int idx, unsigned int i);
-void js_delindex(js_State *J, int idx, unsigned int i);
+int js_getlength(js_State *J, int idx);
+void js_setlength(js_State *J, int idx, int len);
+int js_hasindex(js_State *J, int idx, int i);
+void js_getindex(js_State *J, int idx, int i);
+void js_setindex(js_State *J, int idx, int i);
+void js_delindex(js_State *J, int idx, int i);
void js_currentfunction(js_State *J);
void js_pushglobal(js_State *J);
@@ -133,7 +133,7 @@
void js_pushboolean(js_State *J, int v);
void js_pushnumber(js_State *J, double v);
void js_pushstring(js_State *J, const char *v);
-void js_pushlstring(js_State *J, const char *v, unsigned int n);
+void js_pushlstring(js_State *J, const char *v, int n);
void js_pushliteral(js_State *J, const char *v);
void js_newobject(js_State *J);
@@ -141,8 +141,8 @@
void js_newboolean(js_State *J, int v);
void js_newnumber(js_State *J, double v);
void js_newstring(js_State *J, const char *v);
-void js_newcfunction(js_State *J, js_CFunction fun, const char *name, unsigned int length);
-void js_newcconstructor(js_State *J, js_CFunction fun, js_CFunction con, const char *name, unsigned int length);
+void js_newcfunction(js_State *J, js_CFunction fun, const char *name, int length);
+void js_newcconstructor(js_State *J, js_CFunction fun, js_CFunction con, const char *name, int length);
void js_newuserdata(js_State *J, const char *tag, void *data, js_Finalize finalize);
void js_newuserdatax(js_State *J, const char *tag, void *data, js_HasProperty has, js_Put put, js_Delete delete, js_Finalize finalize);
void js_newregexp(js_State *J, const char *pattern, int flags);
@@ -168,7 +168,7 @@
const char *js_tostring(js_State *J, int idx);
void *js_touserdata(js_State *J, int idx, const char *tag);
-double js_tointeger(js_State *J, int idx);
+int js_tointeger(js_State *J, int idx);
int js_toint32(js_State *J, int idx);
unsigned int js_touint32(js_State *J, int idx);
short js_toint16(js_State *J, int idx);
--- a/regexp.c
+++ b/regexp.c
@@ -11,7 +11,7 @@
#define next regnext
#define accept regaccept
-#define nelem(a) (sizeof (a) / sizeof (a)[0])
+#define nelem(a) (int)(sizeof (a) / sizeof (a)[0])
#define REPINF 255
#define MAXTHREAD 1000
@@ -30,7 +30,7 @@
struct Reprog {
Reinst *start, *end;
int flags;
- unsigned int nsub;
+ int nsub;
Reclass cclass[16];
};
@@ -39,8 +39,8 @@
Renode *pstart, *pend;
const char *source;
- unsigned int ncclass;
- unsigned int nsub;
+ int ncclass;
+ int nsub;
Renode *sub[MAXSUB];
int lookahead;
@@ -597,9 +597,9 @@
Reinst *y;
};
-static unsigned int count(Renode *node)
+static int count(Renode *node)
{
- unsigned int min, max;
+ int min, max;
if (!node) return 0;
switch (node->type) {
default: return 1;
@@ -631,7 +631,7 @@
static void compile(Reprog *prog, Renode *node)
{
Reinst *inst, *split, *jump;
- unsigned int i;
+ int i;
if (!node)
return;
@@ -909,7 +909,7 @@
return 0;
}
-static int strncmpcanon(const char *a, const char *b, unsigned int n)
+static int strncmpcanon(const char *a, const char *b, int n)
{
Rune ra, rb;
int c;
@@ -944,7 +944,7 @@
Resub scratch;
Resub sub;
Rune c;
- unsigned int nready;
+ int nready;
int i;
/* queue initial thread */
@@ -1112,7 +1112,7 @@
const char *s;
Reprog *p;
Resub m;
- unsigned int i;
+ int i;
if (argc > 1) {
p = regcomp(argv[1], 0, &error);
--- a/regexp.h
+++ b/regexp.h
@@ -25,7 +25,7 @@
};
struct Resub {
- unsigned int nsub;
+ int nsub;
struct {
const char *sp;
const char *ep;
--- a/utf.c
+++ b/utf.c
@@ -42,7 +42,7 @@
Bad = Runeerror,
};
-unsigned int
+int
chartorune(Rune *rune, const char *str)
{
int c, c1, c2;
@@ -98,10 +98,10 @@
return 1;
}
-unsigned int
+int
runetochar(char *str, const Rune *rune)
{
- unsigned int c;
+ int c;
/*
* one character sequence
@@ -133,7 +133,7 @@
return 3;
}
-unsigned int
+int
runelen(int c)
{
Rune rune;
@@ -143,11 +143,11 @@
return runetochar(str, &rune);
}
-unsigned int
+int
utflen(const char *s)
{
- unsigned int c;
- unsigned int n;
+ int c;
+ int n;
Rune rune;
n = 0;
--- a/utf.h
+++ b/utf.h
@@ -25,10 +25,10 @@
Runeerror = 0xFFFD, /* decoding error in UTF */
};
-unsigned int chartorune(Rune *rune, const char *str);
-unsigned int runetochar(char *str, const Rune *rune);
-unsigned int runelen(int c);
-unsigned int utflen(const char *s);
+int chartorune(Rune *rune, const char *str);
+int runetochar(char *str, const Rune *rune);
+int runelen(int c);
+int utflen(const char *s);
int isalpharune(Rune c);
int islowerrune(Rune c);
--- a/utftype.c
+++ b/utftype.c
@@ -1,7 +1,7 @@
#include "utf.h"
#define bsearch jsU_bsearch
-#define nelem(a) (sizeof (a) / sizeof (a)[0])
+#define nelem(a) (int)(sizeof (a) / sizeof (a)[0])
/*
* alpha ranges -