aboutsummaryrefslogtreecommitdiff
path: root/idlestat.c
diff options
context:
space:
mode:
authorTuukka Tikkanen <tuukka.tikkanen@linaro.org>2014-12-03 07:25:05 +0200
committerTuukka Tikkanen <tuukka.tikkanen@linaro.org>2014-12-05 09:52:38 +0200
commit8f4a5b446ec48ce6fb54af2e3d37f0558fee0483 (patch)
tree7777306c110c27e196319489a13b16725851d5ab /idlestat.c
parent73b0121e97a604ee0d97c66c41b239dc76739ae7 (diff)
Idlestat: Prevent printing control character in error message
The error message printed out by bad_filename() contains the illegal character detected. In case the character is not printable, display the hexadecimal code for it instead of writing out the literal character as is. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>
Diffstat (limited to 'idlestat.c')
-rw-r--r--idlestat.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/idlestat.c b/idlestat.c
index 47f975e..cf6a1e9 100644
--- a/idlestat.c
+++ b/idlestat.c
@@ -36,6 +36,7 @@
#include <sys/resource.h>
#include <sys/wait.h>
#include <assert.h>
+#include <ctype.h>
#include "idlestat.h"
#include "utils.h"
@@ -67,7 +68,11 @@ static inline int bad_filename(const char *filename)
for (; *c; c++) {
/* Check for control chars and other bad characters */
if (*c < 32 || *c == '<' || *c == '>' || *c == '|') {
- fprintf(stderr, "Bad character '%c' found in filename\n", *c);
+ fprintf(stderr,
+ isprint(*c) ?
+ "Bad character '%c' found in filename\n" :
+ "Bad character 0x%02x found in filename\n",
+ *c);
return EINVAL;
}
}