switch (type) { case 'f': numdigits = prec; mode = 3; break; case 'E': exp = 'E';  case 'e': numdigits = prec + 1; mode = 2; break; case 'G': exp = 'E';  case 'g': if (prec == 0) { prec = 1; } numdigits = prec; mode = 2; break; default: NS_ERROR("invalid type passed to cvt_f"); }  if (PR_dtoa(d, mode, numdigits, &decpt, &sign, &endnum, num, bufsz) == PR_FAILURE) { buf[0] = '\0'; return -1; } numdigits = endnum - num; nump = num;  if (sign) { *bufp++ = '-'; } else if (flags & _SIGNED) { *bufp++ = '+'; }  if (decpt == 9999) { while ((*bufp++ = *nump++)) { } } else {  switch (type) {  case 'E': case 'e':  *bufp++ = *nump++; if (prec > 0) { *bufp++ = '.'; while (*nump) { *bufp++ = *nump++; prec--; } while (prec-- > 0) { *bufp++ = '0'; } } *bufp++ = exp; PR_snprintf(bufp, bufsz - (bufp - buf), "%+03d", decpt-1); break;  case 'f':  if (decpt < 1) { *bufp++ = '0'; if (prec > 0) { *bufp++ = '.'; while (decpt++ && prec-- > 0) { *bufp++ = '0'; } while (*nump && prec-- > 0) { *bufp++ = *nump++; } while (prec-- > 0) { *bufp++ = '0'; } } } else { while (*nump && decpt-- > 0) { *bufp++ = *nump++; } while (decpt-- > 0) { *bufp++ = '0'; } if (prec > 0) { *bufp++ = '.'; while (*nump && prec-- > 0) { *bufp++ = *nump++; } while (prec-- > 0) { *bufp++ = '0'; } } } *bufp = '\0'; break;  case 'G': case 'g':  if ((decpt < -3) || ((decpt - 1) >= prec)) { *bufp++ = *nump++; numdigits--; if (numdigits > 0) { *bufp++ = '.'; while (*nump) { *bufp++ = *nump++; } } *bufp++ = exp; PR_snprintf(bufp, bufsz - (bufp - buf), "%+03d", decpt-1); } else { if (decpt < 1) { *bufp++ = '0'; if (prec > 0) { *bufp++ = '.'; while (decpt++) { *bufp++ = '0'; } while (*nump) { *bufp++ = *nump++; } } } else { while (*nump && decpt-- > 0) { *bufp++ = *nump++; numdigits--; } while (decpt-- > 0) { *bufp++ = '0'; } if (numdigits > 0) { *bufp++ = '.'; while (*nump) { *bufp++ = *nump++; } } } *bufp = '\0'; }
static int cvt_f(SprintfState *ss, double d, const PRUnichar *fmt0, const PRUnichar *fmt1){    char fin[20];    char fout[300];    PRUnichar fout2[300];    int amount = fmt1 - fmt0;    int i;    PR_ASSERT((amount > 0) && (amount < (int)sizeof(fin)));    if (amount >= (int)sizeof(fin)) {	/* Totally bogus % command to sprintf. Just ignore it */	return 0;    }    for(i=0;i<amount;i++)      fin[i] = (char) fmt0[i]; // cast down here    fin[amount] = 0;    /* Convert floating point using the native sprintf code */#ifdef DEBUG    {        const char *p = fin;        while (*p) {            PR_ASSERT(*p != 'L');            p++;        }    }#endif    sprintf(fout, fin, d);    /*    ** This assert will catch overflow's of fout, when building with    ** debugging on. At least this way we can track down the evil piece    ** of calling code and fix it!    */    PR_ASSERT((nsCRT::strlen(fout)*2) < sizeof(fout));    for(i=0; fout[i]; i++)        fout2[i]=fout[i];    fout2[i] = 0;    return (*ss->stuff)(ss, fout2, nsCRT::strlen(fout2));}