Skip to contentSkip to conversation

cyclictest: Fix compiler warning about srncpy output truncated

PATCH New John Kacur 1 participant 2 messages Mar 11, 2019

lore
Share & tools
lore

John Kacur

author
#0 lore raw

PATCH 1/2 cyclictest: Fix compiler warning about srncpy output truncated

From: Clark Williams <[email protected]>

Fix compiler warning about strncpy output truncated before terminating nul copying as many bytes from a string as its length

Extracted from a patch from Clark

---
 src/cyclictest/cyclictest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/cyclictest/cyclictest.c +2 -2
index 68b3836405c1..1bd63fd93dce 100644
@@ -1257,7 +1257,7 @@ static void process_options (int argc, char *argv[], int max_cpus)
 		case 'F':
 		case OPT_FIFO:
 			use_fifo = 1;
-			strncpy(fifopath, optarg, strlen(optarg));
+			strncpy(fifopath, optarg, strnlen(optarg, MAX_PATH-1));
 			break;
 		case 'H':
 		case OPT_HISTOFALL:
@@ -1267,7 +1267,7 @@ static void process_options (int argc, char *argv[], int max_cpus)
 			histogram = atoi(optarg); break;
 		case OPT_HISTFILE:
 			use_histfile = 1;
-			strncpy(histfile, optarg, strlen(optarg));
+			strncpy(histfile, optarg, strnlen(optarg, MAX_PATH-1));
 			break;
 		case 'i':
 		case OPT_INTERVAL:
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH 2/2 cyclictest: Make sure affinity is respected when numa is detected

Make sure affinity is respected when numa is automatically detected and when smp is not specified. Don't break the way smp currently works.

---
 src/cyclictest/cyclictest.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
src/cyclictest/cyclictest.c +6 -7
index 1bd63fd93dce..ed59edefbf97 100644
@@ -1218,7 +1218,7 @@ static void process_options (int argc, char *argv[], int max_cpus)
 		case 'a':
 		case OPT_AFFINITY:
 			option_affinity = 1;
-			if (smp || numa)
+			if (smp)
 				break;
 			if (optarg != NULL) {
 				parse_cpumask(optarg, max_cpus);
@@ -1384,8 +1384,10 @@ static void process_options (int argc, char *argv[], int max_cpus)
 #ifdef NUMA
 		if (numa_available() != -1) {
 			numa = 1;
-			num_threads = max_cpus;
-			setaffinity = AFFINITY_USEALL;
+			if (setaffinity == AFFINITY_UNSPECIFIED) {
+				num_threads = max_cpus;
+				setaffinity = AFFINITY_USEALL;
+			}
 		}
 #else
 		warn("cyclictest was not built with the numa option\n");
@@ -1394,11 +1396,8 @@ static void process_options (int argc, char *argv[], int max_cpus)
 	}
 
 	if (option_affinity) {
-		if (smp) {
+		if (smp)
 			warn("-a ignored due to smp mode\n");
-		} else if (numa) {
-			warn("-a ignored due to numa mode\n");
-		}
 	}
 
 	if (smi) {
Signature · 1 line
2.20.1