[PATCH 08/10] scripts/basic/fixdep: Complete error handling in print_config()

From: SF Markus Elfring
Date: Fri Oct 28 2016 - 04:39:25 EST


From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 27 Oct 2016 22:45:03 +0200

Return values were not checked from calls of the function "printf"
and "putchar".

This issue was detected also by using the Coccinelle software.

* Add a bit of exception handling there.

* Optimise this function implementation a bit by replacing two output calls
with the functions "fputs" and "puts".

Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
---
scripts/basic/fixdep.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index 2c4ec91..f5ff6eea 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -142,16 +142,26 @@ static void print_config(const char *m, int slen)
{
int c, i;

- printf(" $(wildcard include/config/");
+ if (fputs(" $(wildcard include/config/", stdout) < 0)
+ goto put_failure;
for (i = 0; i < slen; i++) {
c = m[i];
if (c == '_')
c = '/';
else
c = tolower(c);
- putchar(c);
+ if (putchar(c) == EOF)
+ goto put_failure;
+ }
+ if (puts(".h) \\") < 0) {
+put_failure:
+ {
+ int code = errno;
+
+ perror("fixdep: print_config");
+ exit(code);
+ }
}
- printf(".h) \\\n");
}

static void do_extra_deps(void)
--
2.10.1