commit 3b49ce26d9debcf435f7f1ed26ea6bdadbe24d5e
parent ce303420e58d25a62a4a55092f7fe2cae070bad2
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Wed, 17 Feb 2021 13:41:19 -0600
use macros for size limits
Diffstat:
3 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/kiss.c b/kiss.c
@@ -13,8 +13,8 @@ void
kiss_list_all()
{
DIR *db;
- char pkgs[1024][64];
- char ver[256];
+ char pkgs[PKG_COUNT_MAX][PKG_NAME_MAX];
+ char ver[PKG_VERSION_MAX];
if ((db = opendir(KISS_INSTALLED)) == NULL)
die("couldn't open package database:");
@@ -24,7 +24,7 @@ kiss_list_all()
if (pkg->d_type != DT_DIR || pkg->d_name[0] == '.')
continue;
- if (strlen(pkg->d_name) >= 64) {
+ if (strlen(pkg->d_name) >= PKG_NAME_MAX) {
closedir(db);
die("kiss_list: '%s' is too long of a package name", pkg->d_name);
}
@@ -32,7 +32,7 @@ kiss_list_all()
strcpy(pkgs[pkgcount], pkg->d_name);
pkgcount++;
- if (pkgcount > 1024) {
+ if (pkgcount > PKG_COUNT_MAX) {
closedir(db);
die("kiss_list: too many packages to list!");
}
@@ -49,7 +49,7 @@ kiss_list_all()
void
kiss_list_names(char *names[], int len)
{
- char ver[256];
+ char ver[PKG_VERSION_MAX];
for (; len > 0; names++, len--) {
pkg_version(KISS_INSTALLED, *names, ver);
@@ -60,7 +60,7 @@ kiss_list_names(char *names[], int len)
void
kiss_search(const char *kiss_path, char *pattern)
{
- char *repo, path[strlen(kiss_path)], pkgs[1024][64];
+ char *repo, path[strlen(kiss_path)], pkgs[PKG_COUNT_MAX][PKG_NAME_MAX];
int pkgcount;
memccpy(path, kiss_path, '\0', strlen(kiss_path));
@@ -71,7 +71,7 @@ kiss_search(const char *kiss_path, char *pattern)
/* iterate through KISS_PATH */
do {
/* clear pkgs array */
- for (int i = 0; i < 1024; i++)
+ for (int i = 0; i < PKG_COUNT_MAX; i++)
pkgs[i][0] = '\0';
pkgcount = pkg_match(repo, pkgs, pattern);
@@ -82,7 +82,7 @@ kiss_search(const char *kiss_path, char *pattern)
} while ((repo = strtok(NULL, ":")) != NULL);
repo = KISS_INSTALLED;
- for (int i = 0; i < 1024; i++)
+ for (int i = 0; i < PKG_COUNT_MAX; i++)
pkgs[i][0] = '\0';
pkgcount = pkg_match(repo, pkgs, pattern);
diff --git a/pkg.c b/pkg.c
@@ -30,7 +30,7 @@ pkg_version(char *repo, char *name, char *ver)
}
int
-pkg_match(char *repo, char pkgs[][64], const char *pattern)
+pkg_match(char *repo, char pkgs[][PKG_NAME_MAX], const char *pattern)
{
DIR *db;
int index = 0;
@@ -46,7 +46,7 @@ pkg_match(char *repo, char pkgs[][64], const char *pattern)
die("%s: fnmatch failed for '%s'", __func__, pkg->d_name);
}
- if (strlen(pkg->d_name) >= 64) {
+ if (strlen(pkg->d_name) >= PKG_NAME_MAX) {
closedir(db);
die("%s: '%s' is too long of a package name", __func__,
pkg->d_name);
@@ -54,7 +54,7 @@ pkg_match(char *repo, char pkgs[][64], const char *pattern)
strcpy(pkgs[index++], pkg->d_name);
- if (index > 1024) {
+ if (index > PKG_COUNT_MAX) {
closedir(db);
die("%s: too many packages to list!", __func__);
}
diff --git a/pkg.h b/pkg.h
@@ -1,5 +1,7 @@
#define KISS_INSTALLED "/var/db/kiss/installed"
#define PKG_VERSION_MAX 256
+#define PKG_COUNT_MAX 1024
+#define PKG_NAME_MAX 64
void pkg_version(char *repo, char *name, char *ver);
int pkg_match(char *repo, char pkgs[][64], const char *pattern);