Skip to content

Commit

Permalink
Bug cmus#177: Clean-up of reserved identifier violations
Browse files Browse the repository at this point in the history
Some identifiers did not fit to the expected naming convention of the
C language standard.
https://www.securecoding.cert.org/confluence/display/seccode/DCL37-C.+Do+not+declare+or+define+a+reserved+identifier

This detail was fixed by the deletion of leading underscores.

Signed-off-by: Markus Elfring <[email protected]>
  • Loading branch information
elfring authored and flyingmutant committed Sep 5, 2014
1 parent aacf178 commit 06fe149
Show file tree
Hide file tree
Showing 23 changed files with 247 additions and 247 deletions.
10 changes: 5 additions & 5 deletions Doc/ttman.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ static const struct {
#define BUG() die("BUG in %s\n", __FUNCTION__)

#ifdef __GNUC__
#define __NORETURN __attribute__((__noreturn__))
#define CMUS_NORETURN __attribute__((__noreturn__))
#else
#define __NORETURN
#define CMUS_NORETURN
#endif

static __NORETURN void quit(void)
static CMUS_NORETURN void quit(void)
{
if (tmp_file[0])
unlink(tmp_file);
exit(1);
}

static __NORETURN void die(const char *format, ...)
static CMUS_NORETURN void die(const char *format, ...)
{
va_list ap;

Expand All @@ -102,7 +102,7 @@ static __NORETURN void die(const char *format, ...)
quit();
}

static __NORETURN void syntax(int line, const char *format, ...)
static CMUS_NORETURN void syntax(int line, const char *format, ...)
{
va_list ap;

Expand Down
4 changes: 2 additions & 2 deletions cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct cache_entry {
int32_t bitrate;

// when introducing new fields decrease the reserved space accordingly
uint8_t __reserved[CACHE_ENTRY_RESERVED_SIZE];
uint8_t _reserved[CACHE_ENTRY_RESERVED_SIZE];

// filename, codec, codec_profile and N * (key, val)
char strings[];
Expand Down Expand Up @@ -319,7 +319,7 @@ static void write_ti(int fd, struct gbuf *buf, struct track_info *ti, unsigned i
struct cache_entry e;
int *len, alloc = 64, count, i;

memset(e.__reserved, CACHE_RESERVED_PATTERN, sizeof(e.__reserved));
memset(e._reserved, CACHE_RESERVED_PATTERN, sizeof(e._reserved));

count = 0;
len = xnew(int, alloc);
Expand Down
16 changes: 8 additions & 8 deletions command_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1024,16 +1024,16 @@ static void cmd_run(char *arg)
editable_lock();
switch (cur_view) {
case TREE_VIEW:
__tree_for_each_sel(add_ti, &sel, 0);
_tree_for_each_sel(add_ti, &sel, 0);
break;
case SORTED_VIEW:
__editable_for_each_sel(&lib_editable, add_ti, &sel, 0);
_editable_for_each_sel(&lib_editable, add_ti, &sel, 0);
break;
case PLAYLIST_VIEW:
__editable_for_each_sel(&pl_editable, add_ti, &sel, 0);
_editable_for_each_sel(&pl_editable, add_ti, &sel, 0);
break;
case QUEUE_VIEW:
__editable_for_each_sel(&pq_editable, add_ti, &sel, 0);
_editable_for_each_sel(&pq_editable, add_ti, &sel, 0);
break;
}
editable_unlock();
Expand Down Expand Up @@ -1162,16 +1162,16 @@ static void cmd_echo(char *arg)
editable_lock();
switch (cur_view) {
case TREE_VIEW:
__tree_for_each_sel(get_one_ti, &sel_ti, 0);
_tree_for_each_sel(get_one_ti, &sel_ti, 0);
break;
case SORTED_VIEW:
__editable_for_each_sel(&lib_editable, get_one_ti, &sel_ti, 0);
_editable_for_each_sel(&lib_editable, get_one_ti, &sel_ti, 0);
break;
case PLAYLIST_VIEW:
__editable_for_each_sel(&pl_editable, get_one_ti, &sel_ti, 0);
_editable_for_each_sel(&pl_editable, get_one_ti, &sel_ti, 0);
break;
case QUEUE_VIEW:
__editable_for_each_sel(&pq_editable, get_one_ti, &sel_ti, 0);
_editable_for_each_sel(&pq_editable, get_one_ti, &sel_ti, 0);
break;
}
editable_unlock();
Expand Down
12 changes: 6 additions & 6 deletions compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@
#endif

/* Optimization: Function never returns */
#define __NORETURN __attribute__((__noreturn__))
#define CMUS_NORETURN __attribute__((__noreturn__))

/* Argument at index @fmt_idx is printf compatible format string and
* argument at index @first_idx is the first format argument */
#define __FORMAT(fmt_idx, first_idx) __attribute__((format(printf, (fmt_idx), (first_idx))))
#define CMUS_FORMAT(fmt_idx, first_idx) __attribute__((format(printf, (fmt_idx), (first_idx))))

#if defined(__GNUC__) && (__GNUC__ >= 3)

/* Optimization: Pointer returned can't alias other pointers */
#define __MALLOC __attribute__((__malloc__))
#define CMUS_MALLOC __attribute__((__malloc__))

#else

#define __MALLOC
#define CMUS_MALLOC

#endif

Expand All @@ -81,8 +81,8 @@
#undef container_of
#if defined(__GNUC__)
#define container_of(ptr, type, member) __extension__ ({ \
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
container_of_portable(__mptr, type, member);})
const __typeof__( ((type *)0)->member ) *_mptr = (ptr); \
container_of_portable(_mptr, type, member);})
#else
#define container_of(ptr, type, member) container_of_portable(ptr, type, member)
#endif
Expand Down
14 changes: 7 additions & 7 deletions cue.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct cue_private {
};


static int __parse_cue_url(const char *url, char **filename, int *track_n)
static int _parse_cue_url(const char *url, char **filename, int *track_n)
{
const char *slash;
long n;
Expand All @@ -63,15 +63,15 @@ static int __parse_cue_url(const char *url, char **filename, int *track_n)
}


static double __to_seconds(long v)
static double _to_seconds(long v)
{
const int FRAMES_IN_SECOND = 75;

return (double)v / FRAMES_IN_SECOND;
}


static char *__make_absolute_path(const char *abs_filename, const char *rel_filename)
static char *_make_absolute_path(const char *abs_filename, const char *rel_filename)
{
char *s;
const char *slash;
Expand Down Expand Up @@ -100,7 +100,7 @@ static int cue_open(struct input_plugin_data *ip_data)

priv = xnew(struct cue_private, 1);

rc = __parse_cue_url(ip_data->filename, &priv->cue_filename, &priv->track_n);
rc = _parse_cue_url(ip_data->filename, &priv->cue_filename, &priv->track_n);
if (rc) {
rc = -IP_ERROR_INVALID_URI;
goto url_parse_failed;
Expand Down Expand Up @@ -129,7 +129,7 @@ static int cue_open(struct input_plugin_data *ip_data)
rc = -IP_ERROR_FILE_FORMAT;
goto cue_read_failed;
}
child_filename = __make_absolute_path(priv->cue_filename, child_filename);
child_filename = _make_absolute_path(priv->cue_filename, child_filename);

priv->child = ip_new(child_filename);
free(child_filename);
Expand All @@ -140,15 +140,15 @@ static int cue_open(struct input_plugin_data *ip_data)

ip_setup(priv->child);

priv->start_offset = __to_seconds(track_get_start(t));
priv->start_offset = _to_seconds(track_get_start(t));
priv->current_offset = priv->start_offset;

rc = ip_seek(priv->child, priv->start_offset);
if (rc)
goto ip_open_failed;

if (track_get_length(t) != 0)
priv->end_offset = priv->start_offset + __to_seconds(track_get_length(t));
priv->end_offset = priv->start_offset + _to_seconds(track_get_length(t));
else
priv->end_offset = ip_duration(priv->child);

Expand Down
6 changes: 3 additions & 3 deletions debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void debug_init(void)
/* This function must be defined even if debugging is disabled in the program
* because debugging might still be enabled in some plugin.
*/
void __debug_bug(const char *function, const char *fmt, ...)
void _debug_bug(const char *function, const char *fmt, ...)
{
const char *format = "\n%s: BUG: ";
va_list ap;
Expand All @@ -71,7 +71,7 @@ void __debug_bug(const char *function, const char *fmt, ...)
exit(127);
}

void __debug_print(const char *function, const char *fmt, ...)
void _debug_print(const char *function, const char *fmt, ...)
{
#if DEBUG > 1
va_list ap;
Expand Down Expand Up @@ -102,6 +102,6 @@ void timer_print(const char *what, uint64_t usec)
uint64_t a = usec / 1e6;
uint64_t b = usec - a * 1e6;

__debug_print("TIMER", "%s: %11u.%06u\n", what, (unsigned int)a, (unsigned int)b);
_debug_print("TIMER", "%s: %11u.%06u\n", what, (unsigned int)a, (unsigned int)b);
#endif
}
12 changes: 6 additions & 6 deletions debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@
#include <stdint.h>

void debug_init(void);
void __debug_bug(const char *function, const char *fmt, ...) __FORMAT(2, 3) __NORETURN;
void __debug_print(const char *function, const char *fmt, ...) __FORMAT(2, 3);
void _debug_bug(const char *function, const char *fmt, ...) CMUS_FORMAT(2, 3) CMUS_NORETURN;
void _debug_print(const char *function, const char *fmt, ...) CMUS_FORMAT(2, 3);

uint64_t timer_get(void);
void timer_print(const char *what, uint64_t usec);

#define BUG(...) __debug_bug(__FUNCTION__, __VA_ARGS__)
#define BUG(...) _debug_bug(__FUNCTION__, __VA_ARGS__)

#define __STR(a) #a
#define CMUS_STR(a) #a

#define BUG_ON(a) \
do { \
if (unlikely(a)) \
BUG("%s\n", __STR(a)); \
BUG("%s\n", CMUS_STR(a)); \
} while (0)

#define d_print(...) __debug_print(__FUNCTION__, __VA_ARGS__)
#define d_print(...) _debug_print(__FUNCTION__, __VA_ARGS__)

#endif
4 changes: 2 additions & 2 deletions editable.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void editable_invert_marks(struct editable *e)
e->win->changed = 1;
}

int __editable_for_each_sel(struct editable *e, int (*cb)(void *data, struct track_info *ti),
int _editable_for_each_sel(struct editable *e, int (*cb)(void *data, struct track_info *ti),
void *data, int reverse)
{
int rc = 0;
Expand All @@ -375,7 +375,7 @@ int editable_for_each_sel(struct editable *e, int (*cb)(void *data, struct track
{
int rc;

rc = __editable_for_each_sel(e, cb, data, reverse);
rc = _editable_for_each_sel(e, cb, data, reverse);
if (e->nr_marked == 0)
window_down(e->win, 1);
return rc;
Expand Down
2 changes: 1 addition & 1 deletion editable.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void editable_remove_matching_tracks(struct editable *e,
void editable_mark(struct editable *e, const char *filter);
void editable_unmark(struct editable *e);
void editable_invert_marks(struct editable *e);
int __editable_for_each_sel(struct editable *e, int (*cb)(void *data, struct track_info *ti),
int _editable_for_each_sel(struct editable *e, int (*cb)(void *data, struct track_info *ti),
void *data, int reverse);
int editable_for_each_sel(struct editable *e, int (*cb)(void *data, struct track_info *ti),
void *data, int reverse);
Expand Down
2 changes: 1 addition & 1 deletion gbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void gbuf_free(struct gbuf *buf);
void gbuf_add_ch(struct gbuf *buf, char ch);
void gbuf_add_bytes(struct gbuf *buf, const void *data, size_t len);
void gbuf_add_str(struct gbuf *buf, const char *str);
void gbuf_addf(struct gbuf *buf, const char *fmt, ...) __FORMAT(2, 3);
void gbuf_addf(struct gbuf *buf, const char *fmt, ...) CMUS_FORMAT(2, 3);
void gbuf_set(struct gbuf *buf, int c, size_t count);
char *gbuf_steal(struct gbuf *buf);

Expand Down
2 changes: 1 addition & 1 deletion lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void tree_sel_current(void);
void tree_sel_first(void);
void tree_sel_track(struct tree_track *t);
int tree_for_each_sel(int (*cb)(void *data, struct track_info *ti), void *data, int reverse);
int __tree_for_each_sel(int (*cb)(void *data, struct track_info *ti), void *data, int reverse);
int _tree_for_each_sel(int (*cb)(void *data, struct track_info *ti), void *data, int reverse);

struct track_info *sorted_activate_selected(void);
void sorted_sel_current(void);
Expand Down
Loading

0 comments on commit 06fe149

Please sign in to comment.