64-bit clean + WARNS=6:
- Convert the (char *) cast+cast backs magic to memcpy(3). Without this, the resulting code is potentially risky with higher optimization levels. - Avoid same name when calling local variables, as well as global symbols. This reduces confusion for both human and compiler. - Add necessary casts, consts - Use new style function defination. - Minor style.Makefile(5) tweak - Bump WARNS?= from 0 to 6 ** for the aout code: changes are intentionally limited to ease maintaince.
This commit is contained in:
parent
d0aa4b3fa0
commit
06eda379d4
@ -62,14 +62,13 @@
|
||||
char **search_dirs;
|
||||
int n_search_dirs;
|
||||
|
||||
char *standard_search_dirs[] = {
|
||||
const char *standard_search_dirs[] = {
|
||||
STANDARD_SEARCH_DIRS
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
add_search_dir(name)
|
||||
char *name;
|
||||
add_search_dir(const char *name)
|
||||
{
|
||||
int n;
|
||||
|
||||
@ -269,7 +268,7 @@ search_lib_dir(dir, name, majorp, minorp, do_dot_a)
|
||||
int *minorp;
|
||||
int do_dot_a;
|
||||
{
|
||||
int namelen;
|
||||
size_t namelen;
|
||||
DIR *dd;
|
||||
struct dirent *dp;
|
||||
int best_dewey[MAXDEWEY];
|
||||
|
@ -33,7 +33,7 @@
|
||||
extern char **search_dirs;
|
||||
extern int n_search_dirs;
|
||||
|
||||
void add_search_dir __P((char *));
|
||||
void add_search_dir __P((const char *));
|
||||
void add_search_path __P((char *));
|
||||
void std_search_path __P((void));
|
||||
int getdewey __P((int[], char *));
|
||||
|
@ -3,8 +3,8 @@
|
||||
PROG= ldconfig
|
||||
SRCS= elfhints.c ldconfig.c shlib.c support.c
|
||||
LDDIR?= ${.CURDIR}/../../libexec/rtld-aout
|
||||
WARNS?= 6
|
||||
CFLAGS+=-I${LDDIR} -DFREEBSD_AOUT
|
||||
WARNS?= 0
|
||||
MAN= ldconfig.8
|
||||
|
||||
.PATH: ${LDDIR}
|
||||
|
@ -74,7 +74,7 @@ static int nostd;
|
||||
static int justread;
|
||||
static int merge;
|
||||
static int rescan;
|
||||
static char *hints_file;
|
||||
static const char *hints_file;
|
||||
|
||||
struct shlib_list {
|
||||
/* Internal list of shared libraries found */
|
||||
@ -99,9 +99,7 @@ static int readhints(void);
|
||||
static void usage(void);
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int i, c;
|
||||
int rval = 0;
|
||||
@ -380,10 +378,8 @@ int dewey[], ndewey;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
hinthash(cp, vmajor)
|
||||
char *cp;
|
||||
int vmajor;
|
||||
static int
|
||||
hinthash(char *cp, int vmajor)
|
||||
{
|
||||
int k = 0;
|
||||
|
||||
@ -406,7 +402,7 @@ buildhints()
|
||||
int strtab_sz = 0; /* Total length of strings */
|
||||
int nhints = 0; /* Total number of hints */
|
||||
int fd;
|
||||
char *tmpfile;
|
||||
char *_tmpfile;
|
||||
|
||||
for (shp = shlib_head; shp; shp = shp->next) {
|
||||
strtab_sz += 1 + strlen(shp->name);
|
||||
@ -447,20 +443,20 @@ buildhints()
|
||||
(hinthash(shp->name, shp->major) % hdr.hh_nbucket);
|
||||
|
||||
if (bp->hi_pathx) {
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i < hdr.hh_nbucket; i++) {
|
||||
if (blist[i].hi_pathx == 0)
|
||||
for (j = 0; j < hdr.hh_nbucket; j++) {
|
||||
if (blist[j].hi_pathx == 0)
|
||||
break;
|
||||
}
|
||||
if (i == hdr.hh_nbucket) {
|
||||
if (j == hdr.hh_nbucket) {
|
||||
warnx("bummer!");
|
||||
return -1;
|
||||
}
|
||||
while (bp->hi_next != -1)
|
||||
bp = &blist[bp->hi_next];
|
||||
bp->hi_next = i;
|
||||
bp = blist + i;
|
||||
bp->hi_next = j;
|
||||
bp = blist + j;
|
||||
}
|
||||
|
||||
/* Insert strings in string table */
|
||||
@ -486,10 +482,10 @@ buildhints()
|
||||
errx(1, "str_index(%d) != strtab_sz(%d)", str_index, strtab_sz);
|
||||
}
|
||||
|
||||
tmpfile = concat(hints_file, ".XXXXXXXXXX", "");
|
||||
_tmpfile = concat(hints_file, ".XXXXXXXXXX", "");
|
||||
umask(0); /* Create with exact permissions */
|
||||
if ((fd = mkstemp(tmpfile)) == -1) {
|
||||
warn("%s", tmpfile);
|
||||
if ((fd = mkstemp(_tmpfile)) == -1) {
|
||||
warn("%s", _tmpfile);
|
||||
return -1;
|
||||
}
|
||||
fchmod(fd, 0444);
|
||||
@ -500,7 +496,7 @@ buildhints()
|
||||
return -1;
|
||||
}
|
||||
if (write(fd, blist, hdr.hh_nbucket * sizeof(struct hints_bucket)) !=
|
||||
hdr.hh_nbucket * sizeof(struct hints_bucket)) {
|
||||
(ssize_t)(hdr.hh_nbucket * sizeof(struct hints_bucket))) {
|
||||
warn("%s", hints_file);
|
||||
return -1;
|
||||
}
|
||||
@ -519,7 +515,7 @@ buildhints()
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rename(tmpfile, hints_file) != 0) {
|
||||
if (rename(_tmpfile, hints_file) != 0) {
|
||||
warn("%s", hints_file);
|
||||
return -1;
|
||||
}
|
||||
@ -578,7 +574,6 @@ readhints()
|
||||
}
|
||||
close(fd);
|
||||
|
||||
blist = (struct hints_bucket *)((char *)addr + hdr->hh_hashtab);
|
||||
strtab = (char *)addr + hdr->hh_strtab;
|
||||
|
||||
if (hdr->hh_version >= LD_HINTS_VERSION_2)
|
||||
@ -590,16 +585,25 @@ readhints()
|
||||
if (rescan)
|
||||
return 0;
|
||||
|
||||
blist = malloc(sizeof(struct hints_bucket) * hdr->hh_nbucket);
|
||||
if (blist == NULL)
|
||||
err(1, "readhints");
|
||||
memcpy(blist, (char *)addr + hdr->hh_hashtab,
|
||||
sizeof(struct hints_bucket) * hdr->hh_nbucket);
|
||||
|
||||
|
||||
for (i = 0; i < hdr->hh_nbucket; i++) {
|
||||
struct hints_bucket *bp = &blist[i];
|
||||
|
||||
/* Sanity check */
|
||||
if (bp->hi_namex >= hdr->hh_strtab_sz) {
|
||||
warnx("bad name index: %#x", bp->hi_namex);
|
||||
free(blist);
|
||||
return -1;
|
||||
}
|
||||
if (bp->hi_pathx >= hdr->hh_strtab_sz) {
|
||||
warnx("bad path index: %#x", bp->hi_pathx);
|
||||
free(blist);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -615,6 +619,7 @@ readhints()
|
||||
shlib_tail = &shp->next;
|
||||
}
|
||||
|
||||
free(blist);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user