Skip to content

Commit f8caaef

Browse files
committed
Fixed 'const' warnings
1 parent 079fc2e commit f8caaef

File tree

9 files changed

+52
-23
lines changed

9 files changed

+52
-23
lines changed

Makefile

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
11
FLAGS=-O0 -ggdb3 \
2-
-Wall -Werror -Wextra -fsanitize=undefined -fsanitize=address \
3-
-Wmaybe-uninitialized -Wmissing-field-initializers -Wshadow -Wno-unused-parameter \
4-
-pedantic -Wno-implicit-fallthrough \
2+
-Wall -Werror -Wextra \
3+
-Wempty-body \
4+
-Wenum-compare \
5+
-Wformat-nonliteral \
6+
-Wformat-security \
7+
-Wimplicit-fallthrough \
8+
-Winit-self \
9+
-Wlogical-not-parentheses \
10+
-Wlogical-op \
11+
-Wmaybe-uninitialized \
12+
-Wmaybe-uninitialized \
13+
-Wmissing-field-initializers \
14+
-Wmissing-format-attribute \
15+
-Wno-implicit-fallthrough \
16+
-Wno-missing-field-initializers \
17+
-Wno-sign-compare \
18+
-Wno-unused-but-set-variable \
19+
-Wno-unused-parameter \
20+
-Wno-variadic-macros \
21+
-Wparentheses \
22+
-Wpointer-arith \
23+
-Wshadow \
24+
-Wsizeof-array-argument \
25+
-Wwrite-strings \
26+
-fdiagnostics-show-option \
27+
-fno-exceptions \
28+
-fno-omit-frame-pointer \
29+
-fno-optimize-sibling-calls \
30+
-fsanitize=address \
31+
-fsanitize=undefined \
32+
-fstack-protector \
33+
-pedantic \
534
-DHAVE_STDINT_H -DHAVE_GETTIMEOFDAY -DHAVE_UNISTD_H -DHAVE_DIRENT_H -I.# -DDEBUG_PARSER
635

736
CFLAGS=-Wdeclaration-after-statement ${FLAGS}

docs/date-from-iso-parts.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ timelib_tzinfo *cached_tzfile_wrapper(const char *tz_id, const timelib_tzdb *db,
6161
return timelib_parse_tzfile(tz_id, global.db, error);
6262
}
6363

64-
timelib_tzinfo *cached_fetch_tzinfo(char *tz_id)
64+
timelib_tzinfo *cached_fetch_tzinfo(const char *tz_id)
6565
{
6666
int dummy_error;
6767

@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
7777
timelib_sll ti = 50;
7878
timelib_sll ts = 58;
7979
timelib_sll tus = 48 * 1000;
80-
char *tz_id = "America/New_York";
80+
const char *tz_id = "America/New_York";
8181
timelib_time *t;
8282
timelib_tzinfo *tzi;
8383

docs/date-from-parts.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ timelib_tzinfo *cached_tzfile_wrapper(const char *tz_id, const timelib_tzdb *db,
6161
return timelib_parse_tzfile(tz_id, global.db, error);
6262
}
6363

64-
timelib_tzinfo *cached_fetch_tzinfo(char *tz_id)
64+
timelib_tzinfo *cached_fetch_tzinfo(const char *tz_id)
6565
{
6666
int dummy_error;
6767

@@ -77,7 +77,7 @@ int main(void)
7777
timelib_sll ti = 50;
7878
timelib_sll ts = 58;
7979
timelib_sll tus = 713 * 1000;
80-
char *tz_id = "America/New_York";
80+
const char *tz_id = "America/New_York";
8181
timelib_time *t;
8282
timelib_tzinfo *tzi;
8383

docs/date-from-string.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ timelib_tzinfo *cached_tzfile_wrapper(const char *tz_id, const timelib_tzdb *db,
6363
return timelib_parse_tzfile(tz_id, global.db, error);
6464
}
6565

66-
timelib_tzinfo *cached_fetch_tzinfo(char *tz_id)
66+
timelib_tzinfo *cached_fetch_tzinfo(const char *tz_id)
6767
{
6868
int dummy_error;
6969

@@ -73,7 +73,7 @@ timelib_tzinfo *cached_fetch_tzinfo(char *tz_id)
7373
int main(int argc, char *argv[])
7474
{
7575
char *time_string = NULL;
76-
char *tz_id = NULL;
76+
const char *tz_id = NULL;
7777
timelib_time *t;
7878
#if defined(PARTIAL)
7979
timelib_time *t_now;

docs/date-to-parts.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ timelib_tzinfo *cached_tzfile_wrapper(const char *tz_id, const timelib_tzdb *db,
6161
return timelib_parse_tzfile(tz_id, global.db, error);
6262
}
6363

64-
timelib_tzinfo *cached_fetch_tzinfo(char *tz_id)
64+
timelib_tzinfo *cached_fetch_tzinfo(const char *tz_id)
6565
{
6666
int dummy_error;
6767

@@ -70,8 +70,8 @@ timelib_tzinfo *cached_fetch_tzinfo(char *tz_id)
7070

7171
int main(void)
7272
{
73-
char *dt_string = "2017-06-05T11:30:09.123Z";
74-
char *tz_id = "Europe/London";
73+
const char *dt_string = "2017-06-05T11:30:09.123Z";
74+
const char *tz_id = "Europe/London";
7575
timelib_time *t;
7676
timelib_tzinfo *tzi;
7777
timelib_error_container *errors;

parse_date.re

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static timelib_error_message *alloc_error_message(timelib_error_message **messag
360360
return *messages + (*count)++;
361361
}
362362

363-
static void add_warning(Scanner *s, int error_code, char *error)
363+
static void add_warning(Scanner *s, int error_code, const char *error)
364364
{
365365
timelib_error_message *message = alloc_error_message(&s->errors->warning_messages, &s->errors->warning_count);
366366

@@ -370,7 +370,7 @@ static void add_warning(Scanner *s, int error_code, char *error)
370370
message->message = timelib_strdup(error);
371371
}
372372

373-
static void add_error(Scanner *s, int error_code, char *error)
373+
static void add_error(Scanner *s, int error_code, const char *error)
374374
{
375375
timelib_error_message *message = alloc_error_message(&s->errors->error_messages, &s->errors->error_count);
376376

@@ -380,7 +380,7 @@ static void add_error(Scanner *s, int error_code, char *error)
380380
message->message = timelib_strdup(error);
381381
}
382382

383-
static void add_pbf_warning(Scanner *s, int error_code, char *error, const char *sptr, const char *cptr)
383+
static void add_pbf_warning(Scanner *s, int error_code, const char *error, const char *sptr, const char *cptr)
384384
{
385385
timelib_error_message *message = alloc_error_message(&s->errors->warning_messages, &s->errors->warning_count);
386386

@@ -390,7 +390,7 @@ static void add_pbf_warning(Scanner *s, int error_code, char *error, const char
390390
message->message = timelib_strdup(error);
391391
}
392392

393-
static void add_pbf_error(Scanner *s, int error_code, char *error, const char *sptr, const char *cptr)
393+
static void add_pbf_error(Scanner *s, int error_code, const char *error, const char *sptr, const char *cptr)
394394
{
395395
timelib_error_message *message = alloc_error_message(&s->errors->error_messages, &s->errors->error_count);
396396

@@ -2632,7 +2632,7 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options)
26322632
*/
26332633
}
26342634

2635-
char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst)
2635+
const char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst)
26362636
{
26372637
const timelib_tz_lookup_table *tp;
26382638

parse_iso_intervals.re

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ typedef struct _Scanner {
8686
int have_end_date;
8787
} Scanner;
8888

89-
static void add_error(Scanner *s, char *error)
89+
static void add_error(Scanner *s, const char *error)
9090
{
9191
s->errors->error_count++;
9292
s->errors->error_messages = timelib_realloc(s->errors->error_messages, s->errors->error_count * sizeof(timelib_error_message));

tests/test-abbr-to-id.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
int main(void)
2828
{
29-
char *id;
29+
const char *id;
3030

3131
id = timelib_timezone_id_from_abbr("cest", 10800, 1); printf("%s\n", id);
3232
id = timelib_timezone_id_from_abbr("cest", 7200, 1); printf("%s\n", id);

timelib.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,10 @@ typedef struct _timelib_error_container {
342342
} timelib_error_container;
343343

344344
typedef struct _timelib_tz_lookup_table {
345-
char *name;
345+
const char *name;
346346
int type;
347347
float gmtoffset;
348-
char *full_tz_name;
348+
const char *full_tz_name;
349349
} timelib_tz_lookup_table;
350350

351351
typedef struct _timelib_tzdb_index_entry {
@@ -354,7 +354,7 @@ typedef struct _timelib_tzdb_index_entry {
354354
} timelib_tzdb_index_entry;
355355

356356
typedef struct _timelib_tzdb {
357-
char *version;
357+
const char *version;
358358
int index_size;
359359
const timelib_tzdb_index_entry *index;
360360
const unsigned char *data;
@@ -583,7 +583,7 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options);
583583
*
584584
* The returned char* is not duplicated, and should not be freed.
585585
*/
586-
char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst);
586+
const char *timelib_timezone_id_from_abbr(const char *abbr, timelib_long gmtoffset, int isdst);
587587

588588
/* Returns an array of known time zone abbreviations
589589
*

0 commit comments

Comments
 (0)