[lld] r238669 - Fix unsafe memory access.

Simon Atanasyan simon at atanasyan.com
Sat May 30 22:10:41 PDT 2015


Hi,

On Sun, May 31, 2015 at 6:57 AM, Rui Ueyama <ruiu at google.com> wrote:
> @@ -172,7 +174,7 @@ ErrorOr<StringRef> SymbolTable::findDefa
>        {"WinMain", "WinMainCRTStartup"},
>        {"wWinMain", "wWinMainCRTStartup"},
>    };
> -  for (size_t I = 0; I < sizeof(Entries); ++I) {
> +  for (size_t I = 0; I < array_lengthof(Entries); ++I) {
>      if (!find(Entries[I][0]))
>        continue;
>      if (auto EC = addSymbol(new Undefined(Entries[I][1])))

Maybe the range loop based approach is even safer and shorter:
[[
for (const auto &Entry : Entries) {
  if (!find(Entry[0]))
    continue;
  if (auto EC = addSymbol(new Undefined(Entry[1])))
    return EC;
  return StringRef(Entry[1]);
}
]]

-- 
Simon Atanasyan



More information about the llvm-commits mailing list