Skip to content

Commit ccb1197

Browse files
committed
Further refine the warning message
1 parent 28a4371 commit ccb1197

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -446,23 +446,23 @@ ProgramStateRef CStringChecker::checkInit(CheckerContext &C,
446446
if (!ER)
447447
return State;
448448

449-
const auto *Orig = ER->getSuperRegion()->getAs<TypedValueRegion>();
450-
if (!Orig)
449+
const auto *SuperR = ER->getSuperRegion()->getAs<TypedValueRegion>();
450+
if (!SuperR)
451451
return State;
452452

453453
// FIXME: We ought to able to check objects as well. Maybe
454454
// UninitializedObjectChecker could help?
455-
if (!Orig->getValueType()->isArrayType())
455+
if (!SuperR->getValueType()->isArrayType())
456456
return State;
457457

458458
SValBuilder &SVB = C.getSValBuilder();
459459
ASTContext &Ctx = SVB.getContext();
460460

461-
const QualType ElemTy = Ctx.getBaseElementType(Orig->getValueType());
461+
const QualType ElemTy = Ctx.getBaseElementType(SuperR->getValueType());
462462
const NonLoc Zero = SVB.makeZeroArrayIndex();
463463

464464
Loc FirstElementVal =
465-
State->getLValue(ElemTy, Zero, loc::MemRegionVal(Orig)).castAs<Loc>();
465+
State->getLValue(ElemTy, Zero, loc::MemRegionVal(SuperR)).castAs<Loc>();
466466

467467
// Ensure that we wouldn't read uninitialized value.
468468
if (Filter.CheckCStringUninitializedRead &&
@@ -516,7 +516,7 @@ ProgramStateRef CStringChecker::checkInit(CheckerContext &C,
516516
return State;
517517

518518
SVal LastElementVal =
519-
State->getLValue(ElemTy, LastIdx, loc::MemRegionVal(Orig));
519+
State->getLValue(ElemTy, LastIdx, loc::MemRegionVal(SuperR));
520520
if (!isa<Loc>(LastElementVal))
521521
return State;
522522

@@ -531,9 +531,9 @@ ProgramStateRef CStringChecker::checkInit(CheckerContext &C,
531531
}
532532
llvm::SmallString<258> Buf;
533533
llvm::raw_svector_ostream OS(Buf);
534-
OS << "The last (";
535-
printIdxWithOrdinalSuffix(OS, IdxInt->getExtValue() + 1);
536-
OS << ") element to access in the ";
534+
OS << "The last accessed element (at index ";
535+
OS << IdxInt->getExtValue();
536+
OS << ") in the ";
537537
printIdxWithOrdinalSuffix(OS, Buffer.ArgumentIndex + 1);
538538
OS << " argument is undefined";
539539
emitUninitializedReadBug(C, State, Buffer.Expression, OS.str());

clang/test/Analysis/bstring_UninitRead.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void memcpy_array_fully_uninit(char *dst) {
2323
void memcpy_array_partially_uninit(char *dst) {
2424
char buf[10];
2525
buf[0] = 'i';
26-
memcpy(dst, buf, 10); // expected-warning{{The last (10th) element to access in the 2nd argument is undefined}}
26+
memcpy(dst, buf, 10); // expected-warning{{The last accessed element (at index 9) in the 2nd argument is undefined}}
2727
// expected-note@-1{{Other elements might also be undefined}}
2828
(void)buf;
2929
}
@@ -38,7 +38,7 @@ void memcpy_array_only_init_portion(char *dst) {
3838
void memcpy_array_partially_init_error(char *dst) {
3939
char buf[10];
4040
buf[0] = 'i';
41-
memcpy(dst, buf, 2); // expected-warning{{The last (2nd) element to access in the 2nd argument is undefined}}
41+
memcpy(dst, buf, 2); // expected-warning{{The last accessed element (at index 1) in the 2nd argument is undefined}}
4242
// expected-note@-1{{Other elements might also be undefined}}
4343
(void)buf;
4444
}

0 commit comments

Comments
 (0)