aboutsummaryrefslogtreecommitdiffhomepage
path: root/builtin_printf.cpp
diff options
context:
space:
mode:
authorGravatar Siteshwar Vashisht <siteshwar@gmail.com>2013-03-04 23:25:14 +0530
committerGravatar Siteshwar Vashisht <siteshwar@gmail.com>2013-03-04 23:25:14 +0530
commit42be7733fe9b214be187eb7b3719a00b0f43d07d (patch)
tree5fc650880529ec594c731db74c8891105b14131a /builtin_printf.cpp
parent97c9c9c9d123f1a31f99508d978ad1c77a86f291 (diff)
Return EXIT_FAILURE in printf builtin if conversion to number fails
Diffstat (limited to 'builtin_printf.cpp')
-rw-r--r--builtin_printf.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/builtin_printf.cpp b/builtin_printf.cpp
index b579d15e..f184c2ad 100644
--- a/builtin_printf.cpp
+++ b/builtin_printf.cpp
@@ -68,6 +68,8 @@
# define PRIdMAX L"ld"
+static int exit_code;
+
/* True if the POSIXLY_CORRECT environment variable is set. */
static bool posixly_correct;
@@ -120,6 +122,7 @@ static void verify_numeric (const wchar_t *s, const wchar_t *end)
if (errno)
{
append_format(stderr_buffer, L"%ls", s);
+ exit_code = EXIT_FAILURE;
}
else if (*end)
{
@@ -127,6 +130,7 @@ static void verify_numeric (const wchar_t *s, const wchar_t *end)
append_format(stderr_buffer, _(L"%ls: expected a numeric value"), s);
else
append_format(stderr_buffer, _(L"%ls: value not completely converted"), s);
+ exit_code = EXIT_FAILURE;
}
}
@@ -175,7 +179,7 @@ print_esc_char (wchar_t c)
append_format(stdout_buffer, L"%lc", L'\b');
break;
case L'c': /* Cancel the rest of the output. */
- exit (EXIT_SUCCESS);
+ return;
break;
case L'f': /* Form feed. */
append_format(stdout_buffer, L"%lc", L'\f');
@@ -610,6 +614,8 @@ static int builtin_printf(parser_t &parser, wchar_t **argv)
int args_used;
int argc = builtin_count_args(argv);
+ exit_code = EXIT_SUCCESS;
+
if (argc <= 1)
{
append_format(stderr_buffer, _(L"missing operand"));
@@ -627,5 +633,5 @@ static int builtin_printf(parser_t &parser, wchar_t **argv)
argv += args_used;
}
while (args_used > 0 && argc > 0);
- return 0;
+ return exit_code;
}