1
0
Pārlūkot izejas kodu

faux: Style for int retval checking

Serj Kalichev 4 gadi atpakaļ
vecāks
revīzija
ca952145ce
3 mainītis faili ar 28 papildinājumiem un 26 dzēšanām
  1. 3 1
      faux/list/list.c
  2. 20 20
      faux/log/log.c
  3. 5 5
      faux/sysdb/sysdb.c

+ 3 - 1
faux/list/list.c

@@ -110,6 +110,7 @@ faux_list_node_t *faux_list_each_node(faux_list_node_t **iter) {
 
 	faux_list_node_t *current_node = *iter;
 
+	// No assert() on current_node. NULL iterator is normal
 	if (!current_node)
 		return NULL;
 	*iter = faux_list_next_node(current_node);
@@ -130,6 +131,7 @@ void *faux_list_each(faux_list_node_t **iter) {
 
 	faux_list_node_t *current_node = NULL;
 
+	// No assert() on current_node. NULL iterator is normal
 	if (!*iter)
 		return NULL;
 	current_node = faux_list_each_node(iter);
@@ -289,7 +291,7 @@ static faux_list_node_t *faux_list_add_generic(faux_list_t *list, void *data,
 	while (iter) {
 		int res = list->compareFn(node->data, iter->data);
 
-		if (uniq && (res == 0)) {
+		if (uniq && (0 == res)) {
 			faux_list_free_node(node);
 			return (find ? iter : NULL);
 		}

+ 20 - 20
faux/log/log.c

@@ -23,49 +23,49 @@
  */
 int faux_log_facility(const char *str, int *facility) {
 
-	if (!faux_str_casecmp(str, "local0"))
+	if (faux_str_casecmp(str, "local0") == 0)
 		*facility = LOG_LOCAL0;
-	else if (!faux_str_casecmp(str, "local1"))
+	else if (faux_str_casecmp(str, "local1") == 0)
 		*facility = LOG_LOCAL1;
-	else if (!faux_str_casecmp(str, "local2"))
+	else if (faux_str_casecmp(str, "local2") == 0)
 		*facility = LOG_LOCAL2;
-	else if (!faux_str_casecmp(str, "local3"))
+	else if (faux_str_casecmp(str, "local3") == 0)
 		*facility = LOG_LOCAL3;
-	else if (!faux_str_casecmp(str, "local4"))
+	else if (faux_str_casecmp(str, "local4") == 0)
 		*facility = LOG_LOCAL4;
-	else if (!faux_str_casecmp(str, "local5"))
+	else if (faux_str_casecmp(str, "local5") == 0)
 		*facility = LOG_LOCAL5;
-	else if (!faux_str_casecmp(str, "local6"))
+	else if (faux_str_casecmp(str, "local6") == 0)
 		*facility = LOG_LOCAL6;
-	else if (!faux_str_casecmp(str, "local7"))
+	else if (faux_str_casecmp(str, "local7") == 0)
 		*facility = LOG_LOCAL7;
-	else if (!faux_str_casecmp(str, "auth"))
+	else if (faux_str_casecmp(str, "auth") == 0)
 		*facility = LOG_AUTH;
 #ifdef LOG_AUTHPRIV
-	else if (!faux_str_casecmp(str, "authpriv"))
+	else if (faux_str_casecmp(str, "authpriv") == 0)
 		*facility = LOG_AUTHPRIV;
 #endif
-	else if (!faux_str_casecmp(str, "cron"))
+	else if (faux_str_casecmp(str, "cron") == 0)
 		*facility = LOG_CRON;
-	else if (!faux_str_casecmp(str, "daemon"))
+	else if (faux_str_casecmp(str, "daemon") == 0)
 		*facility = LOG_DAEMON;
 #ifdef LOG_FTP
-	else if (!faux_str_casecmp(str, "ftp"))
+	else if (faux_str_casecmp(str, "ftp") == 0)
 		*facility = LOG_FTP;
 #endif
-	else if (!faux_str_casecmp(str, "kern"))
+	else if (faux_str_casecmp(str, "kern") == 0)
 		*facility = LOG_KERN;
-	else if (!faux_str_casecmp(str, "lpr"))
+	else if (faux_str_casecmp(str, "lpr") == 0)
 		*facility = LOG_LPR;
-	else if (!faux_str_casecmp(str, "mail"))
+	else if (faux_str_casecmp(str, "mail") == 0)
 		*facility = LOG_MAIL;
-	else if (!faux_str_casecmp(str, "news"))
+	else if (faux_str_casecmp(str, "news") == 0)
 		*facility = LOG_NEWS;
-	else if (!faux_str_casecmp(str, "syslog"))
+	else if (faux_str_casecmp(str, "syslog") == 0)
 		*facility = LOG_SYSLOG;
-	else if (!faux_str_casecmp(str, "user"))
+	else if (faux_str_casecmp(str, "user") == 0)
 		*facility = LOG_USER;
-	else if (!faux_str_casecmp(str, "uucp"))
+	else if (faux_str_casecmp(str, "uucp") == 0)
 		*facility = LOG_UUCP;
 	else
 		return -1;

+ 5 - 5
faux/sysdb/sysdb.c

@@ -47,9 +47,9 @@ struct passwd *faux_sysdb_getpwnam(const char *name) {
 	buf = (char *)pwbuf + sizeof(*pwbuf);
 
 	res = getpwnam_r(name, pwbuf, buf, size, &pw);
-	if (res || !pw) {
+	if ((res != 0) || !pw) {
 		faux_free(pwbuf);
-		if (res)
+		if (res != 0)
 			errno = res;
 		else
 			errno = ENOENT;
@@ -89,7 +89,7 @@ struct passwd *faux_sysdb_getpwuid(uid_t uid) {
 	res = getpwuid_r(uid, pwbuf, buf, size, &pw);
 	if (!pw) {
 		faux_free(pwbuf);
-		if (res)
+		if (res != 0)
 			errno = res;
 		else
 			errno = ENOENT;
@@ -129,7 +129,7 @@ struct group *faux_sysdb_getgrnam(const char *name) {
 	res = getgrnam_r(name, grbuf, buf, size, &gr);
 	if (!gr) {
 		faux_free(grbuf);
-		if (res)
+		if (res != 0)
 			errno = res;
 		else
 			errno = ENOENT;
@@ -169,7 +169,7 @@ struct group *faux_sysdb_getgrgid(gid_t gid) {
 	res = getgrgid_r(gid, grbuf, buf, size, &gr);
 	if (!gr) {
 		faux_free(grbuf);
-		if (res)
+		if (res != 0)
 			errno = res;
 		else
 			errno = ENOENT;