Commit d5b69215 authored by rswindell's avatar rswindell
Browse files

Fix numerous long-standing bugs that would occur on systems with 64-bit 'ints'

or 'longs'. Amazing that no one noticed.
parent 6df02c64
......@@ -953,8 +953,10 @@ static uint get_subnum(JSContext* cx, sbbs_t* sbbs, jsval *argv, int argc, int p
if(!stricmp(sbbs->cfg.sub[subnum]->code,p))
break;
} else if(argc>pos && JSVAL_IS_NUMBER(argv[pos])) {
if(!JS_ValueToInt32(cx,argv[pos],(int32*)&subnum))
int32 i;
if(!JS_ValueToInt32(cx,argv[pos],&i))
return JS_FALSE;
subnum = i;
}
else if(sbbs->usrgrps>0)
subnum=sbbs->usrsub[sbbs->curgrp][sbbs->cursub[sbbs->curgrp]];
......@@ -977,8 +979,10 @@ static uint get_dirnum(JSContext* cx, sbbs_t* sbbs, jsval val, bool dflt)
if(!stricmp(sbbs->cfg.dir[dirnum]->code,p))
break;
} else if(JSVAL_IS_NUMBER(val)) {
if(!JS_ValueToInt32(cx,val,(int32*)&dirnum))
int32 i;
if(!JS_ValueToInt32(cx,val,&i))
return JS_FALSE;
dirnum = i;
}
else if(sbbs->usrlibs>0)
dirnum=sbbs->usrdir[sbbs->curlib][sbbs->curdir[sbbs->curlib]];
......@@ -3387,8 +3391,10 @@ js_getnstime(JSContext *cx, uintN argc, jsval *arglist)
return(JS_FALSE);
if(argc && JSVAL_IS_NUMBER(argv[0])) {
if(!JS_ValueToInt32(cx,argv[0],(int32*)&t))
int32 i;
if(!JS_ValueToInt32(cx,argv[0],&i))
return JS_FALSE;
t = i;
}
rc=JS_SUSPENDREQUEST(cx);
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2013 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -279,7 +279,7 @@ js_sendbin(JSContext *cx, uintN argc, jsval *arglist)
DWORD l;
int32 val=0;
size_t wr=0;
size_t size=sizeof(DWORD);
int32 size=sizeof(DWORD);
private_t* p;
jsrefcount rc;
......@@ -296,7 +296,7 @@ js_sendbin(JSContext *cx, uintN argc, jsval *arglist)
if(!JS_ValueToInt32(cx,argv[0],&val))
return JS_FALSE;
if(!JS_ValueToInt32(cx,argv[1],(int32*)&size))
if(!JS_ValueToInt32(cx,argv[1],&size))
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
......@@ -462,7 +462,7 @@ js_recvbin(JSContext *cx, uintN argc, jsval *arglist)
BYTE b;
WORD w;
DWORD l;
int size=sizeof(DWORD);
int32 size=sizeof(DWORD);
int rd=0;
private_t* p;
jsrefcount rc;
......@@ -476,7 +476,7 @@ js_recvbin(JSContext *cx, uintN argc, jsval *arglist)
}
if(argc) {
if(!JS_ValueToInt32(cx,argv[0],(int32*)&size))
if(!JS_ValueToInt32(cx,argv[0],&size))
return JS_FALSE;
}
......@@ -556,6 +556,7 @@ static JSBool js_com_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, j
private_t* p;
jsrefcount rc;
double d;
int32 i;
if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
// Prototype access
......@@ -574,13 +575,15 @@ static JSBool js_com_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, j
JS_ValueToBoolean(cx,*vp,&(p->debug));
break;
case COM_PROP_DESCRIPTOR:
if(!JS_ValueToInt32(cx,*vp,(int32*)&(p->com)))
if(!JS_ValueToInt32(cx,*vp,&i))
return JS_FALSE;
p->com=(COM_HANDLE)i;
p->is_open=TRUE;
break;
case COM_PROP_LAST_ERROR:
if(!JS_ValueToInt32(cx,*vp,(int32*)&(p->last_error)))
if(!JS_ValueToInt32(cx,*vp,&i))
return JS_FALSE;
p->last_error=i;
break;
case COM_PROP_BAUD_RATE:
JS_ValueToNumber(cx,*vp,&d);
......
......@@ -478,7 +478,7 @@ js_getstr(JSContext *cx, uintN argc, jsval *arglist)
char *p,*p2;
int32 mode=0;
uintN i;
size_t maxlen=0;
int32 maxlen=0;
sbbs_t* sbbs;
JSString* js_str=NULL;
jsrefcount rc;
......@@ -491,11 +491,11 @@ js_getstr(JSContext *cx, uintN argc, jsval *arglist)
for(i=0;i<argc;i++) {
if(JSVAL_IS_NUMBER(argv[i])) {
if(!maxlen) {
if(!JS_ValueToInt32(cx,argv[i],(int32*)&maxlen))
if(!JS_ValueToInt32(cx,argv[i],&maxlen))
return JS_FALSE;
}
else {
if(!JS_ValueToInt32(cx,argv[i],(int32*)&mode))
if(!JS_ValueToInt32(cx,argv[i],&mode))
return JS_FALSE;
}
continue;
......@@ -540,7 +540,7 @@ js_getnum(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
uint32_t maxnum=~0;
uint32_t dflt=0;
int32_t dflt=0;
sbbs_t* sbbs;
jsrefcount rc;
......@@ -554,7 +554,7 @@ js_getnum(JSContext *cx, uintN argc, jsval *arglist)
return JS_FALSE;
}
if(argc>1 && JSVAL_IS_NUMBER(argv[1])) {
if(!JS_ValueToInt32(cx,argv[1],(int32*)&dflt))
if(!JS_ValueToInt32(cx,argv[1],&dflt))
return JS_FALSE;
}
......@@ -1069,7 +1069,7 @@ js_putmsg(JSContext *cx, uintN argc, jsval *arglist)
return(JS_FALSE);
if(argc>1 && JSVAL_IS_NUMBER(argv[1])) {
if(!JS_ValueToInt32(cx,argv[1],(int32*)&mode))
if(!JS_ValueToInt32(cx,argv[1],&mode))
return JS_FALSE;
}
......@@ -1103,7 +1103,7 @@ js_printfile(JSContext *cx, uintN argc, jsval *arglist)
return(JS_FALSE);
if(argc>1 && JSVAL_IS_NUMBER(argv[1])) {
if(!JS_ValueToInt32(cx,argv[1],(int32*)&mode))
if(!JS_ValueToInt32(cx,argv[1],&mode))
return JS_FALSE;
}
......@@ -1121,7 +1121,7 @@ static JSBool
js_printtail(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
int lines=0;
int32 lines=0;
int32 mode=0;
uintN i;
sbbs_t* sbbs;
......@@ -1137,11 +1137,11 @@ js_printtail(JSContext *cx, uintN argc, jsval *arglist)
for(i=0;i<argc;i++) {
if(JSVAL_IS_NUMBER(argv[i])) {
if(!lines) {
if(!JS_ValueToInt32(cx,argv[i],(int32*)&lines))
if(!JS_ValueToInt32(cx,argv[i],&lines))
return JS_FALSE;
}
else {
if(!JS_ValueToInt32(cx,argv[i],(int32*)&mode))
if(!JS_ValueToInt32(cx,argv[i],&mode))
return JS_FALSE;
}
} else if(JSVAL_IS_STRING(argv[i]))
......
......@@ -440,9 +440,9 @@ js_readbin(JSContext *cx, uintN argc, jsval *arglist)
BYTE *b;
WORD *w;
DWORD *l;
size_t size=sizeof(DWORD);
int32 size=sizeof(DWORD);
private_t* p;
size_t count=1;
int32 count=1;
size_t retlen;
void *buffer=NULL;
size_t i;
......@@ -461,10 +461,10 @@ js_readbin(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE);
if(argc) {
if(!JS_ValueToInt32(cx,argv[0],(int32*)&size))
if(!JS_ValueToInt32(cx,argv[0],&size))
return(JS_FALSE);
if(argc>1) {
if(!JS_ValueToInt32(cx,argv[1],(int32*)&count))
if(!JS_ValueToInt32(cx,argv[1],&count))
return(JS_FALSE);
}
}
......@@ -1413,8 +1413,8 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
jsval *argv=JS_ARGV(cx, arglist);
char* cp;
char* uubuf=NULL;
size_t len; /* string length */
size_t tlen; /* total length to write (may be greater than len) */
int32 len; /* string length */
int32 tlen; /* total length to write (may be greater than len) */
JSString* str;
private_t* p;
jsrefcount rc;
......@@ -1462,7 +1462,7 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
JS_RESUMEREQUEST(cx, rc);
tlen=len;
if(argc>1) {
if(!JS_ValueToInt32(cx,argv[1],(int32*)&tlen)) {
if(!JS_ValueToInt32(cx,argv[1],&tlen)) {
free(cp);
return(JS_FALSE);
}
......@@ -1481,7 +1481,7 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
return(JS_FALSE);
}
memset(cp,p->etx,len);
if(fwrite(cp,1,len,p->fp) < len) {
if(fwrite(cp,1,len,p->fp) < (size_t)len) {
free(cp);
JS_RESUMEREQUEST(cx, rc);
return JS_TRUE;
......@@ -1571,7 +1571,7 @@ js_writebin(JSContext *cx, uintN argc, jsval *arglist)
WORD *w;
DWORD *l;
size_t wr=0;
size_t size=sizeof(DWORD);
int32 size=sizeof(DWORD);
jsuint count=1;
void *buffer;
private_t* p;
......@@ -1604,7 +1604,7 @@ js_writebin(JSContext *cx, uintN argc, jsval *arglist)
return(JS_FALSE);
}
if(argc>1) {
if(!JS_ValueToInt32(cx,argv[1],(int32*)&size))
if(!JS_ValueToInt32(cx,argv[1],&size))
return(JS_FALSE);
}
if(size != sizeof(BYTE) && size != sizeof(WORD) && size != sizeof(DWORD)) {
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2012 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2013 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -124,7 +124,7 @@ static ptrdiff_t js_socket_recv(private_t *p, void *buf, size_t len, int flags,
if(p->nonblocking)
return copied;
total += copied;
if(total>=len)
if(total>=(ptrdiff_t)len)
return total;
len-=copied;
buf=((uint8_t *)buf) + copied;
......@@ -151,7 +151,7 @@ static ptrdiff_t js_socket_sendsocket(private_t *p, const void *msg, size_t len,
return copied;
}
total += copied;
if(total >= len) {
if(total >= (ptrdiff_t)len) {
if(flush) do_CryptFlush(p->session);
return total;
}
......@@ -345,8 +345,11 @@ SOCKET DLLCALL js_socket(JSContext *cx, jsval val)
if(cl->flags&JSCLASS_HAS_PRIVATE)
if((vp=JS_GetPrivate(cx,JSVAL_TO_OBJECT(val)))!=NULL)
sock=*(SOCKET*)vp;
} else if(val!=JSVAL_VOID)
JS_ValueToInt32(cx,val,(int32*)&sock);
} else if(val!=JSVAL_VOID) {
int32 i;
if(JS_ValueToInt32(cx,val,&i))
sock = i;
}
return(sock);
}
......@@ -760,7 +763,7 @@ js_sendbin(JSContext *cx, uintN argc, jsval *arglist)
DWORD l;
int32 val=0;
size_t wr=0;
size_t size=sizeof(DWORD);
int32 size=sizeof(DWORD);
private_t* p;
jsrefcount rc;
......@@ -774,7 +777,7 @@ js_sendbin(JSContext *cx, uintN argc, jsval *arglist)
if(argc && argv[0]!=JSVAL_VOID)
JS_ValueToInt32(cx,argv[0],&val);
if(argc>1 && argv[1]!=JSVAL_VOID)
JS_ValueToInt32(cx,argv[1],(int32*)&size);
JS_ValueToInt32(cx,argv[1],&size);
rc=JS_SUSPENDREQUEST(cx);
switch(size) {
......@@ -1186,7 +1189,7 @@ js_recvbin(JSContext *cx, uintN argc, jsval *arglist)
BYTE b;
WORD w;
DWORD l;
int size=sizeof(DWORD);
int32 size=sizeof(DWORD);
int rd=0;
private_t* p;
jsrefcount rc;
......@@ -1199,7 +1202,7 @@ js_recvbin(JSContext *cx, uintN argc, jsval *arglist)
}
if(argc && argv[0]!=JSVAL_VOID)
JS_ValueToInt32(cx,argv[0],(int32*)&size);
JS_ValueToInt32(cx,argv[0],&size);
rc=JS_SUSPENDREQUEST(cx);
switch(size) {
......@@ -1479,6 +1482,7 @@ static JSBool js_socket_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict
private_t* p;
jsrefcount rc;
BOOL b;
int32 i;
if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
// Prototype access
......@@ -1501,11 +1505,13 @@ static JSBool js_socket_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict
cryptDestroySession(p->session);
p->session=-1;
}
JS_ValueToInt32(cx,*vp,(int32*)&(p->sock));
if(JS_ValueToInt32(cx,*vp,&i))
p->sock = i;
p->is_connected=TRUE;
break;
case SOCK_PROP_LAST_ERROR:
JS_ValueToInt32(cx,*vp,(int32*)&(p->last_error));
if(JS_ValueToInt32(cx,*vp,&i))
p->last_error = i;
break;
case SOCK_PROP_NONBLOCKING:
JS_ValueToBoolean(cx,*vp,&(p->nonblocking));
......
......@@ -79,11 +79,11 @@
#define JAVASCRIPT_LOAD_PATH_LIST "load_path_list"
typedef struct {
ulong counter;
ulong limit;
ulong yield_interval;
ulong gc_interval;
ulong gc_attempts;
uint32 counter;
uint32 limit;
uint32 yield_interval;
uint32 gc_interval;
uint32 gc_attempts;
BOOL auto_terminate;
volatile BOOL* terminated;
} js_callback_t;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment