Skip to content

Commit afa3291

Browse files
committed
Fix bugs and enhance code. 4.0.142
1 parent 66a696e commit afa3291

File tree

6 files changed

+23
-18
lines changed

6 files changed

+23
-18
lines changed

.github/workflows/codeql-analysis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ on:
1818
# The branches below must be a subset of the branches above
1919
branches: [ 4.0release, develop ]
2020
schedule:
21-
- cron: '43 11 * * 0'
21+
# '20 19 * * 6' means 'At 19:20, only on Saturday' @see https://crontab.cronhub.io/
22+
- cron: '20 19 * * 6'
2223

2324
jobs:
2425
analyze:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ cmake-build-debug
4040
/trunk/ide/srs_clion/Makefile
4141
/trunk/ide/srs_clion/cmake_install.cmake
4242
/trunk/ide/srs_clion/srs
43+
/trunk/ide/srs_clion/Testing/

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The changelog for SRS.
66

77
## SRS 4.0 Changelog
88

9+
* v4.0, 2021-07-17, Fix bugs and enhance code. 4.0.142
910
* v4.0, 2021-07-16, Support [CLion and cmake](https://github.com/ossrs/srs/wiki/v4_CN_IDE#clion) to build and debug SRS. 4.0.141
1011
* v4.0, 2021-07-08, For [#2403](https://github.com/ossrs/srs/issues/2403), fix padding packets for RTMP2RTC. 4.0.140
1112
* v4.0, 2021-07-04, For [#2424](https://github.com/ossrs/srs/issues/2424), use srandom/random to generate. 4.0.139

trunk/src/app/srs_app_utility.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,14 @@ string srs_path_build_timestamp(string template_path)
8080
}
8181

8282
// to calendar time
83-
struct tm* tm;
83+
struct tm now;
84+
// Each of these functions returns NULL in case an error was detected. @see https://linux.die.net/man/3/localtime_r
8485
if (_srs_config->get_utc_time()) {
85-
if ((tm = gmtime(&tv.tv_sec)) == NULL) {
86+
if (gmtime_r(&tv.tv_sec, &now) == NULL) {
8687
return path;
8788
}
8889
} else {
89-
if ((tm = localtime(&tv.tv_sec)) == NULL) {
90+
if (localtime_r(&tv.tv_sec, &now) == NULL) {
9091
return path;
9192
}
9293
}
@@ -96,32 +97,32 @@ string srs_path_build_timestamp(string template_path)
9697

9798
// [2006], replace with current year.
9899
if (true) {
99-
snprintf(buf, sizeof(buf), "%04d", 1900 + tm->tm_year);
100+
snprintf(buf, sizeof(buf), "%04d", 1900 + now.tm_year);
100101
path = srs_string_replace(path, "[2006]", buf);
101102
}
102103
// [01], replace this const to current month.
103104
if (true) {
104-
snprintf(buf, sizeof(buf), "%02d", 1 + tm->tm_mon);
105+
snprintf(buf, sizeof(buf), "%02d", 1 + now.tm_mon);
105106
path = srs_string_replace(path, "[01]", buf);
106107
}
107108
// [02], replace this const to current date.
108109
if (true) {
109-
snprintf(buf, sizeof(buf), "%02d", tm->tm_mday);
110+
snprintf(buf, sizeof(buf), "%02d", now.tm_mday);
110111
path = srs_string_replace(path, "[02]", buf);
111112
}
112113
// [15], replace this const to current hour.
113114
if (true) {
114-
snprintf(buf, sizeof(buf), "%02d", tm->tm_hour);
115+
snprintf(buf, sizeof(buf), "%02d", now.tm_hour);
115116
path = srs_string_replace(path, "[15]", buf);
116117
}
117118
// [04], repleace this const to current minute.
118119
if (true) {
119-
snprintf(buf, sizeof(buf), "%02d", tm->tm_min);
120+
snprintf(buf, sizeof(buf), "%02d", now.tm_min);
120121
path = srs_string_replace(path, "[04]", buf);
121122
}
122123
// [05], repleace this const to current second.
123124
if (true) {
124-
snprintf(buf, sizeof(buf), "%02d", tm->tm_sec);
125+
snprintf(buf, sizeof(buf), "%02d", now.tm_sec);
125126
path = srs_string_replace(path, "[05]", buf);
126127
}
127128
// [999], repleace this const to current millisecond.

trunk/src/core/srs_core_version4.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
#define VERSION_MAJOR 4
1111
#define VERSION_MINOR 0
12-
#define VERSION_REVISION 141
12+
#define VERSION_REVISION 142
1313

1414
#endif

trunk/src/protocol/srs_service_log.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,14 @@ bool srs_log_header(char* buffer, int size, bool utc, bool dangerous, const char
217217
}
218218

219219
// to calendar time
220-
struct tm* tm;
220+
struct tm now;
221+
// Each of these functions returns NULL in case an error was detected. @see https://linux.die.net/man/3/localtime_r
221222
if (utc) {
222-
if ((tm = gmtime(&tv.tv_sec)) == NULL) {
223+
if (gmtime_r(&tv.tv_sec, &now) == NULL) {
223224
return false;
224225
}
225226
} else {
226-
if ((tm = localtime(&tv.tv_sec)) == NULL) {
227+
if (localtime_r(&tv.tv_sec, &now) == NULL) {
227228
return false;
228229
}
229230
}
@@ -233,24 +234,24 @@ bool srs_log_header(char* buffer, int size, bool utc, bool dangerous, const char
233234
if (tag) {
234235
written = snprintf(buffer, size,
235236
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%s][%d][%s] ",
236-
1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000),
237+
1900 + now.tm_year, 1 + now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec, (int)(tv.tv_usec / 1000),
237238
level, getpid(), cid.c_str(), errno, tag);
238239
} else {
239240
written = snprintf(buffer, size,
240241
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%s][%d] ",
241-
1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000),
242+
1900 + now.tm_year, 1 + now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec, (int)(tv.tv_usec / 1000),
242243
level, getpid(), cid.c_str(), errno);
243244
}
244245
} else {
245246
if (tag) {
246247
written = snprintf(buffer, size,
247248
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%s][%s] ",
248-
1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000),
249+
1900 + now.tm_year, 1 + now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec, (int)(tv.tv_usec / 1000),
249250
level, getpid(), cid.c_str(), tag);
250251
} else {
251252
written = snprintf(buffer, size,
252253
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%s] ",
253-
1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000),
254+
1900 + now.tm_year, 1 + now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec, (int)(tv.tv_usec / 1000),
254255
level, getpid(), cid.c_str());
255256
}
256257
}

0 commit comments

Comments
 (0)