math: handle logical expressions
[smatch.git] / check_pointer_math.c
blob8097c2fd0c7ef721d5bb49499992d7f6df0a3de0
1 /*
2 * smatch/check_pointer_math.c
4 * Copyright (C) 2012 Oracle.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
12 static int my_id;
14 static void match_binop(struct expression *expr)
16 struct symbol *type;
18 if (expr->op != '+')
19 return;
20 if (expr->right->type != EXPR_SIZEOF)
21 return;
22 type = get_pointer_type(expr->left);
23 if (!type)
24 return;
25 if (type->bit_size <= 8) /* ignore void, bool and char pointers*/
26 return;
27 sm_msg("warn: potential pointer math issue (%d bits)", type->bit_size);
31 void check_pointer_math(int id)
33 my_id = id;
34 add_hook(&match_binop, BINOP_HOOK);