int padlen, strln; /* amount to pad */
int cnt = 0;
- if (value == 0) {
- value = "<NULL>";
- }
if (flags & DP_F_DOT && max < 0) { /* Max not specified */
max = 0;
} else if (max < 0) {
max = maxlen;
}
+ if (!value) {
+ value = "<NULL>";
+ }
strln = strlen(value);
if (strln > max) {
strln = max; /* truncate to max */
char iconvert[311];
char fconvert[311];
char *result;
+ char dummy[10];
int dec_pt, sig;
int r_length;
extern char *fcvt(double value, int ndigit, int *decpt, int *sign);
intpart++;
fracpart -= (int64_t)pow10(max);
}
+
#ifdef DEBUG_SNPRINTF
printf("fmtfp: %g %d.%d min=%d max=%d\n",
(double)fvalue, intpart, fracpart, min, max);
result = fcvt(ufvalue, max, &dec_pt, &sig);
# endif
- r_length = strlen(result);
+ if (!result) {
+ r_length = 0;
+ result = dummy;
+ } else {
+ r_length = strlen(result);
+ }
/*
* Fix broken fcvt implementation returns..
fplace = 0;
- while (r_length)
+ while (r_length) {
fconvert[fplace++] = result[--r_length];
+ }
while ((dec_pt < 0) && (fplace < max)) {
fconvert[fplace++] = '0';