From: Dan Carpenter Date: Fri, 11 Jan 2013 13:37:12 +0000 (+0300) Subject: smatch: introduce expr_to_str_complex() X-Git-Tag: 1.57~60 X-Git-Url: https://repo.or.cz/w/smatch.git/commitdiff_plain/4206fcd1e67bef4aa29cc836b4be443e4eba507c smatch: introduce expr_to_str_complex() This version doesn't need a NULL parameter. As a side note, I don't really care for the _complex() on the end. It sort of made sense to talk about complex variables but it doesn't make sense to talk about complex expressions. The reason for the split is that if you have a pointer "p" and an offset "i" and you do "p[i] = 1;" then if either "p" or "i" changes you don't know what p[i] is. I originally had the _complex() as default and a _simple() version. But then I made _simple() the default and created the _complex() version. Naming is hard. Signed-off-by: Dan Carpenter --- diff --git a/check_access_ok_math.c b/check_access_ok_math.c index 03743357..db99f2a1 100644 --- a/check_access_ok_math.c +++ b/check_access_ok_math.c @@ -51,7 +51,7 @@ static void match_size(struct expression *size_expr) if (!can_overflow(size_expr)) return; - name = expr_to_str_sym_complex(size_expr, NULL); + name = expr_to_str_complex(size_expr); sm_msg("warn: math in access_ok() is dangerous '%s'", name); free_string(name); diff --git a/check_assigned_expr.c b/check_assigned_expr.c index f3b7fdcf..1db6ad5c 100644 --- a/check_assigned_expr.c +++ b/check_assigned_expr.c @@ -35,7 +35,7 @@ static struct smatch_state *alloc_my_state(struct expression *expr) state = __alloc_smatch_state(0); expr = strip_expr(expr); - name = expr_to_str_sym_complex(expr, NULL); + name = expr_to_str_complex(expr); state->name = alloc_sname(name); free_string(name); state->data = expr; diff --git a/check_debug.c b/check_debug.c index da1078fc..191e22d3 100644 --- a/check_debug.c +++ b/check_debug.c @@ -57,7 +57,7 @@ static void match_print_implied(const char *fn, struct expression *expr, void *i arg = get_argument_from_call_expr(expr->args, 0); get_implied_rl(arg, &rl); - name = expr_to_str_sym_complex(arg, NULL); + name = expr_to_str_complex(arg); sm_msg("implied: %s = '%s'", name, show_ranges(rl)); free_string(name); } @@ -69,7 +69,7 @@ static void match_print_implied_min(const char *fn, struct expression *expr, voi char *name; arg = get_argument_from_call_expr(expr->args, 0); - name = expr_to_str_sym_complex(arg, NULL); + name = expr_to_str_complex(arg); if (get_implied_min(arg, &sval)) sm_msg("implied min: %s = %s", name, sval_to_str(sval)); @@ -86,7 +86,7 @@ static void match_print_implied_max(const char *fn, struct expression *expr, voi char *name; arg = get_argument_from_call_expr(expr->args, 0); - name = expr_to_str_sym_complex(arg, NULL); + name = expr_to_str_complex(arg); if (get_implied_max(arg, &sval)) sm_msg("implied max: %s = %s", name, sval_to_str(sval)); @@ -103,7 +103,7 @@ static void match_print_hard_max(const char *fn, struct expression *expr, void * char *name; arg = get_argument_from_call_expr(expr->args, 0); - name = expr_to_str_sym_complex(arg, NULL); + name = expr_to_str_complex(arg); if (get_hard_max(arg, &sval)) sm_msg("hard max: %s = %s", name, sval_to_str(sval)); @@ -120,7 +120,7 @@ static void match_print_fuzzy_max(const char *fn, struct expression *expr, void char *name; arg = get_argument_from_call_expr(expr->args, 0); - name = expr_to_str_sym_complex(arg, NULL); + name = expr_to_str_complex(arg); if (get_fuzzy_max(arg, &sval)) sm_msg("fuzzy max: %s = %s", name, sval_to_str(sval)); @@ -137,7 +137,7 @@ static void match_print_absolute_min(const char *fn, struct expression *expr, vo char *name; arg = get_argument_from_call_expr(expr->args, 0); - name = expr_to_str_sym_complex(arg, NULL); + name = expr_to_str_complex(arg); if (get_absolute_min(arg, &sval)) sm_msg("absolute min: %s = %s", name, sval_to_str(sval)); @@ -156,7 +156,7 @@ static void match_print_absolute_max(const char *fn, struct expression *expr, vo arg = get_argument_from_call_expr(expr->args, 0); get_absolute_max(arg, &sval); - name = expr_to_str_sym_complex(arg, NULL); + name = expr_to_str_complex(arg); sm_msg("absolute max: %s = %s", name, sval_to_str(sval)); free_string(name); } @@ -168,7 +168,7 @@ static void match_sval_info(const char *fn, struct expression *expr, void *info) char *name; arg = get_argument_from_call_expr(expr->args, 0); - name = expr_to_str_sym_complex(arg, NULL); + name = expr_to_str_complex(arg); if (!get_implied_value(arg, &sval)) { sm_msg("no sval for '%s'", name); @@ -221,7 +221,7 @@ static void match_buf_size(const char *fn, struct expression *expr, void *info) elements = get_array_size(arg); bytes = get_array_size_bytes(arg); - name = expr_to_str_sym_complex(arg, NULL); + name = expr_to_str_complex(arg); sm_msg("buf size: '%s' %d elements, %d bytes", name, elements, bytes); free_string(name); } diff --git a/check_dma_on_stack.c b/check_dma_on_stack.c index 20706dd3..86c54c87 100644 --- a/check_dma_on_stack.c +++ b/check_dma_on_stack.c @@ -24,7 +24,7 @@ static void match_dma_func(const char *fn, struct expression *expr, void *param) if (arg->type == EXPR_PREOP && arg->op == '&') { if (arg->unop->type != EXPR_SYMBOL) return; - name = expr_to_str_sym_complex(arg, NULL); + name = expr_to_str_complex(arg); sm_msg("error: doing dma on the stack (%s)", name); free_string(name); return; diff --git a/check_locking.c b/check_locking.c index 079202ff..d9538994 100644 --- a/check_locking.c +++ b/check_locking.c @@ -377,7 +377,7 @@ static char *get_full_name(struct expression *expr, int index) if (!arg) goto free; arg = remove_spinlock_check(arg); - name = expr_to_str_sym_complex(arg, NULL); + name = expr_to_str_complex(arg); if (!name) goto free; full_name = make_full_name(lock->name, name); diff --git a/check_macro_side_effects.c b/check_macro_side_effects.c index 0d6ddc69..4bd59490 100644 --- a/check_macro_side_effects.c +++ b/check_macro_side_effects.c @@ -24,7 +24,7 @@ static struct smatch_state *alloc_my_state(struct expression *expr) state = __alloc_smatch_state(0); expr = strip_expr(expr); - name = expr_to_str_sym_complex(expr, NULL); + name = expr_to_str_complex(expr); state->name = alloc_sname(name); free_string(name); state->data = expr; @@ -109,7 +109,7 @@ static void match_unop(struct expression *raw_expr) if (!positions_eq(old_pos, expr->pos)) return; - name = expr_to_str_sym_complex(raw_expr, NULL); + name = expr_to_str_complex(raw_expr); sm_msg("warn: side effect in macro '%s' doing '%s'", macro, name); free_string(name); diff --git a/check_min_t.c b/check_min_t.c index 19da0397..da8eef35 100644 --- a/check_min_t.c +++ b/check_min_t.c @@ -34,7 +34,7 @@ static void match_assign(struct expression *expr) if (sval_cmp(max_left, max_right) >= 0) return; - name = expr_to_str_sym_complex(expr->right, NULL); + name = expr_to_str_complex(expr->right); sm_msg("warn: min_t truncates here '%s' (%s vs %s)", name, sval_to_str(max_left), sval_to_str(max_right)); free_string(name); } diff --git a/check_missing_break.c b/check_missing_break.c index ce5ba3a8..2ef4446d 100644 --- a/check_missing_break.c +++ b/check_missing_break.c @@ -44,7 +44,7 @@ static struct smatch_state *alloc_my_state(struct expression *expr) state = __alloc_smatch_state(0); expr = strip_expr(expr); - name = expr_to_str_sym_complex(expr, NULL); + name = expr_to_str_complex(expr); if (!name) name = alloc_string(""); state->name = alloc_sname(name); diff --git a/check_overflow.c b/check_overflow.c index 4f6f9117..afea234a 100644 --- a/check_overflow.c +++ b/check_overflow.c @@ -119,7 +119,7 @@ static void array_check(struct expression *expr) return; } - name = expr_to_str_sym_complex(array_expr, NULL); + name = expr_to_str_complex(array_expr); /* Blast. Smatch can't figure out glibc's strcmp __strcmp_cg() * so it prints an error every time you compare to a string * literal array with 4 or less chars. @@ -195,8 +195,8 @@ static void match_strcpy(const char *fn, struct expression *expr, void *unused) if (data_size && dest_size >= data_size) return; - dest_name = expr_to_str_sym_complex(dest, NULL); - data_name = expr_to_str_sym_complex(data, NULL); + dest_name = expr_to_str_complex(dest); + data_name = expr_to_str_complex(data); if (data_size) sm_msg("error: %s() '%s' too large for '%s' (%d vs %d)", @@ -237,7 +237,7 @@ static void match_snprintf(const char *fn, struct expression *expr, void *unused return; if (strcmp(format, "\"%s\"")) goto free; - data_name = expr_to_str_sym_complex(data, NULL); + data_name = expr_to_str_complex(data); data_size = get_array_size_bytes(data); if (limit_size.value < data_size) sm_msg("error: snprintf() chops off the last chars of '%s': %d vs %s", @@ -269,7 +269,7 @@ static void match_sprintf(const char *fn, struct expression *expr, void *unused) return; if (strcmp(format, "\"%s\"")) goto free; - data_name = expr_to_str_sym_complex(data, NULL); + data_name = expr_to_str_complex(data); data_size = get_array_size_bytes(data); if (dest_size < data_size) sm_msg("error: sprintf() copies too much data from '%s': %d vs %d", @@ -298,7 +298,7 @@ static void match_limited(const char *fn, struct expression *expr, void *_limite if (has >= needed.value) return; - dest_name = expr_to_str_sym_complex(dest, NULL); + dest_name = expr_to_str_complex(dest); sm_msg("error: %s() '%s' too small (%d vs %s)", fn, dest_name, has, sval_to_str(needed)); free_string(dest_name); } diff --git a/check_pointer_math.c b/check_pointer_math.c index 71f7d987..814e759a 100644 --- a/check_pointer_math.c +++ b/check_pointer_math.c @@ -69,7 +69,7 @@ static void match_binop(struct expression *expr) if (!is_size_in_bytes(expr->right)) return; - name = expr_to_str_sym_complex(expr->left, NULL); + name = expr_to_str_complex(expr->left); sm_msg("warn: potential pointer math issue ('%s' is a %d bit pointer)", name, type->bit_size); free_string(name); diff --git a/check_signed.c b/check_signed.c index be5be47c..4ed734e7 100644 --- a/check_signed.c +++ b/check_signed.c @@ -45,8 +45,8 @@ static void match_assign(struct expression *expr) return; max = sval_type_max(sym); if (sval_cmp(max, sval) < 0 && !(sval.value < 256 && max.value == 127)) { - left_name = expr_to_str_sym_complex(expr->left, NULL); - right_name = expr_to_str_sym_complex(expr->right, NULL); + left_name = expr_to_str_complex(expr->left); + right_name = expr_to_str_complex(expr->right); sm_msg("warn: '%s' %s can't fit into %s '%s'", right_name, sval_to_numstr(sval), sval_to_numstr(max), left_name); free_string(left_name); @@ -61,7 +61,7 @@ static void match_assign(struct expression *expr) return; if (sval_positive_bits(sval) == 7) return; - left_name = expr_to_str_sym_complex(expr->left, NULL); + left_name = expr_to_str_complex(expr->left); if (min.value == 0) { sm_msg("warn: assigning %s to unsigned variable '%s'", sval_to_str(sval), left_name); @@ -102,11 +102,11 @@ static int cap_gt_zero_and_lt(struct expression *expr) right->op != SPECIAL_UNSIGNED_LTE) return 0; - name1 = expr_to_str_sym_complex(var, NULL); + name1 = expr_to_str_complex(var); if (!name1) goto free; - name2 = expr_to_str_sym_complex(right->left, NULL); + name2 = expr_to_str_complex(right->left); if (!name2) goto free; if (!strcmp(name1, name2)) @@ -152,11 +152,11 @@ static int cap_lt_zero_or_gt(struct expression *expr) right->op != SPECIAL_UNSIGNED_GTE) return 0; - name1 = expr_to_str_sym_complex(var, NULL); + name1 = expr_to_str_complex(var); if (!name1) goto free; - name2 = expr_to_str_sym_complex(right->left, NULL); + name2 = expr_to_str_complex(right->left); if (!name2) goto free; if (!strcmp(name1, name2)) @@ -205,7 +205,7 @@ static int print_unsigned_never_less_than_zero(struct expression *expr) if (!get_value(expr->right, &known) || known.value != 0) return 0; - name = expr_to_str_sym_complex(expr->left, NULL); + name = expr_to_str_complex(expr->left); sm_msg("warn: unsigned '%s' is never less than zero.", name); free_string(name); return 1; @@ -268,7 +268,7 @@ static void match_condition(struct expression *expr) } if (!possibly_true_rl(rl_left, expr->op, rl_right)) { - char *name = expr_to_str_sym_complex(expr, NULL); + char *name = expr_to_str_complex(expr); sm_msg("warn: impossible condition '(%s) => (%s %s %s)'", name, show_ranges(rl_left), show_special(expr->op), @@ -277,7 +277,7 @@ static void match_condition(struct expression *expr) } if (!possibly_false_rl(rl_left, expr->op, rl_right)) { - char *name = expr_to_str_sym_complex(expr, NULL); + char *name = expr_to_str_complex(expr); sm_msg("warn: always true condition '(%s) => (%s %s %s)'", name, show_ranges(rl_left_orig), show_special(expr->op), diff --git a/check_sizeof.c b/check_sizeof.c index 0cd4f505..afbcb24a 100644 --- a/check_sizeof.c +++ b/check_sizeof.c @@ -22,7 +22,7 @@ static void check_pointer(struct expression *expr, char *ptr_name) get_value(expr, &sval); expr = strip_expr(expr->cast_expression); - name = expr_to_str_sym_complex(expr, NULL); + name = expr_to_str_complex(expr); if (!name) return; @@ -40,7 +40,7 @@ static void match_call_assignment(struct expression *expr) if (!is_pointer(expr->left)) return; - ptr_name = expr_to_str_sym_complex(expr->left, NULL); + ptr_name = expr_to_str_complex(expr->left); if (!ptr_name) return; diff --git a/check_type.c b/check_type.c index 149331ad..1a37c433 100644 --- a/check_type.c +++ b/check_type.c @@ -33,7 +33,7 @@ static void match_free(const char *fn, struct expression *expr, void *data) if (!type || !type->ident) return; - name = expr_to_str_sym_complex(arg_expr, NULL); + name = expr_to_str_complex(arg_expr); if (!strcmp("sk_buff", type->ident->name)) { sm_msg("error: use kfree_skb() here instead of kfree(%s)", name); diff --git a/check_wait_for_common.c b/check_wait_for_common.c index 4e3f5e29..99241e5e 100644 --- a/check_wait_for_common.c +++ b/check_wait_for_common.c @@ -17,7 +17,7 @@ static void match_wait_for_common(const char *fn, struct expression *expr, void if (!expr_unsigned(expr->left)) return; - name = expr_to_str_sym_complex(expr->left, NULL); + name = expr_to_str_complex(expr->left); sm_msg("error: '%s()' returns negative and '%s' is unsigned", fn, name); free_string(name); } diff --git a/smatch.h b/smatch.h index 08af3419..0737340f 100644 --- a/smatch.h +++ b/smatch.h @@ -224,6 +224,7 @@ struct expression *get_argument_from_call_expr(struct expression_list *args, int num); char *expr_to_str(struct expression *expr); +char *expr_to_str_complex(struct expression *expr); char *expr_to_str_sym_complex(struct expression *expr, struct symbol **sym_ptr); char *expr_to_str_sym(struct expression *expr, diff --git a/smatch_conditions.c b/smatch_conditions.c index c3af9b58..67544fe9 100644 --- a/smatch_conditions.c +++ b/smatch_conditions.c @@ -338,7 +338,7 @@ static void hackup_unsigned_compares(struct expression *expr) static void split_conditions(struct expression *expr) { if (option_debug) { - char *cond = expr_to_str_sym_complex(expr, NULL); + char *cond = expr_to_str_complex(expr); sm_debug("%d in split_conditions (%s)\n", get_lineno(), cond); free_string(cond); diff --git a/smatch_helper.c b/smatch_helper.c index 2be5f551..ac2462d1 100644 --- a/smatch_helper.c +++ b/smatch_helper.c @@ -261,9 +261,14 @@ char *expr_to_str_sym_complex(struct expression *expr, struct symbol **sym_ptr) return NULL; } +char *expr_to_str_complex(struct expression *expr) +{ + return expr_to_str_sym_complex(expr, NULL); +} + /* * get_variable_from_expr_simple() only returns simple variables. - * If it's a complicated variable like a->foo instead of just 'a' + * If it's a complicated variable like a->foo[x] instead of just 'a->foo' * then it returns NULL. */