aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/bc.c65
1 files changed, 39 insertions, 26 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 26ab94cbd..aa478e461 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -976,7 +976,20 @@ static void bc_verror_msg(const char *fmt, va_list p)
976 } 976 }
977} 977}
978 978
979static NOINLINE int bc_error_fmt(const char *fmt, ...) 979#if ENABLE_FEATURE_BC_SIGNALS
980# define ERRORFUNC /*nothing*/
981# define ERROR_RETURN(a) a
982#else
983# if ENABLE_FEATURE_CLEAN_UP
984# define ERRORFUNC /*nothing*/
985# define ERROR_RETURN(a) a
986# else
987# define ERRORFUNC NORETURN
988# define ERROR_RETURN(a) /*nothing*/
989# endif
990#endif
991
992static NOINLINE ERRORFUNC int bc_error_fmt(const char *fmt, ...)
980{ 993{
981 va_list p; 994 va_list p;
982 995
@@ -986,7 +999,7 @@ static NOINLINE int bc_error_fmt(const char *fmt, ...)
986 999
987 if (!ENABLE_FEATURE_CLEAN_UP && !G_ttyin) 1000 if (!ENABLE_FEATURE_CLEAN_UP && !G_ttyin)
988 exit(1); 1001 exit(1);
989 return BC_STATUS_FAILURE; 1002 ERROR_RETURN(return BC_STATUS_FAILURE;)
990} 1003}
991 1004
992#if ENABLE_BC 1005#if ENABLE_BC
@@ -1016,52 +1029,52 @@ static NOINLINE int bc_posix_error_fmt(const char *fmt, ...)
1016// function must not have caller-cleaned parameters on stack. 1029// function must not have caller-cleaned parameters on stack.
1017// Unfortunately, vararg function API does exactly that on most arches. 1030// Unfortunately, vararg function API does exactly that on most arches.
1018// Thus, use these shims for the cases when we have no vararg PARAMS: 1031// Thus, use these shims for the cases when we have no vararg PARAMS:
1019static int bc_error(const char *msg) 1032static ERRORFUNC int bc_error(const char *msg)
1020{ 1033{
1021 return bc_error_fmt("%s", msg); 1034 ERROR_RETURN(return) bc_error_fmt("%s", msg);
1022} 1035}
1023#if ENABLE_BC 1036static ERRORFUNC int bc_error_bad_character(char c)
1024static int bc_POSIX_requires(const char *msg)
1025{ 1037{
1026 return bc_posix_error_fmt("POSIX requires %s", msg); 1038 ERROR_RETURN(return) bc_error_fmt("bad character '%c'", c);
1027} 1039}
1028static int bc_POSIX_does_not_allow(const char *msg) 1040static ERRORFUNC int bc_error_bad_expression(void)
1029{ 1041{
1030 return bc_posix_error_fmt("%s%s", "POSIX does not allow ", msg); 1042 ERROR_RETURN(return) bc_error("bad expression");
1031} 1043}
1032static int bc_POSIX_does_not_allow_bool_ops_this_is_bad(const char *msg) 1044static ERRORFUNC int bc_error_bad_token(void)
1033{ 1045{
1034 return bc_posix_error_fmt("%s%s %s", "POSIX does not allow ", "boolean operators; the following is bad:", msg); 1046 ERROR_RETURN(return) bc_error("bad token");
1035} 1047}
1036static int bc_POSIX_does_not_allow_empty_X_expression_in_for(const char *msg) 1048static ERRORFUNC int bc_error_stack_has_too_few_elements(void)
1037{ 1049{
1038 return bc_posix_error_fmt("%san empty %s expression in a for loop", "POSIX does not allow ", msg); 1050 ERROR_RETURN(return) bc_error("stack has too few elements");
1039} 1051}
1040#endif 1052static ERRORFUNC int bc_error_variable_is_wrong_type(void)
1041static int bc_error_bad_character(char c)
1042{ 1053{
1043 return bc_error_fmt("bad character '%c'", c); 1054 ERROR_RETURN(return) bc_error("variable is wrong type");
1044} 1055}
1045static int bc_error_bad_expression(void) 1056static ERRORFUNC int bc_error_nested_read_call(void)
1046{ 1057{
1047 return bc_error("bad expression"); 1058 ERROR_RETURN(return) bc_error("read() call inside of a read() call");
1048} 1059}
1049static int bc_error_bad_token(void) 1060#if ENABLE_BC
1061static int bc_POSIX_requires(const char *msg)
1050{ 1062{
1051 return bc_error("bad token"); 1063 return bc_posix_error_fmt("POSIX requires %s", msg);
1052} 1064}
1053static int bc_error_stack_has_too_few_elements(void) 1065static int bc_POSIX_does_not_allow(const char *msg)
1054{ 1066{
1055 return bc_error("stack has too few elements"); 1067 return bc_posix_error_fmt("%s%s", "POSIX does not allow ", msg);
1056} 1068}
1057static int bc_error_variable_is_wrong_type(void) 1069static int bc_POSIX_does_not_allow_bool_ops_this_is_bad(const char *msg)
1058{ 1070{
1059 return bc_error("variable is wrong type"); 1071 return bc_posix_error_fmt("%s%s %s", "POSIX does not allow ", "boolean operators; the following is bad:", msg);
1060} 1072}
1061static int bc_error_nested_read_call(void) 1073static int bc_POSIX_does_not_allow_empty_X_expression_in_for(const char *msg)
1062{ 1074{
1063 return bc_error("read() call inside of a read() call"); 1075 return bc_posix_error_fmt("%san empty %s expression in a for loop", "POSIX does not allow ", msg);
1064} 1076}
1077#endif
1065 1078
1066static void bc_vec_grow(BcVec *v, size_t n) 1079static void bc_vec_grow(BcVec *v, size_t n)
1067{ 1080{