Skip to content

Commit 30f8902

Browse files
tsepezjoaosaffran
authored andcommitted
[-Wunsafe-buffer-usage] Fix assert when constexpr size passed to snprintf() (llvm#119786) (llvm#124022)
EvaluateAsConstExpr() can return an lvalue which is not compatible with a subsequent getInt() call. Instead, use EvaluateAsInt() which will use all techniques availble to get an int result compatible with the subsequent getInt() call.
1 parent bab4e15 commit 30f8902

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

clang/lib/Analysis/UnsafeBufferUsage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ AST_MATCHER(CallExpr, hasUnsafeSnprintfBuffer) {
930930
// The array element type must be compatible with `char` otherwise an
931931
// explicit cast will be needed, which will make this check unreachable.
932932
// Therefore, the array extent is same as its' bytewise size.
933-
if (Size->EvaluateAsConstantExpr(ER, Ctx)) {
933+
if (Size->EvaluateAsInt(ER, Ctx)) {
934934
APSInt EVal = ER.Val.getInt(); // Size must have integer type
935935

936936
return APSInt::compareValues(EVal, APSInt(CAT->getSize(), true)) != 0;

0 commit comments

Comments
 (0)