Package: syslog-ng / 3.28.1-2+deb11u1

0010-timeutils-name-repeating-constant.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
From: László Várady <laszlo.varady@protonmail.com>
Date: Sat, 20 Aug 2022 14:29:43 +0200
Subject: timeutils: name repeating constant

Signed-off-by: László Várady <laszlo.varady@protonmail.com>
Origin: https://github.com/syslog-ng/syslog-ng/commit/09f489c89c826293ff8cbd282cfc866ab56054c4
---
 lib/timeutils/scan-timestamp.c | 54 +++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 25 deletions(-)

diff --git a/lib/timeutils/scan-timestamp.c b/lib/timeutils/scan-timestamp.c
index cb6802d..197e3ad 100644
--- a/lib/timeutils/scan-timestamp.c
+++ b/lib/timeutils/scan-timestamp.c
@@ -34,41 +34,43 @@ scan_day_abbrev(const gchar **buf, gint *left, gint *wday)
 {
   *wday = -1;
 
-  if (*left < 3)
+  const gsize abbrev_length = 3;
+
+  if (*left < abbrev_length)
     return FALSE;
 
   switch (**buf)
     {
     case 'S':
-      if (strncasecmp(*buf, "Sun", 3) == 0)
+      if (strncasecmp(*buf, "Sun", abbrev_length) == 0)
         *wday = 0;
-      else if (strncasecmp(*buf, "Sat", 3) == 0)
+      else if (strncasecmp(*buf, "Sat", abbrev_length) == 0)
         *wday = 6;
       else
         return FALSE;
       break;
     case 'M':
-      if (strncasecmp(*buf, "Mon", 3) == 0)
+      if (strncasecmp(*buf, "Mon", abbrev_length) == 0)
         *wday = 1;
       else
         return FALSE;
       break;
     case 'T':
-      if (strncasecmp(*buf, "Tue", 3) == 0)
+      if (strncasecmp(*buf, "Tue", abbrev_length) == 0)
         *wday = 2;
-      else if (strncasecmp(*buf, "Thu", 3) == 0)
+      else if (strncasecmp(*buf, "Thu", abbrev_length) == 0)
         *wday = 4;
       else
         return FALSE;
       break;
     case 'W':
-      if (strncasecmp(*buf, "Wed", 3) == 0)
+      if (strncasecmp(*buf, "Wed", abbrev_length) == 0)
         *wday = 3;
       else
         return FALSE;
       break;
     case 'F':
-      if (strncasecmp(*buf, "Fri", 3) == 0)
+      if (strncasecmp(*buf, "Fri", abbrev_length) == 0)
         *wday = 5;
       else
         return FALSE;
@@ -77,8 +79,8 @@ scan_day_abbrev(const gchar **buf, gint *left, gint *wday)
       return FALSE;
     }
 
-  (*buf) += 3;
-  (*left) -= 3;
+  (*buf) += abbrev_length;
+  (*left) -= abbrev_length;
   return TRUE;
 }
 
@@ -87,63 +89,65 @@ scan_month_abbrev(const gchar **buf, gint *left, gint *mon)
 {
   *mon = -1;
 
-  if (*left < 3)
+  const gsize abbrev_length = 3;
+
+  if (*left < abbrev_length)
     return FALSE;
 
   switch (**buf)
     {
     case 'J':
-      if (strncasecmp(*buf, "Jan", 3) == 0)
+      if (strncasecmp(*buf, "Jan", abbrev_length) == 0)
         *mon = 0;
-      else if (strncasecmp(*buf, "Jun", 3) == 0)
+      else if (strncasecmp(*buf, "Jun", abbrev_length) == 0)
         *mon = 5;
-      else if (strncasecmp(*buf, "Jul", 3) == 0)
+      else if (strncasecmp(*buf, "Jul", abbrev_length) == 0)
         *mon = 6;
       else
         return FALSE;
       break;
     case 'F':
-      if (strncasecmp(*buf, "Feb", 3) == 0)
+      if (strncasecmp(*buf, "Feb", abbrev_length) == 0)
         *mon = 1;
       else
         return FALSE;
       break;
     case 'M':
-      if (strncasecmp(*buf, "Mar", 3) == 0)
+      if (strncasecmp(*buf, "Mar", abbrev_length) == 0)
         *mon = 2;
-      else if (strncasecmp(*buf, "May", 3) == 0)
+      else if (strncasecmp(*buf, "May", abbrev_length) == 0)
         *mon = 4;
       else
         return FALSE;
       break;
     case 'A':
-      if (strncasecmp(*buf, "Apr", 3) == 0)
+      if (strncasecmp(*buf, "Apr", abbrev_length) == 0)
         *mon = 3;
-      else if (strncasecmp(*buf, "Aug", 3) == 0)
+      else if (strncasecmp(*buf, "Aug", abbrev_length) == 0)
         *mon = 7;
       else
         return FALSE;
       break;
     case 'S':
-      if (strncasecmp(*buf, "Sep", 3) == 0)
+      if (strncasecmp(*buf, "Sep", abbrev_length) == 0)
         *mon = 8;
       else
         return FALSE;
       break;
     case 'O':
-      if (strncasecmp(*buf, "Oct", 3) == 0)
+      if (strncasecmp(*buf, "Oct", abbrev_length) == 0)
         *mon = 9;
       else
         return FALSE;
       break;
     case 'N':
-      if (strncasecmp(*buf, "Nov", 3) == 0)
+      if (strncasecmp(*buf, "Nov", abbrev_length) == 0)
         *mon = 10;
       else
         return FALSE;
       break;
     case 'D':
-      if (strncasecmp(*buf, "Dec", 3) == 0)
+      if (strncasecmp(*buf, "Dec", abbrev_length) == 0)
         *mon = 11;
       else
         return FALSE;
@@ -152,8 +156,8 @@ scan_month_abbrev(const gchar **buf, gint *left, gint *mon)
       return FALSE;
     }
 
-  (*buf) += 3;
-  (*left) -= 3;
+  (*buf) += abbrev_length;
+  (*left) -= abbrev_length;
   return TRUE;
 }