Permalink
Browse files

fix long long overflow

  • Loading branch information...
1 parent cf731d9 commit 238d5ecd35cb93c07d1dd120460ff13825ad35fa @tj tj committed Jan 26, 2013
Showing with 5 additions and 4 deletions.
  1. +5 −4 ms.c
View
9 ms.c
@@ -12,11 +12,12 @@
// microseconds
-#define US_SEC 1000000
+#define US_MSEC (long long) 1000
+#define US_SEC 1000 * US_MSEC
#define US_MIN 60 * US_SEC
#define US_HOUR 60 * US_MIN
#define US_DAY 24 * US_HOUR
-#define US_WEEK 7 * US_HOUR
+#define US_WEEK 7 * US_DAY
#define US_YEAR 52 * US_WEEK
// milliseconds
@@ -90,7 +91,7 @@ char *
milliseconds_to_string(long long ms) {
char *str = malloc(MS_MAX);
if (!str) return NULL;
- long div = 1;
+ long long div = 1;
char *fmt;
if (ms < MS_SEC) fmt = "%lldms";
@@ -112,7 +113,7 @@ milliseconds_to_string(long long ms) {
char *
milliseconds_to_long_string(long long ms) {
- long div;
+ long long div;
char *name;
char *str = malloc(MS_MAX);

0 comments on commit 238d5ec

Please sign in to comment.