[PATCH alsa-lib 4/4] ucm: parser: Fix snprintf usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There is no need to manually 0 terminate the buffer with snprintf,
only strncpy has the very unfortunate behavior of not guaranteeing 0
termination.

Likewise there is no need to substract one from the buffer size of
the buffer passed to snprintf.

Signed-off-by: Hans de Goede <hdegoede@xxxxxxxxxx>
---
 src/ucm/parser.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/ucm/parser.c b/src/ucm/parser.c
index 319e3c1a..305d36c5 100644
--- a/src/ucm/parser.c
+++ b/src/ucm/parser.c
@@ -71,7 +71,6 @@ static void configuration_filename2(char *fn, size_t fn_len, int format,
 	snprintf(fn, fn_len, "%s/ucm%s/%s/%s%s",
 		 snd_config_topdir(), format >= 2 ? "2" : "",
 		 dir, file, suffix);
-	fn[fn_len-1] = '\0';
 }
 
 static void configuration_filename(snd_use_case_mgr_t *uc_mgr,
@@ -96,7 +95,6 @@ static void configuration_filename(snd_use_case_mgr_t *uc_mgr,
 	}
 	if (env) {
 		snprintf(fn, fn_len, "%s/%s/%s%s", env, dir, file, suffix);
-		fn[fn_len-1] = '\0';
 		return;
 	}
 
@@ -1712,11 +1710,10 @@ int uc_mgr_scan_master_configs(const char **_list[])
 	struct dirent **namelist;
 
 	if (env)
-		snprintf(filename, sizeof(filename)-1, "%s", env);
+		snprintf(filename, sizeof(filename), "%s", env);
 	else
-		snprintf(filename, sizeof(filename)-1, "%s/ucm2",
+		snprintf(filename, sizeof(filename), "%s/ucm2",
 			 snd_config_topdir());
-	filename[sizeof(filename)-1] = '\0';
 
 #if defined(_GNU_SOURCE) && !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__sun) && !defined(ANDROID)
 #define SORTFUNC	versionsort
-- 
2.23.0

_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel



[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux