summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-08-01 14:15:44 +0200
committerThomas Haller <thaller@redhat.com>2015-08-04 11:21:56 +0200
commit655b85bfea2c8e4594c6da304c844da64c0faa4d (patch)
tree64dff07a70d1e6e4f0067af2cc27f6914e9fee78
parentd3b91eb258ff7b95e7f7604d565268fa76cdb12c (diff)
downloadNetworkManager-655b85bfea2c8e4594c6da304c844da64c0faa4d.tar.gz
logging: replace using _LOGL_N by G_N_ELEMENTS()
At various places we used _LOGL_N to check the index before accessing one of our static arrays. Instead use G_N_ELEMENTS().
-rw-r--r--src/nm-logging.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/nm-logging.c b/src/nm-logging.c
index 82e672bb10..a98972caa4 100644
--- a/src/nm-logging.c
+++ b/src/nm-logging.c
@@ -149,7 +149,7 @@ match_log_level (const char *level,
{
int i;
- for (i = 0; i < _LOGL_N; i++) {
+ for (i = 0; i < G_N_ELEMENTS (level_desc); i++) {
if (!g_ascii_strcasecmp (level_desc[i].name, level)) {
*out_level = i;
return TRUE;
@@ -168,7 +168,7 @@ nm_logging_setup (const char *level,
GError **error)
{
GString *unrecognized = NULL;
- NMLogDomain new_logging[_LOGL_N];
+ NMLogDomain new_logging[G_N_ELEMENTS (logging)];
NMLogLevel new_log_level = log_level;
char **tmp, **iter;
int i;
@@ -178,7 +178,7 @@ nm_logging_setup (const char *level,
logging_set_up = TRUE;
- for (i = 0; i < _LOGL_N; i++)
+ for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
new_logging[i] = 0;
/* levels */
@@ -268,7 +268,7 @@ nm_logging_setup (const char *level,
g_clear_pointer (&logging_domains_to_string, g_free);
log_level = new_log_level;
- for (i = 0; i < _LOGL_N; i++)
+ for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
logging[i] = new_logging[i];
if (unrecognized)
@@ -292,7 +292,7 @@ nm_logging_all_levels_to_string (void)
int i;
str = g_string_new (NULL);
- for (i = 0; i < _LOGL_N; i++) {
+ for (i = 0; i < G_N_ELEMENTS (level_desc); i++) {
if (str->len)
g_string_append_c (str, ',');
g_string_append (str, level_desc[i].name);
@@ -335,7 +335,7 @@ nm_logging_domains_to_string (void)
}
/* Check if it's logging at a higher level than the default. */
if (!(diter->num & logging[log_level])) {
- for (i = log_level + 1; i < _LOGL_N; i++) {
+ for (i = log_level + 1; i < G_N_ELEMENTS (logging); i++) {
if (diter->num & logging[i]) {
g_string_append_printf (str, ":%s", level_desc[i].name);
break;
@@ -374,7 +374,8 @@ nm_logging_all_domains_to_string (void)
gboolean
nm_logging_enabled (NMLogLevel level, NMLogDomain domain)
{
- g_return_val_if_fail (level < _LOGL_N, FALSE);
+ if ((guint) level >= G_N_ELEMENTS (logging))
+ g_return_val_if_reached (FALSE);
_ensure_initialized ();
@@ -423,7 +424,7 @@ _nm_log_impl (const char *file,
char *fullmsg = NULL;
GTimeVal tv;
- if ((guint) level >= _LOGL_N)
+ if ((guint) level >= G_N_ELEMENTS (logging))
g_return_if_reached ();
_ensure_initialized ();