Просмотр исходного кода

Solaris requires asprintf checks for null variables

git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@709 f882894a-f735-0410-b71e-b25c423dba1c
Ton Voon 22 лет назад
Родитель
Сommit
e36840962a
1 измененных файлов с 11 добавлено и 11 удалено
  1. 11 11
      plugins/check_procs.c

+ 11 - 11
plugins/check_procs.c

@@ -259,8 +259,8 @@ main (int argc, char **argv)
 		}
 		}
 	} 
 	} 
 	
 	
-	if (fmt != "") {
-		printf (" with %s", fmt);
+	if (strcmp(fmt,"") != 0) {
+		printf (_(" with %s"), fmt);
 	}
 	}
 
 
 	if ( verbose >= 1 && fails != "" )
 	if ( verbose >= 1 && fails != "" )
@@ -354,7 +354,7 @@ process_arguments (int argc, char **argv)
 			break;
 			break;
 		case 'p':									/* process id */
 		case 'p':									/* process id */
 			if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) {
 			if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) {
-				asprintf (&fmt, "%s%sPPID = %d", fmt, (options ? ", " : ""), ppid);
+				asprintf (&fmt, "%s%sPPID = %d", (fmt ? fmt : "") , (options ? ", " : ""), ppid);
 				options |= PPID;
 				options |= PPID;
 				break;
 				break;
 			}
 			}
@@ -367,7 +367,7 @@ process_arguments (int argc, char **argv)
 				break;
 				break;
 			else
 			else
 				statopts = optarg;
 				statopts = optarg;
-			asprintf (&fmt, _("%s%sSTATE = %s"), fmt, (options ? ", " : ""), statopts);
+			asprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts);
 			options |= STAT;
 			options |= STAT;
 			break;
 			break;
 		case 'u':									/* user or user id */
 		case 'u':									/* user or user id */
@@ -393,7 +393,7 @@ process_arguments (int argc, char **argv)
 				uid = pw->pw_uid;
 				uid = pw->pw_uid;
 			}
 			}
 			user = pw->pw_name;
 			user = pw->pw_name;
-			asprintf (&fmt, _("%s%sUID = %d (%s)"), fmt, (options ? ", " : ""),
+			asprintf (&fmt, _("%s%sUID = %d (%s)"), (fmt ? fmt : ""), (options ? ", " : ""),
 			          uid, user);
 			          uid, user);
 			options |= USER;
 			options |= USER;
 			break;
 			break;
@@ -402,7 +402,7 @@ process_arguments (int argc, char **argv)
 				break;
 				break;
 			else
 			else
 				prog = optarg;
 				prog = optarg;
-			asprintf (&fmt, _("%s%scommand name '%s'"), fmt, (options ? ", " : ""),
+			asprintf (&fmt, _("%s%scommand name '%s'"), (fmt ? fmt : ""), (options ? ", " : ""),
 			          prog);
 			          prog);
 			options |= PROG;
 			options |= PROG;
 			break;
 			break;
@@ -411,12 +411,12 @@ process_arguments (int argc, char **argv)
 				break;
 				break;
 			else
 			else
 				args = optarg;
 				args = optarg;
-			asprintf (&fmt, _("%s%sargs '%s'"), fmt, (options ? ", " : ""), args);
+			asprintf (&fmt, _("%s%sargs '%s'"), (fmt ? fmt : ""), (options ? ", " : ""), args);
 			options |= ARGS;
 			options |= ARGS;
 			break;
 			break;
 		case 'r': 					/* RSS */
 		case 'r': 					/* RSS */
 			if (sscanf (optarg, "%d%[^0-9]", &rss, tmp) == 1) {
 			if (sscanf (optarg, "%d%[^0-9]", &rss, tmp) == 1) {
-				asprintf (&fmt, _("%s%sRSS >= %d"), fmt, (options ? ", " : ""), rss);
+				asprintf (&fmt, _("%s%sRSS >= %d"), (fmt ? fmt : ""), (options ? ", " : ""), rss);
 				options |= RSS;
 				options |= RSS;
 				break;
 				break;
 			}
 			}
@@ -426,7 +426,7 @@ process_arguments (int argc, char **argv)
 			exit (STATE_UNKNOWN);
 			exit (STATE_UNKNOWN);
 		case 'z':					/* VSZ */
 		case 'z':					/* VSZ */
 			if (sscanf (optarg, "%d%[^0-9]", &vsz, tmp) == 1) {
 			if (sscanf (optarg, "%d%[^0-9]", &vsz, tmp) == 1) {
-				asprintf (&fmt, _("%s%sVSZ >= %d"), fmt, (options ? ", " : ""), vsz);
+				asprintf (&fmt, _("%s%sVSZ >= %d"), (fmt ? fmt : ""), (options ? ", " : ""), vsz);
 				options |= VSZ;
 				options |= VSZ;
 				break;
 				break;
 			}
 			}
@@ -437,7 +437,7 @@ process_arguments (int argc, char **argv)
 		case 'P':					/* PCPU */
 		case 'P':					/* PCPU */
 			/* TODO: -P 1.5.5 is accepted */
 			/* TODO: -P 1.5.5 is accepted */
 			if (sscanf (optarg, "%f%[^0-9.]", &pcpu, tmp) == 1) {
 			if (sscanf (optarg, "%f%[^0-9.]", &pcpu, tmp) == 1) {
-				asprintf (&fmt, _("%s%sPCPU >= %.2f"), fmt, (options ? ", " : ""), pcpu);
+				asprintf (&fmt, _("%s%sPCPU >= %.2f"), (fmt ? fmt : ""), (options ? ", " : ""), pcpu);
 				options |= PCPU;
 				options |= PCPU;
 				break;
 				break;
 			}
 			}
@@ -480,7 +480,7 @@ process_arguments (int argc, char **argv)
 		cmax = atoi (argv[c++]);
 		cmax = atoi (argv[c++]);
 	if (statopts == NULL && argv[c]) {
 	if (statopts == NULL && argv[c]) {
 		asprintf (&statopts, "%s", argv[c++]);
 		asprintf (&statopts, "%s", argv[c++]);
-		asprintf (&fmt, _("%s%sSTATE = %s"), fmt, (options ? ", " : ""), statopts);
+		asprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts);
 		options |= STAT;
 		options |= STAT;
 	}
 	}