Bug 419995 - str_fmt_exception does not format the error properly
Summary: str_fmt_exception does not format the error properly
Status: RESOLVED FIXED
Alias: None
Product: TCF
Classification: Tools
Component: Agent (show other bugs)
Version: 1.1   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 1.2   Edit
Assignee: Project Inbox CLA
QA Contact: Eugene Tarassov CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-21 12:05 EDT by Laurent Cruaud CLA
Modified: 2014-02-25 05:50 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Laurent Cruaud CLA 2013-10-21 12:05:56 EDT
The str_fmt_exception() function is based on the vsnprintf().

With Visual, the vsnprintf() could return a negative value -1 when the output was truncated.
According to the Unix man page, it could be the case too, depending on the glibc version.

    while (1) {
        buf = (char *)loc_realloc(buf, len);
        va_start(vaList, fmt);
        n = vsnprintf(buf, len, fmt, vaList);
        va_end(vaList);
>>>     if (n < (int)len) break; <<<
        len = n + 1;
    }

As suggest into the Unix man page of the vsnprintf() example, The condition to exit the loop would be :

    if (n > -1 && n < size) break;
Comment 1 Eugene Tarassov CLA 2013-10-22 08:28:38 EDT
I've changed the code to be similar to set_fmt_errno() function code.

"if (n > -1 && n < size) break;" would not work - it would cause infinite loop.

Fixed.