Bug 123584 JavaScript engine should use malloc/realloc/free consistently

Replace JS_DELETE with free/JS_smprintf_free
r=rogerl
This commit is contained in:
timeless%mozdev.org 2004-02-25 13:33:42 +00:00
parent 786239d041
commit 33607fc717
2 changed files with 70 additions and 70 deletions

View File

@ -396,7 +396,7 @@ static int cvt_s(SprintfState *ss, const char *s, int width, int prec,
}
/*
** BiuldArgArray stands for Numbered Argument list Sprintf
** BuildArgArray stands for Numbered Argument list Sprintf
** for example,
** fmp = "%4$i, %2$d, %3s, %1d";
** the number must start from 1, and no gap among them
@ -405,9 +405,9 @@ static int cvt_s(SprintfState *ss, const char *s, int width, int prec,
static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv, struct NumArgState* nasArray )
{
int number = 0, cn = 0, i;
const char* p;
char c;
struct NumArgState* nas;
const char *p;
char c;
struct NumArgState *nas;
/*
@ -478,7 +478,7 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv,
if( c == '%' ) continue;
cn = 0;
while( c && c != '$' ){ /* should imporve error check later */
while( c && c != '$' ){ /* should improve error check later */
cn = cn*10 + c - '0';
c = *p++;
}
@ -606,7 +606,7 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv,
if( *rv < 0 ){
if( nas != nasArray )
JS_DELETE( nas );
free( nas );
return NULL;
}
@ -641,7 +641,7 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv,
default:
if( nas != nasArray )
JS_DELETE( nas );
free( nas );
*rv = -1;
return NULL;
}
@ -674,10 +674,10 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
static char *HEX = "0123456789ABCDEF";
char *hexp;
int rv, i;
struct NumArgState* nas = NULL;
struct NumArgState nasArray[ NAS_DEFAULT_NUM ];
char pattern[20];
const char* dolPt = NULL; /* in "%4$.2f", dolPt will poiont to . */
struct NumArgState *nas = NULL;
struct NumArgState nasArray[ NAS_DEFAULT_NUM ];
char pattern[20];
const char *dolPt = NULL; /* in "%4$.2f", dolPt will poiont to . */
/*
@ -727,7 +727,7 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
if( nas[i-1].type == TYPE_UNKNOWN ){
if( nas && ( nas != nasArray ) )
JS_DELETE( nas );
free( nas );
return -1;
}
@ -987,7 +987,7 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
rv = (*ss->stuff)(ss, "\0", 1);
if( nas && ( nas != nasArray ) ){
JS_DELETE( nas );
free( nas );
}
return rv;
@ -1089,7 +1089,7 @@ JS_PUBLIC_API(char *) JS_smprintf(const char *fmt, ...)
*/
JS_PUBLIC_API(void) JS_smprintf_free(char *mem)
{
JS_DELETE(mem);
free(mem);
}
JS_PUBLIC_API(char *) JS_vsmprintf(const char *fmt, va_list ap)
@ -1104,7 +1104,7 @@ JS_PUBLIC_API(char *) JS_vsmprintf(const char *fmt, va_list ap)
rv = dosprintf(&ss, fmt, ap);
if (rv < 0) {
if (ss.base) {
JS_DELETE(ss.base);
free(ss.base);
}
return 0;
}
@ -1203,7 +1203,7 @@ JS_PUBLIC_API(char *) JS_vsprintf_append(char *last, const char *fmt, va_list ap
rv = dosprintf(&ss, fmt, ap);
if (rv < 0) {
if (ss.base) {
JS_DELETE(ss.base);
free(ss.base);
}
return 0;
}

View File

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
@ -52,9 +52,9 @@
#endif
#ifdef XP_MAC
# include <Types.h>
# include <Types.h>
# include <stdarg.h>
# include "jsprf.h"
# include "jsprf.h"
#endif
#ifdef XP_MAC
@ -65,76 +65,76 @@
* If the C String pointer is NULL, the pascal string's length is
* set to zero.
*/
static void PStrFromCStr(const char* src, Str255 dst)
static void PStrFromCStr(const char *src, Str255 dst)
{
short length = 0;
short length = 0;
/* handle case of overlapping strings */
if ( (void*)src == (void*)dst )
{
unsigned char* curdst = &dst[1];
unsigned char thisChar;
/* handle case of overlapping strings */
if ( (void*)src == (void*)dst )
{
unsigned char *curdst = &dst[1];
unsigned char thisChar;
thisChar = *(const unsigned char*)src++;
while ( thisChar != '\0' )
{
unsigned char nextChar;
thisChar = *(const unsigned char*)src++;
while ( thisChar != '\0' )
{
unsigned char nextChar;
/*
* Use nextChar so we don't overwrite what we
* are about to read
*/
nextChar = *(const unsigned char*)src++;
*curdst++ = thisChar;
thisChar = nextChar;
/*
* Use nextChar so we don't overwrite what we
* are about to read
*/
nextChar = *(const unsigned char*)src++;
*curdst++ = thisChar;
thisChar = nextChar;
if ( ++length >= 255 )
break;
}
}
else if ( src != NULL )
{
unsigned char* curdst = &dst[1];
/* count down so test it loop is faster */
short overflow = 255;
register char temp;
if ( ++length >= 255 )
break;
}
}
else if ( src != NULL )
{
unsigned char *curdst = &dst[1];
/* count down so test it loop is faster */
short overflow = 255;
register char temp;
/*
* Can't do the K&R C thing of while (*s++ = *t++)
* because it will copy trailing zero which might
* overrun pascal buffer. Instead we use a temp variable.
*/
while ( (temp = *src++) != 0 )
{
*(char*)curdst++ = temp;
/*
* Can't do the K&R C thing of while (*s++ = *t++)
* because it will copy trailing zero which might
* overrun pascal buffer. Instead we use a temp variable.
*/
while ( (temp = *src++) != 0 )
{
*(char*)curdst++ = temp;
if ( --overflow <= 0 )
break;
}
length = 255 - overflow;
}
dst[0] = length;
if ( --overflow <= 0 )
break;
}
length = 255 - overflow;
}
dst[0] = length;
}
static void jsdebugstr(const char *debuggerMsg)
{
Str255 pStr;
Str255 pStr;
PStrFromCStr(debuggerMsg, pStr);
DebugStr(pStr);
PStrFromCStr(debuggerMsg, pStr);
DebugStr(pStr);
}
static void dprintf(const char *format, ...)
{
va_list ap;
char *buffer;
char *buffer;
va_start(ap, format);
buffer = (char *)JS_vsmprintf(format, ap);
va_end(ap);
va_start(ap, format);
buffer = (char *)JS_vsmprintf(format, ap);
va_end(ap);
jsdebugstr(buffer);
JS_DELETE(buffer);
jsdebugstr(buffer);
JS_smprintf_free(buffer);
}
#endif /* XP_MAC */