Resolved warning suppression issue in timerDurationString(). It turns out BOTH this AND the solution were both in timer.c, and I somehow did not notice :V

This commit is contained in:
Pietro Gagliardi 2019-06-01 12:05:29 -04:00
parent a8ad49fead
commit efe118a81d
2 changed files with 17 additions and 20 deletions

View File

@ -154,7 +154,7 @@ static bool testingprivTRun(testingT *t, testingprivOutbuf *parentbuf)
return !t->failed; return !t->failed;
} }
// TODO rename all options to opts and all format to fmt // TODO rename all options to opts
static void testingprivSetRun(testingSet *set, const testingOptions *opts, testingprivOutbuf *outbuf, bool *anyFailed) static void testingprivSetRun(testingSet *set, const testingOptions *opts, testingprivOutbuf *outbuf, bool *anyFailed)
{ {
size_t i; size_t i;
@ -188,7 +188,7 @@ void testingprivTLogfFull(testingT *t, const char *file, long line, const char *
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, format);
testingprivTLogvfFull(t, file, line, format, ap); testingprivTLogvfFull(t, file, line, format, ap);
va_end(ap); va_end(ap);
} }

View File

@ -81,20 +81,20 @@ void timerDurationString(timerDuration d, char buf[timerDurationStringLen])
buf[1] = 's'; buf[1] = 's';
return; return;
} }
unsec = (uint64_t) d; neg = d < 0;
neg = false; if (neg) {
if (d < 0) { // C99 §6.2.6.2 resticts the possible signed integer representations in C to either sign-magnitude, 1's complement, or 2's complement.
#ifdef _MSC_VER // Therefore, INT64_MIN will always be either -INT64_MAX or -INT64_MAX - 1, so we can safely do this to see if we need to special-case INT64_MIN as -INT64_MIN cannot be safely represented, or if we can just say -d as that can be safely represented.
// TODO figure out a more explicit way to do this; until then, just go with what the standard says should happen, because it's what we want (TODO verify this) // See also https://stackoverflow.com/questions/29808397/how-to-portably-find-out-minint-max-absint-min
#pragma warning(push) if (d < -INT64_MAX) {
#pragma warning(disable: 4146) // INT64_MIN is -INT64_MAX - 1.
#endif // This value comes directly from forcing such a value into Go's code; let's just use it.
unsec = -unsec; memmove(buf, "-2562047h47m16.854775808s", (25 + 1) * sizeof (char));
#ifdef _MSC_VER return;
#pragma warning(pop)
#endif
neg = true;
} }
unsec = (uint64_t) (-d);
} else
unsec = (uint64_t) d;
for (p = parts; p->suffix != 0; p++) { for (p = parts; p->suffix != 0; p++) {
if (p->mode == modeMaxAndStop && unsec < p->maxOrMod) { if (p->mode == modeMaxAndStop && unsec < p->maxOrMod) {
@ -149,11 +149,8 @@ static void int128FromInt64(int64_t n, timerprivInt128 *out)
} }
out->neg = true; out->neg = true;
out->high = 0; out->high = 0;
// C99 §6.2.6.2 resticts the possible signed integer representations in C to either sign-magnitude, 1's complement, or 2's complement. // And now we do the same INT64_MIN/INT64_MAX juggling as above.
// Therefore, INT64_MIN will always be either -INT64_MAX or -INT64_MAX - 1, so we can safely do this to see if we need to special-case INT64_MIN as -INT64_MIN cannot be safely represented, or if we can just say -n as that can be safely represented.
// See also https://stackoverflow.com/questions/29808397/how-to-portably-find-out-minint-max-absint-min
if (n < -INT64_MAX) { if (n < -INT64_MAX) {
// INT64_MIN is -INT64_MAX - 1
out->low = ((uint64_t) INT64_MAX) + 1; out->low = ((uint64_t) INT64_MAX) + 1;
return; return;
} }