Ticket #3011: 0006-cppformat-Permit-NULL-arguments-for-s.patch

File 0006-cppformat-Permit-NULL-arguments-for-s.patch, 1.1 KB (added by Philip Taylor, 9 years ago)
  • source/third_party/cppformat/format.cpp

    From 099485989f8580e1288ca51e81bc7c9593f08f81 Mon Sep 17 00:00:00 2001
    From: Philip Taylor <philip@zaynar.co.uk>
    Date: Tue, 20 Jan 2015 23:16:11 +0000
    Subject: [PATCH 06/13] cppformat: Permit NULL arguments for %s.
    
    Throwing exception on NULL is a bit extreme, and unhelpful when it happens in rarely-tested error paths. Printing "(null)" is safer and provides compatibility with glibc sprintf.
    ---
     source/third_party/cppformat/format.cpp | 7 +++++--
     1 file changed, 5 insertions(+), 2 deletions(-)
    
    diff --git a/source/third_party/cppformat/format.cpp b/source/third_party/cppformat/format.cpp
    index 4aee869..580d6cd 100644
    a b void fmt::BasicWriter<Char>::write_str(  
    754754  const StrChar *s = str.value;
    755755  std::size_t size = str.size;
    756756  if (size == 0) {
    757     if (!s)
    758       throw FormatError("string pointer is null");
     757    if (!s) {
     758      Char err[] = { '(', 'n', 'u', 'l', 'l', ')', 0 };
     759      write_str(err, 6, spec);
     760      return;
     761    }
    759762    if (*s)
    760763      size = std::char_traits<StrChar>::length(s);
    761764  }