fixed crasher in bufferroutines, and eliminated 1 costly call to sprintf

git-svn-id: svn://10.0.0.236/trunk@48319 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rickg%netscape.com
1999-09-20 05:10:32 +00:00
parent a3557b2d24
commit 7005feb199
7 changed files with 128 additions and 59 deletions

View File

@@ -952,16 +952,27 @@ nsCString& nsCString::Append(char aChar) {
* @return
*/
nsCString& nsCString::Append(PRInt32 aInteger,PRInt32 aRadix) {
char* fmt = "%d";
if (8 == aRadix) {
fmt = "%o";
} else if (16 == aRadix) {
fmt = "%x";
char buf[128]={0,0};
char* buffer=buf;
ldiv_t r; /* result of val / base */
if (aRadix> 36 || aRadix< 2) { /* no conversion if wrong base */
return *this;
}
char buf[40];
// *** XX UNCOMMENT THIS LINE
//PR_snprintf(buf, sizeof(buf), fmt, aInteger);
sprintf(buf,fmt,aInteger);
if (aInteger < 0)
*buffer++ = '-';
r = ldiv (labs(aInteger), aRadix);
/* output digits of val/base first */
if (r.quot > 0)
buffer = ltoa ( r.quot, buf, aRadix);
/* output last digit */
int len=strlen(buffer);
buf[len] = "0123456789abcdefghijklmnopqrstuvwxyz"[(int)r.rem];
buf[len+1] =0;
return Append(buf);
}

View File

@@ -1124,16 +1124,27 @@ nsString& nsString::Append(PRUnichar aChar) {
* @return
*/
nsString& nsString::Append(PRInt32 aInteger,PRInt32 aRadix) {
char* fmt = "%d";
if (8 == aRadix) {
fmt = "%o";
} else if (16 == aRadix) {
fmt = "%x";
char buf[128]={0,0};
char* buffer=buf;
ldiv_t r; /* result of val / base */
if (aRadix> 36 || aRadix< 2) { /* no conversion if wrong base */
return *this;
}
char buf[40];
// *** XX UNCOMMENT THIS LINE
//PR_snprintf(buf, sizeof(buf), fmt, aInteger);
sprintf(buf,fmt,aInteger);
if (aInteger < 0)
*buffer++ = '-';
r = ldiv (labs(aInteger), aRadix);
/* output digits of val/base first */
if (r.quot > 0)
buffer = ltoa ( r.quot, buf, aRadix);
/* output last digit */
int len=strlen(buffer);
buf[len] = "0123456789abcdefghijklmnopqrstuvwxyz"[(int)r.rem];
buf[len+1] =0;
return Append(buf);
}

View File

@@ -64,10 +64,12 @@ inline PRUnichar GetCharAt(const char* aString,PRUint32 anIndex) {
* @param aCount is the number of chars to be "cut"
*/
void ShiftCharsLeft(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCount) {
char* dst = aDest+anOffset;
char* src = aDest+anOffset+aCount;
char* dst = aDest+anOffset;
char* src = aDest+anOffset+aCount;
char* end = aDest+aLength+1;
PRInt32 cnt = end-src;
memmove(dst,src,aLength-anOffset);
memmove(dst,src,cnt);
}
/**
@@ -97,8 +99,10 @@ void ShiftDoubleCharsLeft(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint3
PRUnichar* root=(PRUnichar*)aDest;
PRUnichar* dst = root+anOffset;
PRUnichar* src = root+anOffset+aCount;
PRUnichar* end = root+aLength+1;
PRInt32 cnt = end-src;
memmove(dst,src,sizeof(PRUnichar)*(aLength-anOffset));
memmove(dst,src,cnt*sizeof(PRUnichar));
}
@@ -116,7 +120,6 @@ void ShiftDoubleCharsRight(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint
PRUnichar* dst = root+anOffset+aCount;
memmove(dst,src,sizeof(PRUnichar)*(aLength-anOffset));
}

View File

@@ -952,16 +952,27 @@ nsCString& nsCString::Append(char aChar) {
* @return
*/
nsCString& nsCString::Append(PRInt32 aInteger,PRInt32 aRadix) {
char* fmt = "%d";
if (8 == aRadix) {
fmt = "%o";
} else if (16 == aRadix) {
fmt = "%x";
char buf[128]={0,0};
char* buffer=buf;
ldiv_t r; /* result of val / base */
if (aRadix> 36 || aRadix< 2) { /* no conversion if wrong base */
return *this;
}
char buf[40];
// *** XX UNCOMMENT THIS LINE
//PR_snprintf(buf, sizeof(buf), fmt, aInteger);
sprintf(buf,fmt,aInteger);
if (aInteger < 0)
*buffer++ = '-';
r = ldiv (labs(aInteger), aRadix);
/* output digits of val/base first */
if (r.quot > 0)
buffer = ltoa ( r.quot, buf, aRadix);
/* output last digit */
int len=strlen(buffer);
buf[len] = "0123456789abcdefghijklmnopqrstuvwxyz"[(int)r.rem];
buf[len+1] =0;
return Append(buf);
}

View File

@@ -1124,16 +1124,27 @@ nsString& nsString::Append(PRUnichar aChar) {
* @return
*/
nsString& nsString::Append(PRInt32 aInteger,PRInt32 aRadix) {
char* fmt = "%d";
if (8 == aRadix) {
fmt = "%o";
} else if (16 == aRadix) {
fmt = "%x";
char buf[128]={0,0};
char* buffer=buf;
ldiv_t r; /* result of val / base */
if (aRadix> 36 || aRadix< 2) { /* no conversion if wrong base */
return *this;
}
char buf[40];
// *** XX UNCOMMENT THIS LINE
//PR_snprintf(buf, sizeof(buf), fmt, aInteger);
sprintf(buf,fmt,aInteger);
if (aInteger < 0)
*buffer++ = '-';
r = ldiv (labs(aInteger), aRadix);
/* output digits of val/base first */
if (r.quot > 0)
buffer = ltoa ( r.quot, buf, aRadix);
/* output last digit */
int len=strlen(buffer);
buf[len] = "0123456789abcdefghijklmnopqrstuvwxyz"[(int)r.rem];
buf[len+1] =0;
return Append(buf);
}

View File

@@ -952,16 +952,27 @@ nsCString& nsCString::Append(char aChar) {
* @return
*/
nsCString& nsCString::Append(PRInt32 aInteger,PRInt32 aRadix) {
char* fmt = "%d";
if (8 == aRadix) {
fmt = "%o";
} else if (16 == aRadix) {
fmt = "%x";
char buf[128]={0,0};
char* buffer=buf;
ldiv_t r; /* result of val / base */
if (aRadix> 36 || aRadix< 2) { /* no conversion if wrong base */
return *this;
}
char buf[40];
// *** XX UNCOMMENT THIS LINE
//PR_snprintf(buf, sizeof(buf), fmt, aInteger);
sprintf(buf,fmt,aInteger);
if (aInteger < 0)
*buffer++ = '-';
r = ldiv (labs(aInteger), aRadix);
/* output digits of val/base first */
if (r.quot > 0)
buffer = ltoa ( r.quot, buf, aRadix);
/* output last digit */
int len=strlen(buffer);
buf[len] = "0123456789abcdefghijklmnopqrstuvwxyz"[(int)r.rem];
buf[len+1] =0;
return Append(buf);
}

View File

@@ -1124,16 +1124,27 @@ nsString& nsString::Append(PRUnichar aChar) {
* @return
*/
nsString& nsString::Append(PRInt32 aInteger,PRInt32 aRadix) {
char* fmt = "%d";
if (8 == aRadix) {
fmt = "%o";
} else if (16 == aRadix) {
fmt = "%x";
char buf[128]={0,0};
char* buffer=buf;
ldiv_t r; /* result of val / base */
if (aRadix> 36 || aRadix< 2) { /* no conversion if wrong base */
return *this;
}
char buf[40];
// *** XX UNCOMMENT THIS LINE
//PR_snprintf(buf, sizeof(buf), fmt, aInteger);
sprintf(buf,fmt,aInteger);
if (aInteger < 0)
*buffer++ = '-';
r = ldiv (labs(aInteger), aRadix);
/* output digits of val/base first */
if (r.quot > 0)
buffer = ltoa ( r.quot, buf, aRadix);
/* output last digit */
int len=strlen(buffer);
buf[len] = "0123456789abcdefghijklmnopqrstuvwxyz"[(int)r.rem];
buf[len+1] =0;
return Append(buf);
}