@@ -53,6 +53,10 @@ static regex_t date_ymd_regex;
5353
5454static gboolean regex_compiled = FALSE ;
5555
56+ /* Set and clear flags in bit-flags */
57+ #define import_set_flag (i,f ) (i = static_cast <GncImportFormat>(static_cast <int >(i) | static_cast <int >(f)))
58+ #define import_clear_flag (i,f ) (i = static_cast <GncImportFormat>(static_cast <int >(i) & static_cast <int >(~f)))
59+
5660static void
5761compile_regex (void )
5862{
@@ -104,7 +108,7 @@ my_strntol(const char *str, int len)
104108static GncImportFormat
105109check_date_format (const char * str, regmatch_t *match, GncImportFormat fmts)
106110{
107- GncImportFormat res = 0 ;
111+ GncImportFormat res = GNCIF_NONE ;
108112 int len0 = 0 , len1 = 0 , len2 = 0 ;
109113 int val0 = 0 , val1 = 0 , val2 = 0 ;
110114
@@ -179,18 +183,18 @@ check_date_format(const char * str, regmatch_t *match, GncImportFormat fmts)
179183GncImportFormat
180184gnc_import_test_numeric (const char * str, GncImportFormat fmts)
181185{
182- GncImportFormat res = 0 ;
186+ GncImportFormat res = GNCIF_NONE ;
183187
184188 g_return_val_if_fail (str, fmts);
185189
186190 if (!regex_compiled)
187191 compile_regex ();
188192
189193 if ((fmts & GNCIF_NUM_PERIOD) && !regexec (&decimal_radix_regex, str, 0 , NULL , 0 ))
190- res |= GNCIF_NUM_PERIOD ;
194+ import_set_flag ( res, GNCIF_NUM_PERIOD) ;
191195
192196 if ((fmts & GNCIF_NUM_COMMA) && !regexec (&comma_radix_regex, str, 0 , NULL , 0 ))
193- res |= GNCIF_NUM_COMMA ;
197+ import_set_flag ( res, GNCIF_NUM_COMMA) ;
194198
195199 return res;
196200}
@@ -200,7 +204,7 @@ GncImportFormat
200204gnc_import_test_date (const char * str, GncImportFormat fmts)
201205{
202206 regmatch_t match[5 ];
203- GncImportFormat res = 0 ;
207+ GncImportFormat res = GNCIF_NONE ;
204208
205209 g_return_val_if_fail (str, fmts);
206210 g_return_val_if_fail (strlen (str) > 1 , fmts);
@@ -218,23 +222,24 @@ gnc_import_test_date(const char* str, GncImportFormat fmts)
218222 * let's try both ways and let the parser check that YYYY is
219223 * valid.
220224 */
221- char temp [9 ];
225+ #define DATE_LEN 8
226+ char temp[DATE_LEN + 1 ];
222227
223228 g_return_val_if_fail (match[4 ].rm_so != -1 , fmts);
224- g_return_val_if_fail (match [4 ].rm_eo - match [4 ].rm_so == 8 , fmts );
229+ g_return_val_if_fail (match[4 ].rm_eo - match[4 ].rm_so == DATE_LEN , fmts);
225230
226231 /* make a temp copy of the XXXXXXXX string */
227- strncpy (temp , str + match [4 ].rm_so , 8 );
228- temp [8 ] = '\0' ;
232+ strncpy (temp, str + match[4 ].rm_so , DATE_LEN );
233+ temp[DATE_LEN ] = ' \0 ' ;
229234
230235 /* then check it against the ymd or mdy formats, as necessary */
231236 if (((fmts & GNCIF_DATE_YDM) || (fmts & GNCIF_DATE_YMD)) &&
232237 !regexec (&date_ymd_regex, temp, 4 , match, 0 ))
233- res |= check_date_format (temp , match , fmts );
238+ import_set_flag ( res, check_date_format (temp, match, fmts) );
234239
235240 if (((fmts & GNCIF_DATE_DMY) || (fmts & GNCIF_DATE_MDY)) &&
236241 !regexec (&date_mdy_regex, temp, 4 , match, 0 ))
237- res |= check_date_format (temp , match , fmts );
242+ import_set_flag ( res, check_date_format (temp, match, fmts) );
238243 }
239244 }
240245
0 commit comments