|
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"
|
@@ -1249,27 +1246,45 @@ namespace loguru
|
1249 | 1246 | {
|
1250 | 1247 | if (out_buff_size == 0) { return; }
|
1251 | 1248 | out_buff[0] = '\0';
|
1252 |
| - long pos = 0; |
1253 |
| - if (g_preamble_date) { |
1254 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "date "); |
| 1249 | + size_t pos = 0; |
| 1250 | + if (g_preamble_date && pos < out_buff_size) { |
| 1251 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "date "); |
| 1252 | + if (bytes > 0) { |
| 1253 | + pos += bytes; |
| 1254 | + } |
1255 | 1255 | }
|
1256 | 1256 | if (g_preamble_time && pos < out_buff_size) {
|
1257 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "time "); |
| 1257 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "time "); |
| 1258 | + if (bytes > 0) { |
| 1259 | + pos += bytes; |
| 1260 | + } |
1258 | 1261 | }
|
1259 | 1262 | if (g_preamble_uptime && pos < out_buff_size) {
|
1260 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "( uptime ) "); |
| 1263 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "( uptime ) "); |
| 1264 | + if (bytes > 0) { |
| 1265 | + pos += bytes; |
| 1266 | + } |
1261 | 1267 | }
|
1262 | 1268 | if (g_preamble_thread && pos < out_buff_size) {
|
1263 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "[%-*s]", LOGURU_THREADNAME_WIDTH, " thread name/id"); |
| 1269 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "[%-*s]", LOGURU_THREADNAME_WIDTH, " thread name/id"); |
| 1270 | + if (bytes > 0) { |
| 1271 | + pos += bytes; |
| 1272 | + } |
1264 | 1273 | }
|
1265 | 1274 | if (g_preamble_file && pos < out_buff_size) {
|
1266 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "%*s:line ", LOGURU_FILENAME_WIDTH, "file"); |
| 1275 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "%*s:line ", LOGURU_FILENAME_WIDTH, "file"); |
| 1276 | + if (bytes > 0) { |
| 1277 | + pos += bytes; |
| 1278 | + } |
1267 | 1279 | }
|
1268 | 1280 | if (g_preamble_verbose && pos < out_buff_size) {
|
1269 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, " v"); |
| 1281 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, " v"); |
| 1282 | + if (bytes > 0) { |
| 1283 | + pos += bytes; |
| 1284 | + } |
1270 | 1285 | }
|
1271 | 1286 | if (g_preamble_pipe && pos < out_buff_size) {
|
1272 |
| - /* pos += */ snprintf(out_buff + pos, out_buff_size - pos, "| "); |
| 1287 | + /* pos += */ (void)snprintf(out_buff + pos, out_buff_size - pos, "| "); |
1273 | 1288 | }
|
1274 | 1289 | }
|
1275 | 1290 |
|
@@ -1301,36 +1316,54 @@ namespace loguru
|
1301 | 1316 | snprintf(level_buff, sizeof(level_buff) - 1, "% 4d", verbosity);
|
1302 | 1317 | }
|
1303 | 1318 |
|
1304 |
| - long pos = 0; |
| 1319 | + size_t pos = 0; |
1305 | 1320 |
|
1306 |
| - if (g_preamble_date) { |
1307 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "%04d-%02d-%02d ", |
1308 |
| - 1900 + time_info.tm_year, 1 + time_info.tm_mon, time_info.tm_mday); |
| 1321 | + if (g_preamble_date && pos < out_buff_size) { |
| 1322 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "%04d-%02d-%02d ", |
| 1323 | + 1900 + time_info.tm_year, 1 + time_info.tm_mon, time_info.tm_mday); |
| 1324 | + if (bytes > 0) { |
| 1325 | + pos += bytes; |
| 1326 | + } |
1309 | 1327 | }
|
1310 | 1328 | if (g_preamble_time && pos < out_buff_size) {
|
1311 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "%02d:%02d:%02d.%03lld ", |
1312 |
| - time_info.tm_hour, time_info.tm_min, time_info.tm_sec, ms_since_epoch % 1000); |
| 1329 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "%02d:%02d:%02d.%03lld ", |
| 1330 | + time_info.tm_hour, time_info.tm_min, time_info.tm_sec, ms_since_epoch % 1000); |
| 1331 | + if (bytes > 0) { |
| 1332 | + pos += bytes; |
| 1333 | + } |
1313 | 1334 | }
|
1314 | 1335 | if (g_preamble_uptime && pos < out_buff_size) {
|
1315 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "(%8.3fs) ", |
1316 |
| - uptime_sec); |
| 1336 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "(%8.3fs) ", |
| 1337 | + uptime_sec); |
| 1338 | + if (bytes > 0) { |
| 1339 | + pos += bytes; |
| 1340 | + } |
1317 | 1341 | }
|
1318 | 1342 | if (g_preamble_thread && pos < out_buff_size) {
|
1319 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "[%-*s]", |
1320 |
| - LOGURU_THREADNAME_WIDTH, thread_name); |
| 1343 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "[%-*s]", |
| 1344 | + LOGURU_THREADNAME_WIDTH, thread_name); |
| 1345 | + if (bytes > 0) { |
| 1346 | + pos += bytes; |
| 1347 | + } |
1321 | 1348 | }
|
1322 | 1349 | if (g_preamble_file && pos < out_buff_size) {
|
1323 | 1350 | char shortened_filename[LOGURU_FILENAME_WIDTH + 1];
|
1324 | 1351 | snprintf(shortened_filename, LOGURU_FILENAME_WIDTH + 1, "%s", file);
|
1325 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "%*s:%-5u ", |
1326 |
| - LOGURU_FILENAME_WIDTH, shortened_filename, line); |
| 1352 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "%*s:%-5u ", |
| 1353 | + LOGURU_FILENAME_WIDTH, shortened_filename, line); |
| 1354 | + if (bytes > 0) { |
| 1355 | + pos += bytes; |
| 1356 | + } |
1327 | 1357 | }
|
1328 | 1358 | if (g_preamble_verbose && pos < out_buff_size) {
|
1329 |
| - pos += snprintf(out_buff + pos, out_buff_size - pos, "%4s", |
1330 |
| - level_buff); |
| 1359 | + int bytes = snprintf(out_buff + pos, out_buff_size - pos, "%4s", |
| 1360 | + level_buff); |
| 1361 | + if (bytes > 0) { |
| 1362 | + pos += bytes; |
| 1363 | + } |
1331 | 1364 | }
|
1332 | 1365 | if (g_preamble_pipe && pos < out_buff_size) {
|
1333 |
| - /* pos += */ snprintf(out_buff + pos, out_buff_size - pos, "| "); |
| 1366 | + /* pos += */ (void)snprintf(out_buff + pos, out_buff_size - pos, "| "); |
1334 | 1367 | }
|
1335 | 1368 | }
|
1336 | 1369 |
|
@@ -1969,10 +2002,11 @@ namespace loguru
|
1969 | 2002 |
|
1970 | 2003 | #endif // _WIN32
|
1971 | 2004 |
|
1972 |
| -#ifdef _WIN32 |
1973 |
| -#ifdef _MSC_VER |
| 2005 | + |
| 2006 | +#if defined(__GNUC__) || defined(__clang__) |
| 2007 | +#pragma GCC diagnostic pop |
| 2008 | +#elif defined(_MSC_VER) |
1974 | 2009 | #pragma warning(pop)
|
1975 |
| -#endif // _MSC_VER |
1976 |
| -#endif // _WIN32 |
| 2010 | +#endif |
1977 | 2011 |
|
1978 | 2012 | #endif // LOGURU_IMPLEMENTATION
|
0 commit comments