Print this page
new smatch
@@ -37,10 +37,23 @@
tmp = malloc(strlen(str) + 1);
strcpy(tmp, str);
return tmp;
}
+char *alloc_string_newline(const char *str)
+{
+ char *tmp;
+ int len;
+
+ if (!str)
+ return NULL;
+ len = strlen(str);
+ tmp = malloc(len + 2);
+ snprintf(tmp, len + 2, "%s\n", str);
+ return tmp;
+}
+
void free_string(char *str)
{
free(str);
}
@@ -274,14 +287,17 @@
if (array_expr)
append(buf, "]", len);
return;
}
case EXPR_VALUE: {
+ sval_t sval = {};
char tmp[25];
*complicated = 1;
- snprintf(tmp, 25, "%lld", expr->value);
+ if (!get_value(expr, &sval))
+ return;
+ snprintf(tmp, 25, "%s", sval_to_numstr(sval));
append(buf, tmp, len);
return;
}
case EXPR_STRING:
append(buf, "\"", len);
@@ -587,11 +603,11 @@
if (!strcmp(expr->symbol_name->name, name))
return 1;
return 0;
}
-int is_zero(struct expression *expr)
+int expr_is_zero(struct expression *expr)
{
sval_t sval;
if (get_value(expr, &sval) && sval.value == 0)
return 1;
@@ -816,28 +832,25 @@
if (cur_func->type == SYM_PTR && sval.value == 0)
return 1;
return 0;
}
-int getting_address(void)
+int getting_address(struct expression *expr)
{
- struct expression *tmp;
- int i = 0;
- int dot_ops = 0;
+ int deref_count = 0;
- FOR_EACH_PTR_REVERSE(big_expression_stack, tmp) {
- if (!i++)
- continue;
- if (tmp->type == EXPR_PREOP && tmp->op == '(')
- continue;
- if (tmp->op == '.' && !dot_ops++)
- continue;
- if (tmp->op == '&')
- return 1;
- return 0;
- } END_FOR_EACH_PTR_REVERSE(tmp);
- return 0;
+ while ((expr = expr_get_parent_expr(expr))) {
+ if (expr->type == EXPR_PREOP && expr->op == '*') {
+ /* &foo->bar->baz dereferences "foo->bar" */
+ if (deref_count == 0)
+ deref_count++;
+ return false;
+ }
+ if (expr->type == EXPR_PREOP && expr->op == '&')
+ return true;
+ }
+ return false;
}
int get_struct_and_member(struct expression *expr, const char **type, const char **member)
{
struct symbol *sym;