1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

Bug 923: Added comments about potential time_t truncation.

And removed Miciah's portability question; MSVC++2005 already
has a time_t longer than long, so assuming that time_t is long
is surely not portable.
This commit is contained in:
Kalle Olavi Niemitalo 2007-01-13 15:26:21 +02:00 committed by Kalle Olavi Niemitalo
parent 9385c93ffd
commit 01fdf6c4d3
6 changed files with 15 additions and 4 deletions

View File

@ -280,6 +280,7 @@ set_cookie_expires(struct dialog_data *dlg_data, struct widget_data *widget_data
if (!value || !cookie) return EVENT_NOT_PROCESSED;
/* Bug 923: Assumes time_t values fit in long. */
errno = 0;
number = strtol(value, (char **) &end, 10);
if (errno || *end || number < 0) return EVENT_NOT_PROCESSED;
@ -335,6 +336,7 @@ build_edit_dialog(struct terminal *term, struct cookie *cookie)
safe_strncpy(name, cookie->name, MAX_STR_LEN);
safe_strncpy(value, cookie->value, MAX_STR_LEN);
safe_strncpy(domain, cookie->domain, MAX_STR_LEN);
/* Bug 923: Assumes time_t values fit in unsigned long. */
ulongcat(expires, &length, cookie->expires, MAX_STR_LEN, 0);
length = 0;
ulongcat(secure, &length, cookie->secure, MAX_STR_LEN, 0);

View File

@ -760,6 +760,7 @@ parse_bittorrent_metafile(struct bittorrent_meta *meta, struct string *metafile)
break;
case BENCODING_TOKEN_CREATION_DATE:
/* Bug 923: Assumes time_t values fit in off_t. */
meta->creation_date = (time_t) parse_bencoding_integer(value);
skip_scanner_token(&scanner);
break;

View File

@ -109,6 +109,7 @@ parse_ftp_eplf_response(struct ftp_file_info *info, unsigned char *src, int len)
case FTP_EPLF_MTIME:
if (src >= pos) break;
/* Bug 923: Assumes time_t values cannot exceed LONG_MAX. */
info->mtime = (time_t) parse_ftp_number(&src, pos, 0, LONG_MAX);
break;
case FTP_EPLF_ID:

View File

@ -150,6 +150,7 @@ smjs_globhist_item_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *
case GLOBHIST_LAST_VISIT: {
uint32 seconds;
/* Bug 923: Assumes time_t values fit in uint32. */
JS_ValueToECMAUint32(smjs_ctx, *vp, &seconds);
history_item->last_visit = seconds;

View File

@ -134,6 +134,8 @@ timeval_from_milliseconds(timeval_T *t, milliseconds_T milliseconds)
return t;
}
/* Bug 923: Assumes time_t values fit in long. (This function is used
* for both timestamps and durations.) */
timeval_T *
timeval_from_seconds(timeval_T *t, long seconds)
{
@ -184,6 +186,8 @@ timeval_to_milliseconds(timeval_T *t)
return add_ms_to_ms(a, b);
}
/* Bug 923: Assumes time_t values fit in long. (This function is used
* for both timestamps and durations.) */
long
timeval_to_seconds(timeval_T *t)
{

View File

@ -16,18 +16,20 @@ typedef long milliseconds_T;
#define ms_max(a, b) ((a) < (b) ? (b) : (a))
#define ms_min(a, b) ((a) < (b) ? (a) : (b))
/* Is using atol() in this way acceptable? It seems
* non-portable to me; time_t might not be a long. -- Miciah */
/* Bug 923: Assumes time_t values fit in long. */
#define str_to_time_t(s) ((time_t) atol(s))
/* When formatting time_t values to be parsed with str_to_time_t,
* we first cast to time_print_T and then printf the result with
* TIME_PRINT_FORMAT. */
* TIME_PRINT_FORMAT.
* Bug 923: Assumes time_t values fit in long. */
typedef long time_print_T;
#define TIME_PRINT_FORMAT "ld"
/* Redefine a timeval that has all fields signed so calculations
* will be simplified on rare systems that define timeval with
* unsigned fields. */
* unsigned fields.
* Bug 923: Assumes time_t values fit in long. (This structure is
* used for both timestamps and durations.) */
typedef struct { long sec; long usec; } timeval_T;
timeval_T *timeval_from_milliseconds(timeval_T *t, milliseconds_T milliseconds);