aboutsummaryrefslogtreecommitdiff
path: root/dtc.h
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2017-10-29 22:54:09 +0100
committerDavid Gibson <david@gibson.dropbear.id.au>2017-11-11 19:36:42 +1100
commit7975f6422260af4ac7ae2fcdff0ef2a6e391ab71 (patch)
treeb8ea452fcf138b59d6ccb897e582e44e2cd371a0 /dtc.h
parentfca296445eabf3cfe986e89dd8711c0be583036d (diff)
downloaddtc-7975f6422260af4ac7ae2fcdff0ef2a6e391ab71.zip
dtc-7975f6422260af4ac7ae2fcdff0ef2a6e391ab71.tar.gz
dtc-7975f6422260af4ac7ae2fcdff0ef2a6e391ab71.tar.bz2
Fix widespread incorrect use of strneq(), replace with new strprefixeq()
Every remaining usage of strneq() is, in fact, incorrect. They're trying to check that the first n characters of one string exactly match another string. But, they fall into the classic trap of strncmp() on which strneq() is based. If n is less than the length of the second string, they only check that the first string matches the start of the second, not the whole of it. To fix this, remove strneq() and replace it with a strprefixeq() function which does what we want here. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'dtc.h')
-rw-r--r--dtc.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/dtc.h b/dtc.h
index bb0b91b..758eb7c 100644
--- a/dtc.h
+++ b/dtc.h
@@ -67,8 +67,8 @@ typedef uint32_t cell_t;
#define streq(a, b) (strcmp((a), (b)) == 0)
-#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
#define strstarts(s, prefix) (strncmp((s), (prefix), strlen(prefix)) == 0)
+#define strprefixeq(a, n, b) (strlen(b) == (n) && (memcmp(a, b, n) == 0))
#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))