From: Yu Watanabe Date: Sat, 16 Apr 2022 21:54:50 +0000 (+0900) Subject: macro: check over flow in reference counter X-Git-Tag: v251-rc2~94^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c8431e9e35a904673cf659fd238cb63b3c3896fc;p=thirdparty%2Fsystemd.git macro: check over flow in reference counter --- diff --git a/src/basic/macro.h b/src/basic/macro.h index 68d8b062e87..6e3966ff486 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -396,8 +396,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; \ }