Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177752406
D60368.1795202296.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
D60368.1795202296.diff
View Options
diff --git a/usr.bin/whereis/whereis.c b/usr.bin/whereis/whereis.c
--- a/usr.bin/whereis/whereis.c
+++ b/usr.bin/whereis/whereis.c
@@ -33,6 +33,7 @@
*/
#include <sys/types.h>
+#include <sys/param.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
@@ -249,7 +250,7 @@
static void
defaults(void)
{
- size_t s;
+ size_t i, s;
char *b, buf[BUFSIZ], *cp;
const char *path_ports;
int nele;
@@ -307,9 +308,11 @@
/* -s defaults to precompiled list, plus subdirs of
* $PORTSDIR. If not set, it defaults to /usr/ports */
if (!sourcedirs) {
- size_t sp_len = strlen(*sourcepaths);
- sourcedirs = malloc(sp_len * sizeof (char *));
- for (size_t i = 0; i < sp_len; i++)
+ s = nitems(sourcepaths);
+ sourcedirs = malloc(s * sizeof(char *));
+ if (sourcedirs == NULL)
+ abort();
+ for (i = 0; i < s; i++)
sourcedirs[i] = sourcepaths[i];
path_ports = getenv("PORTSDIR");
@@ -329,6 +332,15 @@
return;
if ((dir = opendir(path_ports)) == NULL)
err(EX_OSERR, "opendir(%s)", path_ports);
+
+ /*
+ * Move the index one element back so if we end up adding some
+ * port directories, we place them back to back to the
+ * sourcepaths and the NULL element shows only at the end (used
+ * later on as end-o-array marker)
+ */
+ --i;
+
while ((dirp = readdir(dir)) != NULL) {
/*
* Not everything below path_ports is of
@@ -360,11 +372,11 @@
continue;
}
sourcedirs = realloc(sourcedirs,
- (nele + 2) * sizeof(char *));
+ (i + 2) * sizeof(char *));
if (sourcedirs == NULL)
abort();
- sourcedirs[nele++] = b;
- sourcedirs[nele] = NULL;
+ sourcedirs[i++] = b;
+ sourcedirs[i] = NULL;
}
closedir(dir);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 20, 7:18 PM (15 h, 51 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40360589
Default Alt Text
D60368.1795202296.diff (1 KB)
Attached To
Mode
D60368: whereis(1): Fix sourcedirs array size calculation
Attached
Detach File
Event Timeline