Skip to content
This repository was archived by the owner on Sep 28, 2023. It is now read-only.

Commit 1bcd0fc

Browse files
committed
Use snprintf instead of fcvt()
fcvt is deprecated (from gcvt(3)): Marked as LEGACY in POSIX.1-2001. POSIX.1-2008 removes the specification of gcvt(), recommending the use of sprintf(3) instead (though snprintf(3) may be preferable) and does not exist on e.g. FreeBSD.
1 parent 75e9dc0 commit 1bcd0fc

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎src/common/OMISC.cpp‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <stdlib.h>
3838
#include <time.h>
3939
#include <ctype.h>
40+
#include <math.h>
4041

4142
#include <ALL.h>
4243
#include <OSTR.h>
@@ -755,10 +756,13 @@ char* Misc::format(double inNum, int formatType)
755756

756757
static char outBuf[35];
757758
char *outPtr=outBuf;
759+
char floatBuf[35];
758760
char *floatStr;
759761
int i, intDigit, sign; // intDigit = no. of integer digits
760762

761-
floatStr = fcvt( inNum, MONEY_DEC_PLACE, &intDigit, &sign );
763+
intDigit = snprintf(floatBuf, sizeof(floatBuf), "%.0lf", fabs(inNum) * 100.0);
764+
intDigit -= 2;
765+
floatStr = floatBuf;
762766

763767
#ifdef DEBUG
764768
if( intDigit > 29 ) // integer digits can't exceed 29

0 commit comments

Comments
 (0)