[pacman-dev] [PATCH 2/2] Kill all remaining 'PATH_MAX + 1' usages

Dan McGee dan at archlinux.org
Thu Jun 9 15:13:42 EDT 2011


The few remaining instances were utilized for buffers in calls to
snprintf() and realpath(). Both of these functions will always ensure
the returned value is padded with '\0', so there is no need for the
extra byte.

Signed-off-by: Dan McGee <dan at archlinux.org>
---
 lib/libalpm/add.c      |    2 +-
 lib/libalpm/conflict.c |    6 +++---
 lib/libalpm/handle.c   |    2 +-
 lib/libalpm/remove.c   |    4 ++--
 src/pacman/query.c     |    2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 4ea6c34..4c9a98c 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -469,7 +469,7 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg,
 		size_t pkg_current, size_t pkg_count)
 {
 	int i, ret = 0, errors = 0;
-	char scriptlet[PATH_MAX+1];
+	char scriptlet[PATH_MAX];
 	int is_upgrade = 0;
 	pmpkg_t *oldpkg = NULL;
 	pmdb_t *db = handle->db_local;
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index b64604f..66441a7 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -377,7 +377,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle,
 	for(current = 0, i = upgrade; i; i = i->next, current++) {
 		alpm_list_t *k, *tmpfiles = NULL;
 		pmpkg_t *p1, *p2, *dbpkg;
-		char path[PATH_MAX+1];
+		char path[PATH_MAX];
 
 		p1 = i->data;
 		if(!p1) {
@@ -500,9 +500,9 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle,
 			}
 
 			if(!resolved_conflict && dbpkg) {
-				char *rpath = calloc(PATH_MAX+1, sizeof(char));
+				char *rpath = calloc(PATH_MAX, sizeof(char));
 				if(!realpath(path, rpath)) {
-					FREE(rpath);
+					free(rpath);
 					continue;
 				}
 				char *filestr = rpath + strlen(handle->root);
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index 898ce41..3c17e9d 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -264,7 +264,7 @@ enum _pmerrno_t _alpm_set_directory_option(const char *value,
 		if(stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
 			return PM_ERR_NOT_A_DIR;
 		}
-		real = calloc(PATH_MAX + 1, sizeof(char));
+		real = calloc(PATH_MAX, sizeof(char));
 		if(!realpath(path, real)) {
 			free(real);
 			return PM_ERR_NOT_A_DIR;
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index a0b6c41..f7ed68e 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -194,7 +194,7 @@ int _alpm_remove_prepare(pmhandle_t *handle, alpm_list_t **data)
 static int can_remove_file(pmhandle_t *handle, const char *path,
 		alpm_list_t *skip)
 {
-	char file[PATH_MAX+1];
+	char file[PATH_MAX];
 
 	snprintf(file, PATH_MAX, "%s%s", handle->root, path);
 
@@ -223,7 +223,7 @@ static void unlink_file(pmhandle_t *handle, pmpkg_t *info, char *filename,
 		alpm_list_t *skip_remove, int nosave)
 {
 	struct stat buf;
-	char file[PATH_MAX+1];
+	char file[PATH_MAX];
 
 	snprintf(file, PATH_MAX, "%s%s", handle->root, filename);
 
diff --git a/src/pacman/query.c b/src/pacman/query.c
index 938fff6..eb34071 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -40,7 +40,7 @@ static char *resolve_path(const char *file)
 {
 	char *str = NULL;
 
-	str = calloc(PATH_MAX + 1, sizeof(char));
+	str = calloc(PATH_MAX, sizeof(char));
 	if(!str) {
 		return NULL;
 	}
-- 
1.7.5.2



More information about the pacman-dev mailing list