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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to