Author: sebor
Date: Mon Feb 5 11:15:50 2007
New Revision: 503831
URL: http://svn.apache.org/viewvc?view=rev&rev=503831
Log:
2007-02-05 Martin Sebor <[EMAIL PROTECTED]>
* src/printf.cpp (_rw_pvasnprintf): Gracefuly handled a null format
string.
* self/0.printf.cpp (test_malformed_directives): Exercised the above.
Modified:
incubator/stdcxx/trunk/tests/self/0.printf.cpp
incubator/stdcxx/trunk/tests/src/printf.cpp
Modified: incubator/stdcxx/trunk/tests/self/0.printf.cpp
URL:
http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/self/0.printf.cpp?view=diff&rev=503831&r1=503830&r2=503831
==============================================================================
--- incubator/stdcxx/trunk/tests/self/0.printf.cpp (original)
+++ incubator/stdcxx/trunk/tests/self/0.printf.cpp Mon Feb 5 11:15:50 2007
@@ -2837,10 +2837,11 @@
//////////////////////////////////////////////////////////////////
printf ("%s\n", "malformed directives");
- TEST ("%{", 0, 0, 0, "%{");
- TEST ("%{%", 0, 0, 0, "%{%");
- TEST ("%{%{", 0, 0, 0, "%{%{");
- TEST ("%{}", 0, 0, 0, "%{}");
+ TEST ((char*)0, 0, 0, 0, "(null)");
+ TEST ("%{", 0, 0, 0, "%{");
+ TEST ("%{%", 0, 0, 0, "%{%");
+ TEST ("%{%{", 0, 0, 0, "%{%{");
+ TEST ("%{}", 0, 0, 0, "%{}");
}
/***********************************************************************/
Modified: incubator/stdcxx/trunk/tests/src/printf.cpp
URL:
http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/printf.cpp?view=diff&rev=503831&r1=503830&r2=503831
==============================================================================
--- incubator/stdcxx/trunk/tests/src/printf.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/printf.cpp Mon Feb 5 11:15:50 2007
@@ -685,6 +685,9 @@
size_t spec_bufsize = sizeof specbuf / sizeof *specbuf;
size_t paramno = 0;
+ if (0 == fmt || 0 > _RW::__rw_memattr (fmt, _RWSTD_SIZE_MAX, -1))
+ return _rw_fmtbadaddr (pspec [0], buf, fmt);
+
for (const char *fc = fmt; *fc; ) {
const char* const pcnt = strchr (fc, '%');
@@ -942,7 +945,9 @@
RW_ASSERT (0 != buf.pbuf);
RW_ASSERT (0 != buf.pbufsize);
- if ('%' == fmt [0] && '{' == fmt [1] && '+' == fmt [2] && '}' == fmt [3]) {
+ if ( fmt
+ && '%' == fmt [0] && '{' == fmt [1]
+ && '+' == fmt [2] && '}' == fmt [3]) {
// when the format string begins with the special %{+}
// directive append to the buffer instead of writing
// over it
@@ -952,7 +957,7 @@
else if (*buf.pbuf)
**buf.pbuf = '\0';
- if ('%' == fmt [0] && '{' == fmt [1]) {
+ if (fmt && '%' == fmt [0] && '{' == fmt [1]) {
if ('*' == fmt [2] && '}' == fmt [3]) {
const int n = va_arg (*pva, int);
if (n < 0) {