[llvm-bugs] [Bug 51177] New: Improper Error Handling in chrono:now()

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jul 23 02:46:31 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51177

            Bug ID: 51177
           Summary: Improper Error Handling in chrono:now()
           Product: libc++
           Version: 12.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: slotosch at validas.de
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

Chrono:now calls the following routine:

static system_clock::time_point __libcpp_system_clock_now() {
  struct timespec tp;
  if (0 != clock_gettime(CLOCK_REALTIME, &tp))
    __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
  return system_clock::time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec
/ 1000));
}

Problem is the the returned error code from clock_gettime is not stored in a
variable and not returned. But Errno is returned. Errno may be set or not from
clock_gettime. 

Proposal: replace 2 lines
  if (0 != clock_gettime(CLOCK_REALTIME, &tp))
    __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");

by
  int ec = clock_gettime(CLOCK_REALTIME, &tp);
  if (0 != ec)
    __throw_system_error(ec, "clock_gettime(CLOCK_REALTIME) failed");

affected versions: all

In safety relevant applications error handling is critical

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210723/9d2bd0b8/attachment.html>


More information about the llvm-bugs mailing list