[libc-commits] [libc] bf0992c - [libc] Fix line reporting in assertion failure

Jon Chesterfield via libc-commits libc-commits at lists.llvm.org
Thu Jul 20 15:44:40 PDT 2023


Author: Jon Chesterfield
Date: 2023-07-20T23:44:33+01:00
New Revision: bf0992c7184407da420ced5bbfa9c718d0cf6d5b

URL: https://github.com/llvm/llvm-project/commit/bf0992c7184407da420ced5bbfa9c718d0cf6d5b
DIFF: https://github.com/llvm/llvm-project/commit/bf0992c7184407da420ced5bbfa9c718d0cf6d5b.diff

LOG: [libc] Fix line reporting in assertion failure

Was passing zeros to the string print function.

Reviewed By: jhuber6

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

Added: 
    

Modified: 
    libc/src/__support/libc_assert.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/libc_assert.h b/libc/src/__support/libc_assert.h
index 64b03e57d7255a..549c5228ff225d 100644
--- a/libc/src/__support/libc_assert.h
+++ b/libc/src/__support/libc_assert.h
@@ -31,10 +31,11 @@ LIBC_INLINE void report_assertion_failure(const char *assertion,
                                           const char *filename, unsigned line,
                                           const char *funcname) {
   char line_str[IntegerToString::dec_bufsize<unsigned>()];
-  IntegerToString::dec(line, line_str);
+  // dec returns an optional, will always be valid for this size buffer
+  auto line_number = IntegerToString::dec(line, line_str);
   __llvm_libc::write_to_stderr(filename);
   __llvm_libc::write_to_stderr(":");
-  __llvm_libc::write_to_stderr(line_str);
+  __llvm_libc::write_to_stderr(*line_number);
   __llvm_libc::write_to_stderr(": Assertion failed: '");
   __llvm_libc::write_to_stderr(assertion);
   __llvm_libc::write_to_stderr("' in function: '");


        


More information about the libc-commits mailing list