On Fri, 17 Jul 2009, Karel Zak wrote:
The ideal solution is to use
$ git commit -a -s
$ git format-patch HEAD^
$ git send-email --to "util-linux-ng@...." <the patch>
Hi Karel,
attached are to more patches for cal, which is babdly broken.
(1) 0001-cal-fix-harmless-typo.patch
(2) fixed locally, no patch
On my system the week starts with Saturday. For some strange reason I get
(from GNU libc 2.3.6, i686)
(int)(intptr_t)nl_langinfo(_NL_TIME_WEEK_1STDAY) = 19971130
*nl_langinfo(_NL_TIME_FIRST_WEEKDAY)) = 7
and consequently
weekstart = 6 (Sat).
This has the effect that 'cal 9 1752' yields a segmentation fault whereas
'cal -j 9 1752' prints garbage.
The proper code should make absolutely sure that 0<=weekstart<=6 (no matter
what results from nl_langinfo), otherwise the next patch may fail as well.
My solution is to disable the piece of code computing a locale dependent
value for weekstart.
(3) 0002-cal-fix-broken-computation-for-Sep-1752.patch
Given the possibility that weekstart can have any value from 0 to 6, the
old code handling the arrays for Sep 1752
int sep1752[MAXDAYS] = { .... };
int days[MAXDAYS];
int *d_sep1752 = sep1752;
memcpy(days, d_sep1752 + weekstart, MAXDAYS * sizeof(int));
is inherently broken and could yield a segfault whenever weekstart != 0.
Moreover the highlighting for Sep 1752 is wrong: 'cal -s 16 9 1752'
correctly highlights the 16th, whereas 'cal -m 16 9 1752' highlights the
17th (same position but wrong day).
Regards
Peter Breitenlohner <peb@xxxxxxxxxxxx>
From 040d1f7f903bb033a37eca0e9e02557013c53cab Mon Sep 17 00:00:00 2001
From: Peter Breitenlohner <peb@xxxxxxxxxxxx>
Date: Fri, 17 Jul 2009 13:12:48 +0200
Subject: [PATCH 1/2] cal: fix (harmless) typo
Signed-off-by: Peter Breitenlohner <peb@xxxxxxxxxxxx>
---
misc-utils/cal.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index a8534b8..3e38f8e 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -354,7 +354,7 @@ main(int argc, char **argv) {
day = month = year = 0;
switch(argc) {
case 3:
- if ((day = atoi(*argv++)) < 1 || month > 31)
+ if ((day = atoi(*argv++)) < 1 || day > 31)
errx(1, _("illegal day value: use 1-%d"), 31);
/* FALLTHROUGH */
case 2:
--
1.6.3.3
From 869db6afc1736598e52c24f8813e2d1940734e90 Mon Sep 17 00:00:00 2001
From: Peter Breitenlohner <peb@xxxxxxxxxxxx>
Date: Fri, 17 Jul 2009 13:39:07 +0200
Subject: [PATCH 2/2] cal: fix broken computation for Sep 1752
Signed-off-by: Peter Breitenlohner <peb@xxxxxxxxxxxx>
---
misc-utils/cal.c | 23 ++++++++++++++---------
1 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 3e38f8e..bda3a96 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -162,7 +162,7 @@ char *Hrow; /* pointer to highlighted row in month */
#define FIRST_MISSING_DAY 639799 /* 3 Sep 1752 */
#define NUMBER_MISSING_DAYS 11 /* 11 day correction */
-#define MAXDAYS 43 /* max slots in a month array */
+#define MAXDAYS 42 /* slots in a month array */
#define SPACE -1 /* used in day array */
static int days_in_month[2][13] = {
@@ -170,30 +170,34 @@ static int days_in_month[2][13] = {
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
};
-int sep1752[MAXDAYS] = {
+#define SEP1752_OFS 4 /* sep1752[4] is a Sunday */
+
+/* 1 Sep 1752 is represented by sep1752[6] and j_sep1752[6] */
+int sep1752[MAXDAYS+6] = {
+ SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, 1, 2, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE
-}, j_sep1752[MAXDAYS] = {
+ SPACE, SPACE
+}, j_sep1752[MAXDAYS+6] = {
+ SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, 245, 246, 258, 259, 260,
261, 262, 263, 264, 265, 266, 267,
268, 269, 270, 271, 272, 273, 274,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE
+ SPACE, SPACE
}, empty[MAXDAYS] = {
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE
+ SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE
};
#define DAY_LEN 3 /* 3 spaces per day */
@@ -629,10 +633,11 @@ day_array(int day, int month, int year, int *days) {
int *d_sep1752;
if (month == 9 && year == 1752) {
+ int sep1752_ofs = (weekstart + SEP1752_OFS) % 7;
d_sep1752 = julian ? j_sep1752 : sep1752;
- memcpy(days, d_sep1752 + weekstart, MAXDAYS * sizeof(int));
+ memcpy(days, d_sep1752 + sep1752_ofs, MAXDAYS * sizeof(int));
for (dm=0; dm<MAXDAYS; dm++)
- if (j_sep1752[dm] == day)
+ if (j_sep1752[dm + sep1752_ofs] == day)
days[dm] |= TODAY_FLAG;
return;
}
--
1.6.3.3