|
2 | 2 | * Copyright (c) 1983, 1995, 1996 Eric P. Allman |
3 | 3 | * Copyright (c) 1988, 1993 |
4 | 4 | * The Regents of the University of California. All rights reserved. |
5 | | - * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group |
| 5 | + * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group |
6 | 6 | * |
7 | 7 | * Redistribution and use in source and binary forms, with or without |
8 | 8 | * modification, are permitted provided that the following conditions |
@@ -739,12 +739,8 @@ find_arguments(const char *format, va_list args, |
739 | 739 | int longflag; |
740 | 740 | int fmtpos; |
741 | 741 | int i; |
742 | | - int last_dollar; |
743 | | - PrintfArgType argtypes[PG_NL_ARGMAX + 1]; |
744 | | - |
745 | | - /* Initialize to "no dollar arguments known" */ |
746 | | - last_dollar = 0; |
747 | | - MemSet(argtypes, 0, sizeof(argtypes)); |
| 742 | + int last_dollar = 0; /* Init to "no dollar arguments known" */ |
| 743 | + PrintfArgType argtypes[PG_NL_ARGMAX + 1] = {0}; |
748 | 744 |
|
749 | 745 | /* |
750 | 746 | * This loop must accept the same format strings as the one in dopr(). |
@@ -985,8 +981,8 @@ fmtptr(const void *value, PrintfTarget *target) |
985 | 981 | int vallen; |
986 | 982 | char convert[64]; |
987 | 983 |
|
988 | | - /* we rely on regular C library's sprintf to do the basic conversion */ |
989 | | - vallen = sprintf(convert, "%p", value); |
| 984 | + /* we rely on regular C library's snprintf to do the basic conversion */ |
| 985 | + vallen = snprintf(convert, sizeof(convert), "%p", value); |
990 | 986 | if (vallen < 0) |
991 | 987 | target->failed = true; |
992 | 988 | else |
@@ -1136,11 +1132,11 @@ fmtfloat(double value, char type, int forcesign, int leftjust, |
1136 | 1132 | int padlen; /* amount to pad with spaces */ |
1137 | 1133 |
|
1138 | 1134 | /* |
1139 | | - * We rely on the regular C library's sprintf to do the basic conversion, |
| 1135 | + * We rely on the regular C library's snprintf to do the basic conversion, |
1140 | 1136 | * then handle padding considerations here. |
1141 | 1137 | * |
1142 | 1138 | * The dynamic range of "double" is about 1E+-308 for IEEE math, and not |
1143 | | - * too wildly more than that with other hardware. In "f" format, sprintf |
| 1139 | + * too wildly more than that with other hardware. In "f" format, snprintf |
1144 | 1140 | * could therefore generate at most 308 characters to the left of the |
1145 | 1141 | * decimal point; while we need to allow the precision to get as high as |
1146 | 1142 | * 308+17 to ensure that we don't truncate significant digits from very |
@@ -1192,14 +1188,14 @@ fmtfloat(double value, char type, int forcesign, int leftjust, |
1192 | 1188 | fmt[2] = '*'; |
1193 | 1189 | fmt[3] = type; |
1194 | 1190 | fmt[4] = '\0'; |
1195 | | - vallen = sprintf(convert, fmt, prec, value); |
| 1191 | + vallen = snprintf(convert, sizeof(convert), fmt, prec, value); |
1196 | 1192 | } |
1197 | 1193 | else |
1198 | 1194 | { |
1199 | 1195 | fmt[0] = '%'; |
1200 | 1196 | fmt[1] = type; |
1201 | 1197 | fmt[2] = '\0'; |
1202 | | - vallen = sprintf(convert, fmt, value); |
| 1198 | + vallen = snprintf(convert, sizeof(convert), fmt, value); |
1203 | 1199 | } |
1204 | 1200 | if (vallen < 0) |
1205 | 1201 | goto fail; |
@@ -1328,7 +1324,7 @@ pg_strfromd(char *str, size_t count, int precision, double value) |
1328 | 1324 | fmt[2] = '*'; |
1329 | 1325 | fmt[3] = 'g'; |
1330 | 1326 | fmt[4] = '\0'; |
1331 | | - vallen = sprintf(convert, fmt, precision, value); |
| 1327 | + vallen = snprintf(convert, sizeof(convert), fmt, precision, value); |
1332 | 1328 | if (vallen < 0) |
1333 | 1329 | { |
1334 | 1330 | target.failed = true; |
|
0 commit comments