stdlib: SDL_snprintf now adds decimal places for ("%f", 0.0). This patch was from @Markvy (thanks!). Fixes #4795.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c
index 67b376e..8a49af5 100644
--- a/src/stdlib/SDL_string.c
+++ b/src/stdlib/SDL_string.c
@@ -1636,51 +1636,38 @@ SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg)
{
size_t length = 0;
- if (arg) {
- /* This isn't especially accurate, but hey, it's easy. :) */
- unsigned long value;
+ /* This isn't especially accurate, but hey, it's easy. :) */
+ unsigned long value;
- if (arg < 0) {
- if (length < maxlen) {
- text[length] = '-';
- }
- ++length;
- arg = -arg;
- } else if (info->force_sign) {
- if (length < maxlen) {
- text[length] = '+';
- }
- ++length;
- }
- value = (unsigned long) arg;
- length += SDL_PrintUnsignedLong(TEXT_AND_LEN_ARGS, NULL, value);
- arg -= value;
- if (info->precision < 0) {
- info->precision = 6;
+ if (arg < 0) {
+ if (length < maxlen) {
+ text[length] = '-';
}
- if (info->force_type || info->precision > 0) {
- int mult = 10;
- if (length < maxlen) {
- text[length] = '.';
- }
- ++length;
- while (info->precision-- > 0) {
- value = (unsigned long) (arg * mult);
- length += SDL_PrintUnsignedLong(TEXT_AND_LEN_ARGS, NULL, value);
- arg -= (double) value / mult;
- mult *= 10;
- }
+ ++length;
+ arg = -arg;
+ } else if (info->force_sign) {
+ if (length < maxlen) {
+ text[length] = '+';
}
- } else {
+ ++length;
+ }
+ value = (unsigned long) arg;
+ length += SDL_PrintUnsignedLong(TEXT_AND_LEN_ARGS, NULL, value);
+ arg -= value;
+ if (info->precision < 0) {
+ info->precision = 6;
+ }
+ if (info->force_type || info->precision > 0) {
+ int mult = 10;
if (length < maxlen) {
- text[length] = '0';
+ text[length] = '.';
}
++length;
- if (info->force_type) {
- if (length < maxlen) {
- text[length] = '.';
- }
- ++length;
+ while (info->precision-- > 0) {
+ value = (unsigned long) (arg * mult);
+ length += SDL_PrintUnsignedLong(TEXT_AND_LEN_ARGS, NULL, value);
+ arg -= (double) value / mult;
+ mult *= 10;
}
}