|
1 |
| -#ifndef _WIN32 |
| 1 | +#if defined(__GNUC__) || defined(__clang__) |
2 | 2 | // Disable all warnings from gcc/clang:
|
3 | 3 | #pragma GCC diagnostic push
|
4 | 4 | #pragma GCC diagnostic ignored "-Wpragmas"
|
|
11 | 11 | #pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
|
12 | 12 | #pragma GCC diagnostic ignored "-Wmissing-prototypes"
|
13 | 13 | #pragma GCC diagnostic ignored "-Wpadded"
|
14 |
| -#pragma GCC diagnostic ignored "-Wsign-compare" |
15 | 14 | #pragma GCC diagnostic ignored "-Wsign-conversion"
|
16 | 15 | #pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
17 | 16 | #pragma GCC diagnostic ignored "-Wunused-macros"
|
18 | 17 | #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
|
19 |
| -#else |
20 |
| -#ifdef _MSC_VER |
| 18 | +#elif defined(_MSC_VER) |
21 | 19 | #pragma warning(push)
|
22 |
| -#pragma warning(disable:4018) |
23 |
| -#endif // _MSC_VER |
| 20 | +#pragma warning(disable:4365) // conversion from 'X' to 'Y', signed/unsigned mismatch |
24 | 21 | #endif
|
25 | 22 |
|
26 | 23 | #include "loguru.hpp"
|
@@ -1244,27 +1241,48 @@ namespace loguru
|
1244 | 1241 | {
|
1245 | 1242 | if (out_buff_size == 0) { return; }
|
1246 | 1243 | out_buff[0] = '\0';
|
1247 |
| - long pos = 0; |
| 1244 | + size_t pos = 0; |
1248 | 1245 | if (g_preamble_date && pos < out_buff_size) {
|
1249 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "date "); |
| 1246 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "date "); |
| 1247 | + if (bytes > 0) { |
| 1248 | + pos += bytes; |
| 1249 | + } |
1250 | 1250 | }
|
1251 | 1251 | if (g_preamble_time && pos < out_buff_size) {
|
1252 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "time "); |
| 1252 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "time "); |
| 1253 | + if (bytes > 0) { |
| 1254 | + pos += bytes; |
| 1255 | + } |
1253 | 1256 | }
|
1254 | 1257 | if (g_preamble_uptime && pos < out_buff_size) {
|
1255 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "( uptime ) "); |
| 1258 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "( uptime ) "); |
| 1259 | + if (bytes > 0) { |
| 1260 | + pos += bytes; |
| 1261 | + } |
1256 | 1262 | }
|
1257 | 1263 | if (g_preamble_thread && pos < out_buff_size) {
|
1258 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "[%-*s]", LOGURU_THREADNAME_WIDTH, " thread name/id"); |
| 1264 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "[%-*s]", LOGURU_THREADNAME_WIDTH, " thread name/id"); |
| 1265 | + if (bytes > 0) { |
| 1266 | + pos += bytes; |
| 1267 | + } |
1259 | 1268 | }
|
1260 | 1269 | if (g_preamble_file && pos < out_buff_size) {
|
1261 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "%*s:line ", LOGURU_FILENAME_WIDTH, "file"); |
| 1270 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "%*s:line ", LOGURU_FILENAME_WIDTH, "file"); |
| 1271 | + if (bytes > 0) { |
| 1272 | + pos += bytes; |
| 1273 | + } |
1262 | 1274 | }
|
1263 | 1275 | if (g_preamble_verbose && pos < out_buff_size) {
|
1264 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, " v"); |
| 1276 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, " v"); |
| 1277 | + if (bytes > 0) { |
| 1278 | + pos += bytes; |
| 1279 | + } |
1265 | 1280 | }
|
1266 | 1281 | if (g_preamble_pipe && pos < out_buff_size) {
|
1267 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "| "); |
| 1282 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "| "); |
| 1283 | + if (bytes > 0) { |
| 1284 | + pos += bytes; |
| 1285 | + } |
1268 | 1286 | }
|
1269 | 1287 | }
|
1270 | 1288 |
|
@@ -1296,36 +1314,57 @@ namespace loguru
|
1296 | 1314 | snprintf(level_buff, sizeof(level_buff) - 1, "% 4d", verbosity);
|
1297 | 1315 | }
|
1298 | 1316 |
|
1299 |
| - long pos = 0; |
| 1317 | + size_t pos = 0; |
1300 | 1318 |
|
1301 | 1319 | if (g_preamble_date && pos < out_buff_size) {
|
1302 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "%04d-%02d-%02d ", |
1303 |
| - 1900 + time_info.tm_year, 1 + time_info.tm_mon, time_info.tm_mday); |
| 1320 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "%04d-%02d-%02d ", |
| 1321 | + 1900 + time_info.tm_year, 1 + time_info.tm_mon, time_info.tm_mday); |
| 1322 | + if (bytes > 0) { |
| 1323 | + pos += bytes; |
| 1324 | + } |
1304 | 1325 | }
|
1305 | 1326 | if (g_preamble_time && pos < out_buff_size) {
|
1306 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "%02d:%02d:%02d.%03lld ", |
1307 |
| - time_info.tm_hour, time_info.tm_min, time_info.tm_sec, ms_since_epoch % 1000); |
| 1327 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "%02d:%02d:%02d.%03lld ", |
| 1328 | + time_info.tm_hour, time_info.tm_min, time_info.tm_sec, ms_since_epoch % 1000); |
| 1329 | + if (bytes > 0) { |
| 1330 | + pos += bytes; |
| 1331 | + } |
1308 | 1332 | }
|
1309 | 1333 | if (g_preamble_uptime && pos < out_buff_size) {
|
1310 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "(%8.3fs) ", |
1311 |
| - uptime_sec); |
| 1334 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "(%8.3fs) ", |
| 1335 | + uptime_sec); |
| 1336 | + if (bytes > 0) { |
| 1337 | + pos += bytes; |
| 1338 | + } |
1312 | 1339 | }
|
1313 | 1340 | if (g_preamble_thread && pos < out_buff_size) {
|
1314 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "[%-*s]", |
1315 |
| - LOGURU_THREADNAME_WIDTH, thread_name); |
| 1341 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "[%-*s]", |
| 1342 | + LOGURU_THREADNAME_WIDTH, thread_name); |
| 1343 | + if (bytes > 0) { |
| 1344 | + pos += bytes; |
| 1345 | + } |
1316 | 1346 | }
|
1317 | 1347 | if (g_preamble_file && pos < out_buff_size) {
|
1318 | 1348 | char shortened_filename[LOGURU_FILENAME_WIDTH + 1];
|
1319 | 1349 | snprintf(shortened_filename, LOGURU_FILENAME_WIDTH + 1, "%s", file);
|
1320 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "%*s:%-5u ", |
1321 |
| - LOGURU_FILENAME_WIDTH, shortened_filename, line); |
| 1350 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "%*s:%-5u ", |
| 1351 | + LOGURU_FILENAME_WIDTH, shortened_filename, line); |
| 1352 | + if (bytes > 0) { |
| 1353 | + pos += bytes; |
| 1354 | + } |
1322 | 1355 | }
|
1323 | 1356 | if (g_preamble_verbose && pos < out_buff_size) {
|
1324 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "%4s", |
1325 |
| - level_buff); |
| 1357 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "%4s", |
| 1358 | + level_buff); |
| 1359 | + if (bytes > 0) { |
| 1360 | + pos += bytes; |
| 1361 | + } |
1326 | 1362 | }
|
1327 | 1363 | if (g_preamble_pipe && pos < out_buff_size) {
|
1328 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "| "); |
| 1364 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "| "); |
| 1365 | + if (bytes > 0) { |
| 1366 | + pos += bytes; |
| 1367 | + } |
1329 | 1368 | }
|
1330 | 1369 | }
|
1331 | 1370 |
|
@@ -1956,10 +1995,11 @@ namespace loguru
|
1956 | 1995 |
|
1957 | 1996 | #endif // _WIN32
|
1958 | 1997 |
|
1959 |
| -#ifdef _WIN32 |
1960 |
| -#ifdef _MSC_VER |
| 1998 | + |
| 1999 | +#if defined(__GNUC__) || defined(__clang__) |
| 2000 | +#pragma GCC diagnostic pop |
| 2001 | +#elif defined(_MSC_VER) |
1961 | 2002 | #pragma warning(pop)
|
1962 |
| -#endif // _MSC_VER |
1963 |
| -#endif // _WIN32 |
| 2003 | +#endif |
1964 | 2004 |
|
1965 | 2005 | #endif // LOGURU_IMPLEMENTATION
|
0 commit comments