Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
cocci: fix NELEM vs nitems mix
Baptiste Daroussin committed 1 year ago
commit bf078b62964538356fdfa398a03791bf6c3d6cbd
parent 91b1b52
10 files changed +24 -17
modified libpkg/fetch.c
@@ -209,7 +209,7 @@ select_fetcher(const char *url)
	struct fetcher *f;
	size_t nsz;

-
	for (size_t i = 0; i < nitems(fetchers); i++) {
+
	for (size_t i = 0; i < NELEM(fetchers); i++) {
		nsz = strlen(fetchers[i].scheme);

		if ((strncasecmp(url, fetchers[i].scheme, nsz) == 0) &&
modified libpkg/pkg_elf.c
@@ -859,7 +859,7 @@ pkg_get_myarch_elfparse(char *dest, size_t sz, struct os_info *oi)
	 * This also helps alleviate some excessive wrapping later.
	 */
	checkroot = ctx.pkg_rootdir != NULL;
-
	for (fd = -1, i = 0; i < nitems(abi_files); i++) {
+
	for (fd = -1, i = 0; i < NELEM(abi_files); i++) {
		if (abi_files[i] == NULL)
			continue;
		/*
modified libpkg/pkg_macho.c
@@ -150,7 +150,7 @@ add_dylibs_to_pkg(__unused void *actdata, struct pkg *pkg, const char *fpath,
		  const char *name, bool is_shlib)
{
	/* Skip references to system libraries */
-
	for (size_t i = 0; i < nitems(system_dylib_prefixes); i++) {
+
	for (size_t i = 0; i < NELEM(system_dylib_prefixes); i++) {
		const char *prefix = system_dylib_prefixes[i];
		if (strncmp(name, prefix, strlen(prefix)) == 0)
			return EPKG_OK;
modified libpkg/pkg_ports.c
@@ -668,7 +668,7 @@ apply_keyword_file(ucl_object_t *obj, struct plist *p, char *line, struct file_a
		l = formated_line;
	}
	/* add all shell scripts */
-
	for (int i = 0; i < nitems(script_mapping); i++) {
+
	for (int i = 0; i < NELEM(script_mapping); i++) {
		if ((o = ucl_object_find_key(obj, script_mapping[i].key))) {
			if (format_exec_cmd(&cmd, ucl_object_tostring(o), p->prefix,
			    p->last_file, l, argc, args, false) != EPKG_OK)
@@ -679,7 +679,7 @@ apply_keyword_file(ucl_object_t *obj, struct plist *p, char *line, struct file_a
	}

	/* add all lua scripts */
-
	for (int i = 0; i < nitems(lua_mapping); i++) {
+
	for (int i = 0; i < NELEM(lua_mapping); i++) {
		if ((o = ucl_object_find_key(obj, lua_mapping[i].key))) {
			if (format_exec_cmd(&cmd, ucl_object_tostring(o), p->prefix,
			    p->last_file, l, argc, args, true) != EPKG_OK)
modified libpkg/pkg_version.c
@@ -196,7 +196,7 @@ get_component(const char *position, version_component *component)
		/* handle special suffixes */
		if (isalpha(pos[1])) {
			unsigned int i;
-
			for (i = 0; i < nitems(stages); i++) {
+
			for (i = 0; i < NELEM(stages); i++) {
				const struct stage *stage = &stages[i];
				size_t len = stage->namelen;
				if (strncasecmp(pos, stage->name, len) == 0 &&
modified libpkg/pkgdb_iterator.c
@@ -838,8 +838,10 @@ populate_pkg(sqlite3_stmt *stmt, struct pkg *pkg) {
		struct column_mapping *column;
		switch (sqlite3_column_type(stmt, icol)) {
		case SQLITE_TEXT:
-
			column = bsearch(colname, columns, NELEM(columns) - 1,
-
					sizeof(columns[0]), compare_column_func);
+
			column = bsearch(colname, columns,
+
					 NELEM(columns) - 1,
+
					 sizeof(columns[0]),
+
					 compare_column_func);
			if (column == NULL) {
				pkg_emit_error("unknown column %s", colname);
				continue;
@@ -918,8 +920,10 @@ populate_pkg(sqlite3_stmt *stmt, struct pkg *pkg) {
			}
			break;
		case SQLITE_INTEGER:
-
			column = bsearch(colname, columns, NELEM(columns) - 1,
-
					sizeof(columns[0]), compare_column_func);
+
			column = bsearch(colname, columns,
+
					 NELEM(columns) - 1,
+
					 sizeof(columns[0]),
+
					 compare_column_func);
			if (column == NULL) {
				pkg_emit_error("Unknown column %s", colname);
				continue;
modified libpkg/pkgsign.c
@@ -82,7 +82,7 @@ pkgsign_new(const char *name, struct pkgsign_ctx **ctx)
	assert(*ctx == NULL);

	ops = NULL;
-
	for (size_t i = 0; i < nitems(pkgsign_builtins); i++) {
+
	for (size_t i = 0; i < NELEM(pkgsign_builtins); i++) {
		impl = &pkgsign_builtins[i];
		if (STREQ(name, impl->pi_name)) {
			ops = impl->pi_ops;
modified libpkg/private/pkg.h
@@ -67,10 +67,6 @@
# endif
#endif

-
#ifndef nitems
-
#define nitems(x)       (sizeof((x)) / sizeof((x)[0]))
-
#endif
-

#ifndef roundup2
#define	roundup2(x, y)	(((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
#endif
modified libpkg/scripts.c
@@ -90,12 +90,12 @@ pkg_script_run(struct pkg * const pkg, pkg_script type, bool upgrade)
		return (EPKG_OK);
	}

-
	for (i = 0; i < nitems(map); i++) {
+
	for (i = 0; i < NELEM(map); i++) {
		if (map[i].a == type)
			break;
	}

-
	assert(i < nitems(map));
+
	assert(i < NELEM(map));

#ifdef PROC_REAP_KILL
	mypid = getpid();
modified tests/cocci/pkg/NELEM.cocci
@@ -29,3 +29,10 @@ T[] E;

- (sizeof(E)/sizeof(T))
+ NELEM(E)
+

+
@@
+
expression E;
+
@@
+

+
- nitems(E)
+
+ NELEM(E)