Print this page
new smatch

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch_array_values.c
          +++ new/usr/src/tools/smatch/src/smatch_array_values.c
↓ open down ↓ 180 lines elided ↑ open up ↑
 181  181          } else {
 182  182                  get_absolute_rl(expr->right, &rl);
 183  183                  rl = cast_rl(type, rl);
 184  184                  orig_rl = get_saved_rl(type, name);
 185  185                  rl = rl_union(orig_rl, rl);
 186  186          }
 187  187  
 188  188          update_cache(name, is_file_local(array), rl);
 189  189  }
 190  190  
      191 +static void mark_strings_unknown(const char *fn, struct expression *expr, void *_arg)
      192 +{
      193 +        struct expression *dest;
      194 +        struct symbol *type;
      195 +        int arg = PTR_INT(_arg);
      196 +        char *name;
      197 +
      198 +        dest = get_argument_from_call_expr(expr->args, arg);
      199 +        if (!dest)
      200 +                return;
      201 +        name = get_array_name(dest);
      202 +        if (!name)
      203 +                return;
      204 +        type = get_type(dest);
      205 +        if (type_is_ptr(type))
      206 +                type = get_real_base_type(type);
      207 +        update_cache(name, is_file_local(dest), alloc_whole_rl(type));
      208 +}
      209 +
 191  210  void register_array_values(int id)
 192  211  {
 193  212          my_id = id;
 194  213  
 195  214          add_hook(&match_assign, ASSIGNMENT_HOOK);
 196  215          add_hook(&match_assign, GLOBAL_ASSIGNMENT_HOOK);
      216 +
      217 +        add_function_hook("sprintf", &mark_strings_unknown, INT_PTR(0));
      218 +        add_function_hook("snprintf", &mark_strings_unknown, INT_PTR(0));
      219 +
      220 +        add_function_hook("strcpy", &mark_strings_unknown, INT_PTR(0));
      221 +        add_function_hook("strncpy", &mark_strings_unknown, INT_PTR(0));
      222 +        add_function_hook("strlcpy", &mark_strings_unknown, INT_PTR(0));
      223 +        add_function_hook("strscpy", &mark_strings_unknown, INT_PTR(0));
 197  224  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX