aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/alf.c5
-rw-r--r--src/extract.c4
-rw-r--r--src/listalf.c10
3 files changed, 15 insertions, 4 deletions
diff --git a/src/alf.c b/src/alf.c
index 82c9432..d0490ab 100644
--- a/src/alf.c
+++ b/src/alf.c
@@ -108,6 +108,11 @@ unsigned long get_msdos_date_time(void) {
else
tm = localtime(&t);
+ /* use a 0 timestamp if the year's out of range, unalf will
+ display it as <none>. */
+ if(tm->tm_year < 1980 || tm->tm_year > 2107)
+ return 0;
+
msdos_year = tm->tm_year + 1900 - 1980;
/* tm_mon + 1 because MS uses 1-12 for months, and struct tm uses 0-11 */
diff --git a/src/extract.c b/src/extract.c
index f6b36e7..bb40056 100644
--- a/src/extract.c
+++ b/src/extract.c
@@ -49,6 +49,10 @@ void set_datetime() {
struct utimbuf utb;
t = dpeek(alf_hdr_time0);
+
+ /* don't set the date/time at all, if it's zero */
+ if(!t) return;
+
d = dpeek(alf_hdr_date0);
tm.tm_sec = (t & 0x1f) << 1;
diff --git a/src/listalf.c b/src/listalf.c
index 34078e5..33b2bfe 100644
--- a/src/listalf.c
+++ b/src/listalf.c
@@ -50,14 +50,16 @@ void format_msdos_date(char *buf) {
/* year actually ranges 1980 to 2107... */
year = (d >> 9) + 1980;
- /* valid months range 1 to 12. values 0, 13, 14, 15 are possible
- but invalid (print as ???) */
+ /* valid months range 1 to 12 */
month = (d >> 5) & 0x0f;
- /* valid day range is 1 to 31. 0 is invalid, print as-is. */
+ /* valid day range is 1 to 31. 0 is invalid. */
day = d & 0x1f;
- snprintf(buf, 12, "%2d %3s %04d", day, monthnames[month], year);
+ if(day == 0 || month == 0 || month > 12)
+ strncpy(buf, "<none>", 12);
+ else
+ snprintf(buf, 12, "%2d %3s %04d", day, monthnames[month], year);
}
/* small files may be "compressed" larger than the original, so this