summaryrefslogtreecommitdiff
path: root/src/udev/udev-rules.c
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2014-03-15 11:40:07 -0700
committerAnthony G. Basile <blueness@gentoo.org>2014-03-17 12:01:15 -0400
commit7b85b243b26a03744d297b4945d31131eb48e05c (patch)
tree728c9d76cb352a3a944fa00beeec774c7c35d8dd /src/udev/udev-rules.c
parentdf97ff74562db71879cd83bb73eba9ff7dde7a7b (diff)
Use strlen even for constant strings
GCC optimizes strlen("string constant") to a constant, even with -O0. Thus, replace patterns like sizeof("string constant")-1 with strlen("string constant") where possible, for clarity. In particular, for expressions intended to add up the lengths of components going into a string, this often makes it clearer that the expression counts the trailing '\0' exactly once, by putting the +1 for the '\0' at the end of the expression, rather than hidden in a sizeof in the middle of the expression.
Diffstat (limited to 'src/udev/udev-rules.c')
-rw-r--r--src/udev/udev-rules.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index 3adbc7a7ed..d581c58faa 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -1147,7 +1147,7 @@ static int add_rule(struct udev_rules *rules, char *line,
}
if (startswith(key, "ATTR{")) {
- attr = get_key_attribute(rules->udev, key + sizeof("ATTR")-1);
+ attr = get_key_attribute(rules->udev, key + strlen("ATTR"));
if (attr == NULL) {
log_error("error parsing ATTR attribute");
goto invalid;
@@ -1161,7 +1161,7 @@ static int add_rule(struct udev_rules *rules, char *line,
}
if (startswith(key, "SECLABEL{")) {
- attr = get_key_attribute(rules->udev, key + sizeof("SECLABEL")-1);
+ attr = get_key_attribute(rules->udev, key + strlen("SECLABEL"));
if (!attr) {
log_error("error parsing SECLABEL attribute");
goto invalid;
@@ -1203,7 +1203,7 @@ static int add_rule(struct udev_rules *rules, char *line,
log_error("invalid ATTRS operation");
goto invalid;
}
- attr = get_key_attribute(rules->udev, key + sizeof("ATTRS")-1);
+ attr = get_key_attribute(rules->udev, key + strlen("ATTRS"));
if (attr == NULL) {
log_error("error parsing ATTRS attribute");
goto invalid;
@@ -1228,7 +1228,7 @@ static int add_rule(struct udev_rules *rules, char *line,
}
if (startswith(key, "ENV{")) {
- attr = get_key_attribute(rules->udev, key + sizeof("ENV")-1);
+ attr = get_key_attribute(rules->udev, key + strlen("ENV"));
if (attr == NULL) {
log_error("error parsing ENV attribute");
goto invalid;
@@ -1287,7 +1287,7 @@ static int add_rule(struct udev_rules *rules, char *line,
}
if (startswith(key, "IMPORT")) {
- attr = get_key_attribute(rules->udev, key + sizeof("IMPORT")-1);
+ attr = get_key_attribute(rules->udev, key + strlen("IMPORT"));
if (attr == NULL) {
log_error("IMPORT{} type missing, ignoring IMPORT %s:%u", filename, lineno);
continue;
@@ -1333,7 +1333,7 @@ static int add_rule(struct udev_rules *rules, char *line,
log_error("invalid TEST operation");
goto invalid;
}
- attr = get_key_attribute(rules->udev, key + sizeof("TEST")-1);
+ attr = get_key_attribute(rules->udev, key + strlen("TEST"));
if (attr != NULL) {
mode = strtol(attr, NULL, 8);
rule_add_key(&rule_tmp, TK_M_TEST, op, value, &mode);
@@ -1344,7 +1344,7 @@ static int add_rule(struct udev_rules *rules, char *line,
}
if (startswith(key, "RUN")) {
- attr = get_key_attribute(rules->udev, key + sizeof("RUN")-1);
+ attr = get_key_attribute(rules->udev, key + strlen("RUN"));
if (attr == NULL)
attr = "program";