[libcxx-commits] [PATCH] D94564: [libcxx] Check return value for asprintf()

Brad Smith via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jan 12 16:21:34 PST 2021


brad created this revision.
brad added reviewers: ldionne, libc++.
brad added a project: libc++.
Herald added a subscriber: krytarowski.
brad requested review of this revision.
Herald added 1 blocking reviewer(s): libc++.

Submitting upstream from OpenBSD tree:

local __libcpp_asprintf_l() -> libc asprintf() was inspecting the pointer (with indeterminate value) for failure, rather than the return value of -1.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94564

Files:
  libcxx/include/locale


Index: libcxx/include/locale
===================================================================
--- libcxx/include/locale
+++ libcxx/include/locale
@@ -1567,7 +1567,7 @@
             __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
         else
             __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
-        if (__nb == nullptr)
+        if (__nc == -1)
             __throw_bad_alloc();
         __nbh.reset(__nb);
     }
@@ -1618,7 +1618,7 @@
             __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
         else
             __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
-        if (__nb == nullptr)
+        if (__nc == -1)
             __throw_bad_alloc();
         __nbh.reset(__nb);
     }
@@ -3399,7 +3399,7 @@
     if (__n > __bs-1)
     {
         __n = static_cast<size_t>(__libcpp_asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units));
-        if (__bb == nullptr)
+        if (__n == -1)
             __throw_bad_alloc();
         __hn.reset(__bb);
         __hd.reset((char_type*)malloc(__n * sizeof(char_type)));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94564.316267.patch
Type: text/x-patch
Size: 1182 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210113/2eefa974/attachment.bin>


More information about the libcxx-commits mailing list