aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2019-03-18 15:11:30 (GMT)
committerDan Carpenter <dan.carpenter@oracle.com>2019-03-18 15:11:30 (GMT)
commit77a3041bdf15dbdb6eb64a6fa782821ebe99f961 (patch)
tree4c8fffe33e3c6d82ba797c8f18a636a9a2034e97
parent58500480b16863e33408e268bd6f8274658e37dc (diff)
mtag: tweak get_mtag_sval()
I've added some comments and changed it to return falure if the offset is too high. Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
-rw-r--r--smatch_mtag.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/smatch_mtag.c b/smatch_mtag.c
index fa45948..0d8bb21 100644
--- a/smatch_mtag.c
+++ b/smatch_mtag.c
@@ -379,6 +379,20 @@ int expr_to_mtag_offset(struct expression *expr, mtag_t *tag, int *offset)
return 0;
}
+/*
+ * This function takes an address and returns an sval. Let's take some
+ * example things you might pass to it:
+ * foo->bar:
+ * If we were only called from smatch_math, we wouldn't need to bother with
+ * this because it's already been looked up in smatch_extra.c but this is
+ * also called from other places so we have to check smatch_extra.c.
+ * &foo
+ * If "foo" is global return the mtag for "foo".
+ * &foo.bar
+ * If "foo" is global return the mtag for "foo" + the offset of ".bar".
+ * It also handles string literals.
+ *
+ */
int get_mtag_sval(struct expression *expr, sval_t *sval)
{
struct symbol *type;
@@ -422,10 +436,10 @@ int get_mtag_sval(struct expression *expr, sval_t *sval)
if (!expr_to_mtag_offset(expr, &tag, &offset))
return 0;
- if (offset > MTAG_OFFSET_MASK)
- offset = MTAG_OFFSET_MASK;
-
found:
+ if (offset >= MTAG_OFFSET_MASK)
+ return 0;
+
sval->type = type;
sval->uvalue = tag | offset;

Privacy Policy