Denys Vlasenko
2013-09-03 14:29:32 UTC
Signed-off-by: Denys Vlasenko <dvlasenk-H+wXaHxf7aLQT0dZR+***@public.gmane.org>
---
src/lib/problem_data.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/lib/problem_data.c b/src/lib/problem_data.c
index c3da1e7..ea2c94e 100644
--- a/src/lib/problem_data.c
+++ b/src/lib/problem_data.c
@@ -37,9 +37,12 @@ char *problem_item_format(struct problem_item *item)
{
errno = 0;
char *end;
- time_t time = strtol(item->content, &end, 10);
- if (!errno && !*end && end != item->content)
- {
+ /* On x32 arch, time_t is wider than long. Must use strtoll */
+ long long ll = strtoll(item->content, &end, 10);
+ time_t time = ll;
+ if (!errno && *end == '\0' && end != item->content
+ && ll == time /* there was no truncation in long long -> time_t conv */
+ ) {
char timeloc[256];
int success = strftime(timeloc, sizeof(timeloc), "%c", localtime(&time));
if (success)
---
src/lib/problem_data.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/lib/problem_data.c b/src/lib/problem_data.c
index c3da1e7..ea2c94e 100644
--- a/src/lib/problem_data.c
+++ b/src/lib/problem_data.c
@@ -37,9 +37,12 @@ char *problem_item_format(struct problem_item *item)
{
errno = 0;
char *end;
- time_t time = strtol(item->content, &end, 10);
- if (!errno && !*end && end != item->content)
- {
+ /* On x32 arch, time_t is wider than long. Must use strtoll */
+ long long ll = strtoll(item->content, &end, 10);
+ time_t time = ll;
+ if (!errno && *end == '\0' && end != item->content
+ && ll == time /* there was no truncation in long long -> time_t conv */
+ ) {
char timeloc[256];
int success = strftime(timeloc, sizeof(timeloc), "%c", localtime(&time));
if (success)
--
1.8.1.4
1.8.1.4