Mercurial > octave-antonio
comparison libinterp/corefcn/error.cc @ 20140:64a2d4c87ecb stable
Don't save "warning: " prefix in lastwarn() message.
* error.cc (vwarning): Save base_msg (without "warning: ") to Vlast_warning_message.
* error.cc (error_1): Use std::string operators rather than strsave to strip
"\n" from fmt string. Simpler syntax avoids having to delete [] memory created
with new.
* error.cc (warning_1): Strip trailing newline from fmt string as error_1 does.
* fail.m: Fix input validation which allowed nonsensical second input with 3
args. Don't post-process warning or error messages from lastwarn or lasterr.
Add BIST test for input validation.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 28 Apr 2015 14:03:03 -0700 |
parents | 0aed244dbdb3 |
children |
comparison
equal
deleted
inserted
replaced
20139:bcf0a288aa6c | 20140:64a2d4c87ecb |
---|---|
156 | 156 |
157 flush_octave_stdout (); | 157 flush_octave_stdout (); |
158 | 158 |
159 std::ostringstream output_buf; | 159 std::ostringstream output_buf; |
160 | 160 |
161 if (name) | |
162 output_buf << name << ": "; | |
163 | |
164 octave_vformat (output_buf, fmt, args); | 161 octave_vformat (output_buf, fmt, args); |
165 | |
166 output_buf << std::endl; | |
167 | 162 |
168 // FIXME: we really want to capture the message before it has all the | 163 // FIXME: we really want to capture the message before it has all the |
169 // formatting goop attached to it. We probably also want just the | 164 // formatting goop attached to it. We probably also want just the |
170 // message, not the traceback information. | 165 // message, not the traceback information. |
171 | 166 |
172 std::string msg_string = output_buf.str (); | 167 std::string base_msg = output_buf.str (); |
168 std::string msg_string; | |
169 | |
170 if (name) | |
171 msg_string = std::string (name) + ": "; | |
172 | |
173 msg_string += base_msg + "\n"; | |
173 | 174 |
174 Vlast_warning_id = id; | 175 Vlast_warning_id = id; |
175 Vlast_warning_message = msg_string; | 176 Vlast_warning_message = base_msg; |
176 | 177 |
177 if (! Vquiet_warning) | 178 if (! Vquiet_warning) |
178 { | 179 { |
179 octave_diary << msg_string; | 180 octave_diary << msg_string; |
180 | 181 |
335 error_1 (std::ostream& os, const char *name, const char *id, | 336 error_1 (std::ostream& os, const char *name, const char *id, |
336 const char *fmt, va_list args, bool with_cfn = false) | 337 const char *fmt, va_list args, bool with_cfn = false) |
337 { | 338 { |
338 if (error_state != -2) | 339 if (error_state != -2) |
339 { | 340 { |
340 if (fmt) | 341 if (fmt && *fmt) |
341 { | 342 { |
342 if (*fmt) | 343 size_t len = strlen (fmt); |
344 | |
345 if (len > 0) | |
343 { | 346 { |
344 size_t len = strlen (fmt); | 347 if (fmt[len - 1] == '\n') |
345 | 348 { |
346 if (len > 0) | 349 if (len > 1) |
347 { | |
348 if (fmt[len - 1] == '\n') | |
349 { | 350 { |
350 if (len > 1) | 351 // Strip newline before issuing error |
351 { | 352 std::string tmp_fmt (fmt, len - 1); |
352 char *tmp_fmt = strsave (fmt); | 353 verror (true, os, name, id, tmp_fmt.c_str (), |
353 tmp_fmt[len - 1] = '\0'; | 354 args, with_cfn); |
354 verror (true, os, name, id, tmp_fmt, args, with_cfn); | |
355 delete [] tmp_fmt; | |
356 } | |
357 | |
358 error_state = -2; | |
359 } | 355 } |
360 else | 356 |
361 { | 357 error_state = -2; |
362 verror (true, os, name, id, fmt, args, with_cfn); | 358 } |
363 | 359 else |
364 if (! error_state) | 360 { |
365 error_state = 1; | 361 verror (true, os, name, id, fmt, args, with_cfn); |
366 } | 362 |
363 if (! error_state) | |
364 error_state = 1; | |
367 } | 365 } |
368 } | 366 } |
369 } | 367 } |
370 else | 368 else |
371 panic ("error_1: invalid format"); | 369 panic ("error_1: invalid format"); |
632 | 630 |
633 error_2 (id, fmt, args); | 631 error_2 (id, fmt, args); |
634 } | 632 } |
635 else if (warn_opt == 1) | 633 else if (warn_opt == 1) |
636 { | 634 { |
637 vwarning ("warning", id, fmt, args); | |
638 | |
639 bool in_user_code = octave_call_stack::caller_user_code () != 0; | |
640 | |
641 bool fmt_suppresses_backtrace = false; | 635 bool fmt_suppresses_backtrace = false; |
642 size_t fmt_len = fmt ? strlen (fmt) : 0; | 636 size_t fmt_len = fmt ? strlen (fmt) : 0; |
643 fmt_suppresses_backtrace = (fmt_len > 0 && fmt[fmt_len-1] == '\n'); | 637 fmt_suppresses_backtrace = (fmt_len > 0 && fmt[fmt_len-1] == '\n'); |
638 | |
639 if (fmt_suppresses_backtrace && fmt_len > 1) | |
640 { | |
641 // Strip newline before issuing warning | |
642 std::string tmp_fmt (fmt, fmt_len - 1); | |
643 vwarning ("warning", id, tmp_fmt.c_str (), args); | |
644 } | |
645 else | |
646 vwarning ("warning", id, fmt, args); | |
647 | |
648 bool in_user_code = octave_call_stack::caller_user_code () != 0; | |
649 | |
644 | 650 |
645 if (! fmt_suppresses_backtrace && in_user_code | 651 if (! fmt_suppresses_backtrace && in_user_code |
646 && Vbacktrace_on_warning && ! warning_state | 652 && Vbacktrace_on_warning && ! warning_state |
647 && ! discard_warning_messages) | 653 && ! discard_warning_messages) |
648 pr_where ("warning"); | 654 pr_where ("warning"); |