From af77e1d8e1b4458d091119f74fbeeea7659fcd8d Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 22 Nov 2011 16:40:37 +0000 Subject: [PATCH] Don't rely on implicit promotion of float to double in printf args. (cherry picked from commit 9b102aae65449a8d321e8cf44a3993af558291db) --- df/output.c | 2 +- generator/generator_fish.ml | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/df/output.c b/df/output.c index ea981b8..2950fff 100644 --- a/df/output.c +++ b/df/output.c @@ -157,7 +157,7 @@ print_stat (const char *name, const char *uuid_param, /* Use 'ceil' on the percentage in order to emulate what df itself does. */ snprintf (buf[3], MAX_LEN, "%3.0f%%", ceil (percent)); else - snprintf (buf[3], MAX_LEN, "%.1f", percent); + snprintf (buf[3], MAX_LEN, "%.1f", (double) percent); cols[3] = buf[3]; #undef MAX_LEN diff --git a/generator/generator_fish.ml b/generator/generator_fish.ml index 03711d1..3d52421 100644 --- a/generator/generator_fish.ml +++ b/generator/generator_fish.ml @@ -267,9 +267,11 @@ Guestfish will prompt for these separately." pr " printf (\"%%s%s: %%c\\n\", indent, %s->%s);\n" name typ name | name, FOptPercent -> - pr " if (%s->%s >= 0) printf (\"%%s%s: %%g %%%%\\n\", indent, %s->%s);\n" - typ name name typ name; - pr " else printf (\"%%s%s: \\n\", indent);\n" name + pr " if (%s->%s >= 0)\n" typ name; + pr " printf (\"%%s%s: %%g %%%%\\n\", indent, (double) %s->%s);\n" + name typ name; + pr " else\n"; + pr " printf (\"%%s%s: \\n\", indent);\n" name ) cols; pr "}\n"; pr "\n"; -- 1.8.3.1