From 17aaa40d1d3e21fec81d2a52902050292f4fe6a1 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 1 Mar 2024 20:23:41 +0300 Subject: [PATCH] Fix msg_date_d and msg_date_e wrongly parsing dates after 29 Feb. Mon returned by month_d() is in 0..11 range. Fix unit-tests that were assuming 25 Mar 2004 to be Wednesday but it's actually Thursday. --- libsofia-sip-ua/msg/msg_date.c | 4 ++-- libsofia-sip-ua/sip/torture_sip.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libsofia-sip-ua/msg/msg_date.c b/libsofia-sip-ua/msg/msg_date.c index 47ffb7ed..2b107959 100644 --- a/libsofia-sip-ua/msg/msg_date.c +++ b/libsofia-sip-ua/msg/msg_date.c @@ -296,7 +296,7 @@ issize_t msg_date_d(char const **ss, msg_time_t *date) (min + 60 * (hour + 24 * (day - 1 + mon * 30 + first_day_offset[mon] + - (leap_year && mon > 2) + ydays))); + (leap_year && mon > 1) + ydays))); } *ss = s; @@ -357,7 +357,7 @@ issize_t msg_date_e(char b[], isize_t bsiz, msg_time_t http_date) while (day >= days_per_month) { day -= days_per_month; month++; - days_per_month = days_per_months[month] + (leap_year && month == 2); + days_per_month = days_per_months[month] + (leap_year && month == 1); } return snprintf(b, bsiz, "%s, %02ld %s %04ld %02ld:%02ld:%02ld GMT", diff --git a/libsofia-sip-ua/sip/torture_sip.c b/libsofia-sip-ua/sip/torture_sip.c index 00514fbd..78989d4b 100644 --- a/libsofia-sip-ua/sip/torture_sip.c +++ b/libsofia-sip-ua/sip/torture_sip.c @@ -743,7 +743,7 @@ int test_basic(void) TEST_1(ex = sip_expires_make(home, "4294967297")); /* XXX */ su_free(home, ex); - TEST_1(ex = sip_expires_make(home, "Wed, 25 Mar 2004 14:49:29 GMT")); + TEST_1(ex = sip_expires_make(home, "Thu, 25 Mar 2004 14:49:29 GMT")); su_free(home, ex); TEST_1(ex = sip_expires_create(home, 3600)); @@ -1034,7 +1034,7 @@ static int test_encoding(void) "Extension-Header: extended, more\r\n" "Reason: Q.850;cause=16;text=\"Terminated\"\r\n" "Contact: \r\n" - "Date: Wed, 25 Mar 2004 14:49:29 GMT\r\n" + "Date: Thu, 25 Mar 2004 14:49:29 GMT\r\n" "Max-Forwards: 80\r\n" "Min-Expires: 30\r\n" "Retry-After: 48 (this is a comment) ;duration=321\r\n" @@ -1109,10 +1109,10 @@ static int test_encoding(void) "Extension-Header: extended, more\r\n" "Reason: SIP;cause=400;text=\"Bad Message\"\r\n" "Contact: ;audio\r\n" - "Date: Wed, 25 Mar 2004 14:49:29 GMT\r\n" + "Date: Thu, 25 Mar 2004 14:49:29 GMT\r\n" "Max-Forwards: 80\r\n" "Min-Expires: 30\r\n" - "Expires: Wed, 25 Mar 2004 15:49:29 GMT\r\n" + "Expires: Thu, 25 Mar 2004 15:49:29 GMT\r\n" "Retry-After: 48;duration=321\r\n" "Record-Route: \r\n" "Event: presence;id=1\r\n"