diff options
| author | Philipp Janda <siffiejoe@gmx.net> | 2017-09-23 10:58:47 +0200 |
|---|---|---|
| committer | Philipp Janda <siffiejoe@gmx.net> | 2017-09-23 10:58:47 +0200 |
| commit | b7829017581164c3e5dda24e3b187c0833b37dbf (patch) | |
| tree | af55d098d680ae079c477acc6af27849e1046e15 /c-api | |
| parent | 9895acb9809cab5812277464a3c94a821d3c3af8 (diff) | |
| download | lua-compat-5.3-b7829017581164c3e5dda24e3b187c0833b37dbf.tar.gz lua-compat-5.3-b7829017581164c3e5dda24e3b187c0833b37dbf.tar.bz2 lua-compat-5.3-b7829017581164c3e5dda24e3b187c0833b37dbf.zip | |
Do less stuff when sz is 0 in compat53_strerror().
Diffstat (limited to 'c-api')
| -rw-r--r-- | c-api/compat-5.3.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/c-api/compat-5.3.c b/c-api/compat-5.3.c index eb62009..9b304c1 100644 --- a/c-api/compat-5.3.c +++ b/c-api/compat-5.3.c | |||
| @@ -53,17 +53,17 @@ | |||
| 53 | static char* compat53_strerror (int en, char* buff, size_t sz) { | 53 | static char* compat53_strerror (int en, char* buff, size_t sz) { |
| 54 | #if COMPAT53_HAVE_STRERROR_R | 54 | #if COMPAT53_HAVE_STRERROR_R |
| 55 | /* use strerror_r here, because it's available on these specific platforms */ | 55 | /* use strerror_r here, because it's available on these specific platforms */ |
| 56 | if (sz > 0) | 56 | if (sz > 0) { |
| 57 | buff[0] = '\0'; | 57 | buff[0] = '\0'; |
| 58 | /* we don't care whether the GNU version or the XSI version is used: */ | 58 | /* we don't care whether the GNU version or the XSI version is used: */ |
| 59 | strerror_r(en, buff, sz); | 59 | strerror_r(en, buff, sz); |
| 60 | if (sz == 0 || buff[0] != '\0') | 60 | if (buff[0] == '\0') |
| 61 | return buff; /* strerror_r wrote into the buffer */ | 61 | /* buffer is unchanged, so we probably have called GNU strerror_r which |
| 62 | else | 62 | * returned a static constant string. Chances are that strerror will |
| 63 | /* buffer is unchanged, so we probably have called GNU strerror_r which | 63 | * return the same static constant string and therefore be thread-safe. */ |
| 64 | * returned a static constant string. Chances are that strerror will | 64 | return strerror(en); |
| 65 | * return the same static constant string and therefore be thread-safe. */ | 65 | } |
| 66 | return strerror(en); | 66 | return buff; /* sz is 0 *or* strerror_r wrote into the buffer */ |
| 67 | #elif COMPAT53_HAVE_STRERROR_S | 67 | #elif COMPAT53_HAVE_STRERROR_S |
| 68 | /* for MSVC and other C11 implementations, use strerror_s since it's | 68 | /* for MSVC and other C11 implementations, use strerror_s since it's |
| 69 | * provided by default by the libraries */ | 69 | * provided by default by the libraries */ |
