[all-commits] [llvm/llvm-project] 301551: [PDB] Fix unsigned integer overflow

Nico Weber via All-commits all-commits at lists.llvm.org
Fri Feb 26 08:27:17 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 301551ae8e8f54fd66867c9411fcc17b2f02be7d
      https://github.com/llvm/llvm-project/commit/301551ae8e8f54fd66867c9411fcc17b2f02be7d
  Author: Nico Weber <thakis at chromium.org>
  Date:   2021-02-26 (Fri, 26 Feb 2021)

  Changed paths:
    M llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp

  Log Message:
  -----------
  [PDB] Fix unsigned integer overflow

When building with -fsanitize=unsigned-integer-overflow, this code
causes a diagnostic like:

    ../../llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp:159:15:
    runtime error: unsigned integer overflow:
    90 - 229 cannot be represented in type 'unsigned long'

unsigned integer overflow is well defined and it isn't an issue in
practice, but in obscure scenarios (S1.size() small, S2.size over 2GB
on 32-bit systems) it could even be a bug.

So use the usual idiom for implementing cmp functions instead of the
gernally considered buggy idiom :)
See e.g. https://www.gnu.org/software/libc/manual/html_node/Comparison-Functions.html
or https://stackoverflow.com/questions/10996418/efficient-integer-compare-function/10997428#10997428

Differential Revision: https://reviews.llvm.org/D97557




More information about the All-commits mailing list