summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garcia Campos <carlosgc@gnome.org>2014-06-06 19:32:40 +0200
committerCarlos Garcia Campos <carlosgc@gnome.org>2014-06-06 19:32:40 +0200
commite94ff24d1393487547ea835ff5fbd8a68bf574c3 (patch)
tree94c8e96ecbc0e9629951f405c942ae59f914564f
parent2bed20d160771686d4c3eac2bb6a0650595c4dba (diff)
xpdf304: Handle NULL strings passed as arguments of GooString::appendfv
-rw-r--r--goo/GooString.cc34
-rw-r--r--goo/GooString.h12
2 files changed, 28 insertions, 18 deletions
diff --git a/goo/GooString.cc b/goo/GooString.cc
index 58d980a1..dc9ace87 100644
--- a/goo/GooString.cc
+++ b/goo/GooString.cc
@@ -253,7 +253,7 @@ GooString::GooString(GooString *str1, GooString *str2) {
GooString *GooString::fromInt(int x) {
char buf[24]; // enough space for 64-bit ints plus a little extra
- char *p;
+ const char *p;
int len;
formatInt(x, buf, sizeof(buf), gFalse, 0, 10, &p, &len);
return new GooString(p, len);
@@ -330,7 +330,7 @@ GooString *GooString::appendfv(const char *fmt, va_list argList) {
char buf[65];
int len, i;
const char *p0, *p1;
- char *str;
+ const char *str;
argsLen = 0;
argsSize = 8;
@@ -599,13 +599,23 @@ GooString *GooString::appendfv(const char *fmt, va_list argList) {
reverseAlign = !reverseAlign;
break;
case fmtString:
- str = arg.s;
- len = strlen(str);
+ if (arg.s) {
+ str = arg.s;
+ len = strlen(str);
+ } else {
+ str = "(null)";
+ len = 6;
+ }
reverseAlign = !reverseAlign;
break;
case fmtGooString:
- str = arg.gs->getCString();
- len = arg.gs->getLength();
+ if (arg.gs) {
+ str = arg.gs->getCString();
+ len = arg.gs->getLength();
+ } else {
+ str = "(null)";
+ len = 6;
+ }
reverseAlign = !reverseAlign;
break;
case fmtSpace:
@@ -653,11 +663,11 @@ static const char upperCaseDigits[17] = "0123456789ABCDEF";
#ifdef LLONG_MAX
void GooString::formatInt(long long x, char *buf, int bufSize,
GBool zeroFill, int width, int base,
- char **p, int *len, GBool upperCase) {
+ const char **p, int *len, GBool upperCase) {
#else
void GooString::formatInt(long x, char *buf, int bufSize,
GBool zeroFill, int width, int base,
- char **p, int *len, GBool upperCase) {
+ const char **p, int *len, GBool upperCase) {
#endif
const char *vals = upperCase ? upperCaseDigits : lowerCaseDigits;
GBool neg;
@@ -698,11 +708,11 @@ void GooString::formatInt(long x, char *buf, int bufSize,
#ifdef ULLONG_MAX
void GooString::formatUInt(unsigned long long x, char *buf, int bufSize,
GBool zeroFill, int width, int base,
- char **p, int *len, GBool upperCase) {
+ const char **p, int *len, GBool upperCase) {
#else
void GooString::formatUInt(Gulong x, char *buf, int bufSize,
GBool zeroFill, int width, int base,
- char **p, int *len, GBool upperCase) {
+ const char **p, int *len, GBool upperCase) {
#endif
const char *vals = upperCase ? upperCaseDigits : lowerCaseDigits;
int i, j;
@@ -726,7 +736,7 @@ void GooString::formatUInt(Gulong x, char *buf, int bufSize,
}
void GooString::formatDouble(double x, char *buf, int bufSize, int prec,
- GBool trim, char **p, int *len) {
+ GBool trim, const char **p, int *len) {
GBool neg, started;
double x2;
int d, i, j;
@@ -765,7 +775,7 @@ void GooString::formatDouble(double x, char *buf, int bufSize, int prec,
}
void GooString::formatDoubleSmallAware(double x, char *buf, int bufSize, int prec,
- GBool trim, char **p, int *len)
+ GBool trim, const char **p, int *len)
{
double absX = fabs(x);
if (absX >= 0.1) {
diff --git a/goo/GooString.h b/goo/GooString.h
index 5932be99..72df4a82 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -185,25 +185,25 @@ private:
#ifdef LLONG_MAX
static void formatInt(long long x, char *buf, int bufSize,
GBool zeroFill, int width, int base,
- char **p, int *len, GBool upperCase = gFalse);
+ const char **p, int *len, GBool upperCase = gFalse);
#else
static void formatInt(long x, char *buf, int bufSize,
GBool zeroFill, int width, int base,
- char **p, int *len, GBool upperCase = gFalse);
+ const char **p, int *len, GBool upperCase = gFalse);
#endif
#ifdef ULLONG_MAX
static void formatUInt(unsigned long long x, char *buf, int bufSize,
GBool zeroFill, int width, int base,
- char **p, int *len, GBool upperCase = gFalse);
+ const char **p, int *len, GBool upperCase = gFalse);
#else
static void formatUInt(Gulong x, char *buf, int bufSize,
GBool zeroFill, int width, int base,
- char **p, int *len, GBool upperCase = gFalse);
+ const char **p, int *len, GBool upperCase = gFalse);
#endif
static void formatDouble(double x, char *buf, int bufSize, int prec,
- GBool trim, char **p, int *len);
+ GBool trim, const char **p, int *len);
static void formatDoubleSmallAware(double x, char *buf, int bufSize, int prec,
- GBool trim, char **p, int *len);
+ GBool trim, const char **p, int *len);
};
#endif