chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Properly check for overflow in offsets
[elogind.git]
/
src
/
shared
/
time-util.c
diff --git
a/src/shared/time-util.c
b/src/shared/time-util.c
index b6a2bec15693161bc7e1b6ccd38cb6515611a3d4..9ee711a49e58e0c1a7c276201897f52d0f305a36 100644
(file)
--- a/
src/shared/time-util.c
+++ b/
src/shared/time-util.c
@@
-251,6
+251,12
@@
char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
if (t == (usec_t) -1)
return NULL;
if (t == (usec_t) -1)
return NULL;
+ if (t <= 0) {
+ snprintf(p, l, "0");
+ p[l-1] = 0;
+ return p;
+ }
+
/* The result of this function can be parsed with parse_sec */
for (i = 0; i < ELEMENTSOF(table); i++) {
/* The result of this function can be parsed with parse_sec */
for (i = 0; i < ELEMENTSOF(table); i++) {
@@
-259,15
+265,11
@@
char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
bool done = false;
usec_t a, b;
bool done = false;
usec_t a, b;
- if (t == 0 || t < accuracy) {
- if (!something) {
- snprintf(p, l, "0");
- p[l-1] = 0;
- return p;
- }
+ if (t <= 0)
+ break;
+ if (t < accuracy && something)
break;
break;
- }
if (t < table[i].usec)
continue;
if (t < table[i].usec)
continue;
@@
-322,7
+324,6
@@
char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
l -= n;
p += n;
l -= n;
p += n;
-
something = true;
}
something = true;
}