Skip to content

Commit 9b97cfa

Browse files
ethourisMikolaj Malecki
andauthored
[core] Fixed reentrancy problem of srt_strerror (#3214)
* [core] Fixed reentrancy problem of srt_strerror * [docs] Updated documentation for srt_strerror --------- Co-authored-by: Mikolaj Malecki <[email protected]>
1 parent 5138f37 commit 9b97cfa

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

docs/API/API-functions.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,13 +2841,13 @@ associated with the last error. The system error is:
28412841
const char* srt_strerror(int code, int errnoval);
28422842
```
28432843

2844-
Returns a string message that represents a given SRT error code and possibly the
2845-
`errno` value, if not 0.
2844+
Returns a string message that represents a given SRT error code.
28462845

2847-
**NOTE:** *This function isn't thread safe. It uses a static variable to hold the
2848-
error description. There's no problem with using it in a multithreaded environment,
2849-
as long as only one thread in the whole application calls this function at the
2850-
moment*
2846+
**NOTE:** *The `errnoval` parameter is ignored. This function's old version
2847+
was intended to get both the SRT error description and system error description,
2848+
but this requires resolution of the reentrancy problem and dynamic strings.
2849+
For getting the error description for a system error, you need to use the
2850+
`strerror` function or some of its reentrant version.*
28512851

28522852

28532853
[:arrow_up: &nbsp; Back to List of Functions & Structures](#srt-api-functions)

srtcore/srt_c_api.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ written by
2626
using namespace std;
2727
using namespace srt;
2828

29+
namespace srt
30+
{
31+
// This is provided in strerror_defs.cpp, which doesn't have
32+
// its header file.
33+
// XXX Consider adding some static function to CUDTException.
34+
const char* strerror_get_message(size_t major, size_t minor);
35+
}
36+
2937

3038
extern "C" {
3139

@@ -248,11 +256,9 @@ int srt_getlasterror(int* loc_errno)
248256
return CUDT::getlasterror().getErrorCode();
249257
}
250258

251-
const char* srt_strerror(int code, int err)
259+
const char* srt_strerror(int code, int /*err ignored*/)
252260
{
253-
static srt::CUDTException e;
254-
e = srt::CUDTException(CodeMajor(code/1000), CodeMinor(code%1000), err);
255-
return(e.getErrorMessage());
261+
return strerror_get_message(CodeMajor(code/1000), CodeMinor(code%1000));
256262
}
257263

258264

0 commit comments

Comments
 (0)