11f5207bJohn Levon/*
21f5207bJohn Levon * Copyright (C) 2013 Oracle.
31f5207bJohn Levon *
41f5207bJohn Levon * This program is free software; you can redistribute it and/or
51f5207bJohn Levon * modify it under the terms of the GNU General Public License
61f5207bJohn Levon * as published by the Free Software Foundation; either version 2
71f5207bJohn Levon * of the License, or (at your option) any later version.
81f5207bJohn Levon *
91f5207bJohn Levon * This program is distributed in the hope that it will be useful,
101f5207bJohn Levon * but WITHOUT ANY WARRANTY; without even the implied warranty of
111f5207bJohn Levon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
121f5207bJohn Levon * GNU General Public License for more details.
131f5207bJohn Levon *
141f5207bJohn Levon * You should have received a copy of the GNU General Public License
151f5207bJohn Levon * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
161f5207bJohn Levon */
171f5207bJohn Levon
181f5207bJohn Levon/*
191f5207bJohn Levon * struct foo { char buf[10]; };
201f5207bJohn Levon *
211f5207bJohn Levon * struct foo *p = something();
221f5207bJohn Levon * if (p->buf) { ...
231f5207bJohn Levon *
241f5207bJohn Levon */
251f5207bJohn Levon
261f5207bJohn Levon#include "smatch.h"
271f5207bJohn Levon
281f5207bJohn Levonstatic int my_id;
291f5207bJohn Levon
301f5207bJohn Levonstatic void match_condition(struct expression *expr)
311f5207bJohn Levon{
321f5207bJohn Levon	struct symbol *type;
331f5207bJohn Levon	char *str;
341f5207bJohn Levon
351f5207bJohn Levon	if (expr->type != EXPR_DEREF)
361f5207bJohn Levon		return;
371f5207bJohn Levon	type = get_type(expr);
381f5207bJohn Levon	if (!type || type->type != SYM_ARRAY)
391f5207bJohn Levon		return;
401f5207bJohn Levon	if (get_macro_name(expr->pos))
411f5207bJohn Levon		return;
421f5207bJohn Levon
431f5207bJohn Levon	str = expr_to_str(expr);
441f5207bJohn Levon	sm_warning("this array is probably non-NULL. '%s'", str);
451f5207bJohn Levon	free_string(str);
461f5207bJohn Levon}
471f5207bJohn Levon
481f5207bJohn Levonvoid check_array_condition(int id)
491f5207bJohn Levon{
501f5207bJohn Levon	my_id = id;
511f5207bJohn Levon	add_hook(&match_condition, CONDITION_HOOK);
521f5207bJohn Levon}
53