You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.4 KiB
31 lines
1.4 KiB
From eb7eca006b5f290481720dc4d7fcdba88d8613cb Mon Sep 17 00:00:00 2001 |
|
From: Yu Watanabe <watanabe.yu+github@gmail.com> |
|
Date: Sun, 17 Apr 2022 06:54:50 +0900 |
|
Subject: [PATCH] macro: check over flow in reference counter |
|
|
|
(cherry picked from commit c8431e9e35a904673cf659fd238cb63b3c3896fc) |
|
|
|
Related: #2087652 |
|
--- |
|
src/basic/macro.h | 8 ++++++-- |
|
1 file changed, 6 insertions(+), 2 deletions(-) |
|
|
|
diff --git a/src/basic/macro.h b/src/basic/macro.h |
|
index aa04039e80..e7dc83ddc5 100644 |
|
--- a/src/basic/macro.h |
|
+++ b/src/basic/macro.h |
|
@@ -387,8 +387,12 @@ static inline int __coverity_check_and_return__(int condition) { |
|
if (!p) \ |
|
return NULL; \ |
|
\ |
|
- assert(p->n_ref > 0); \ |
|
- p->n_ref++; \ |
|
+ /* For type check. */ \ |
|
+ unsigned *q = &p->n_ref; \ |
|
+ assert(*q > 0); \ |
|
+ assert(*q < UINT_MAX); \ |
|
+ \ |
|
+ (*q)++; \ |
|
return p; \ |
|
} |
|
|
|
|