File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change 14
14
std::string SysErrorString (int err)
15
15
{
16
16
char buf[256 ];
17
- buf[0 ] = 0 ;
18
17
/* Too bad there are three incompatible implementations of the
19
18
* thread-safe strerror. */
20
- const char *s;
19
+ const char *s = nullptr ;
21
20
#ifdef WIN32
22
- s = buf;
23
- if (strerror_s (buf, sizeof (buf), err) != 0 )
24
- buf[0 ] = 0 ;
21
+ if (strerror_s (buf, sizeof (buf), err) == 0 ) s = buf;
25
22
#else
26
23
#ifdef STRERROR_R_CHAR_P /* GNU variant can return a pointer outside the passed buffer */
27
24
s = strerror_r (err, buf, sizeof (buf));
28
25
#else /* POSIX variant always returns message in buffer */
29
- s = buf;
30
- if (strerror_r (err, buf, sizeof (buf)))
31
- buf[0 ] = 0 ;
26
+ if (strerror_r (err, buf, sizeof (buf)) == 0 ) s = buf;
32
27
#endif
33
28
#endif
34
- return strprintf (" %s (%d)" , s, err);
29
+ if (s != nullptr ) {
30
+ return strprintf (" %s (%d)" , s, err);
31
+ } else {
32
+ return strprintf (" Unknown error (%d)" , err);
33
+ }
35
34
}
You can’t perform that action at this time.
0 commit comments