diff options
author | Jordan K. Hubbard <jkh@FreeBSD.org> | 1996-12-11 18:23:19 +0000 |
---|---|---|
committer | Jordan K. Hubbard <jkh@FreeBSD.org> | 1996-12-11 18:23:19 +0000 |
commit | 86767547be6d071f1ecbc24c22a4cb3832b05a67 (patch) | |
tree | b4559797b88382d69ce7830e112c0f922eafa0ba /release | |
parent | 4963f4cd96d2963c9a6845a6886aa6fcf8995903 (diff) | |
download | src-86767547be6d071f1ecbc24c22a4cb3832b05a67.tar.gz src-86767547be6d071f1ecbc24c22a4cb3832b05a67.zip |
Be more efficient in how we use memory (stumbled across while looking for
something else) for attributes and variables.
Remove stack-stomper in sstrncpy().
Notes
Notes:
svn path=/head/; revision=20331
Diffstat (limited to 'release')
-rw-r--r-- | release/sysinstall/attr.c | 32 | ||||
-rw-r--r-- | release/sysinstall/cdrom.c | 5 | ||||
-rw-r--r-- | release/sysinstall/dist.c | 4 | ||||
-rw-r--r-- | release/sysinstall/main.c | 13 | ||||
-rw-r--r-- | release/sysinstall/misc.c | 4 | ||||
-rw-r--r-- | release/sysinstall/sysinstall.h | 15 | ||||
-rw-r--r-- | release/sysinstall/variable.c | 36 |
7 files changed, 63 insertions, 46 deletions
diff --git a/release/sysinstall/attr.c b/release/sysinstall/attr.c index 7b2df7373df3..2310d3cc7139 100644 --- a/release/sysinstall/attr.c +++ b/release/sysinstall/attr.c @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * - * $Id: attr.c,v 1.9 1996/12/09 08:22:10 jkh Exp $ + * $Id: attr.c,v 1.10 1996/12/11 09:34:53 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -63,7 +63,7 @@ attr_parse(Attribs *attr, FILE *fp) int n, v; enum { LOOK, COMMENT, NAME, VALUE, COMMIT } state; int lno, num_attribs; - char ch; + int ch; n = v = lno = num_attribs = 0; state = LOOK; @@ -137,19 +137,20 @@ attr_parse(Attribs *attr, FILE *fp) break; case COMMIT: - SAFE_STRCPY(attr[num_attribs].name, hold_n); - SAFE_STRCPY(attr[num_attribs].value, hold_v); + attr[num_attribs].name = strdup(hold_n); + attr[num_attribs].value = strdup(hold_v); state = LOOK; v = n = 0; - ++num_attribs; + if (++num_attribs >= MAX_ATTRIBS) + msgFatal("Attribute limit overflow; encountered a bad attributes file!"); break; default: msgFatal("Unknown state at line %d??", lno); } } - attr[num_attribs].name[0] = '\0'; /* end marker */ - attr[num_attribs].value[0] = '\0'; /* end marker */ + attr[num_attribs].name = NULL; /* end marker */ + attr[num_attribs].value = NULL; /* end marker */ if (isDebug()) msgDebug("Finished parsing %d attributes.\n", num_attribs); @@ -164,7 +165,7 @@ attr_match(Attribs *attr, char *name) if (isDebug()) msgDebug("Trying to match attribute `%s'\n", name); - for (n = 0; attr[n].name[0] && strcasecmp(attr[n].name, name) != 0; n++) { + for (n = 0; attr[n].name && strcasecmp(attr[n].name, name) != 0; n++) { if (isDebug()) msgDebug("Skipping attribute %u\n", n); } @@ -172,7 +173,7 @@ attr_match(Attribs *attr, char *name) if (isDebug()) msgDebug("Stopped on attribute %u\n", n); - if (attr[n].name[0]) { + if (attr[n].name) { if (isDebug()) msgDebug("Returning `%s'\n", attr[n].value); return(attr[n].value); @@ -180,3 +181,16 @@ attr_match(Attribs *attr, char *name) return NULL; } + +void +attr_free(Attribs *attr) +{ + int i; + + for (i = 0; attr[i].name; i++) { + free(attr[i].name); + free(attr[i].value); + attr[i].name = attr[i].value = NULL; + } + free(attr); +} diff --git a/release/sysinstall/cdrom.c b/release/sysinstall/cdrom.c index beb22dbd3364..8324e659f735 100644 --- a/release/sysinstall/cdrom.c +++ b/release/sysinstall/cdrom.c @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * - * $Id: cdrom.c,v 1.26 1996/10/14 21:32:22 jkh Exp $ + * $Id: cdrom.c,v 1.27 1996/12/11 09:34:54 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -74,7 +74,7 @@ mediaInitCDROM(Device *dev) args.fspec = dev->devname; args.flags = 0; - cd_attr = alloca(sizeof(Attribs) * MAX_ATTRIBS); + cd_attr = safe_malloc(sizeof(Attribs) * MAX_ATTRIBS); cp = NULL; dontRead = FALSE; /* If this cdrom's not already mounted or can't be mounted, yell */ @@ -116,6 +116,7 @@ mediaInitCDROM(Device *dev) "to set the boot floppy version string to match that of the CD\n" "before selecting it as an installation media to avoid this warning", cp, variable_get(VAR_RELNAME)); } + attr_free(cd_attr); msgDebug("Mounted FreeBSD CDROM on device %s as /cdrom\n", dev->devname); return TRUE; } diff --git a/release/sysinstall/dist.c b/release/sysinstall/dist.c index 40a0c860c664..b2f60a0558a5 100644 --- a/release/sysinstall/dist.c +++ b/release/sysinstall/dist.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: dist.c,v 1.80 1996/12/08 12:27:54 jkh Exp $ + * $Id: dist.c,v 1.81 1996/12/11 09:34:57 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -400,7 +400,7 @@ distExtract(char *parent, Distribution *me) if (tmp) numchunks = strtol(tmp, 0, 0); } - safe_free(dist_attr); + attr_free(dist_attr); fclose(fp); if (!numchunks) continue; diff --git a/release/sysinstall/main.c b/release/sysinstall/main.c index d61d0c119002..b5ebbb8bc839 100644 --- a/release/sysinstall/main.c +++ b/release/sysinstall/main.c @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated for what's essentially a complete rewrite. * - * $Id: main.c,v 1.28 1996/09/26 21:03:35 pst Exp $ + * $Id: main.c,v 1.29 1996/12/11 09:35:02 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -113,20 +113,20 @@ main(int argc, char **argv) { FILE *fp; - Attribs attrs[512]; - - bzero(attrs, sizeof(attrs)); + Attribs *attrs; + attrs = safe_malloc(sizeof(Attribs) * MAX_ATTRIBS); fp = fopen("install.cfg", "r"); if (fp) { msgNotify("Loading pre-configuration file"); if (DITEM_STATUS(attr_parse(attrs, fp)) == DITEM_SUCCESS) { int i; - for (i = 0; *attrs[i].name; i++) + for (i = 0; attrs[i].name; i++) variable_set2(attrs[i].name, attrs[i].value); } fclose(fp); + attr_free(attrs); } #if defined(LOAD_CONFIG_FILE) @@ -150,10 +150,11 @@ main(int argc, char **argv) if (DITEM_STATUS(attr_parse(attrs, fp)) == DITEM_SUCCESS) { int i; - for (i = 0; *attrs[i].name; i++) + for (i = 0; attrs[i].name; i++) variable_set2(attrs[i].name, attrs[i].value); } fclose(fp); + attr_free(attrs); } mediaDevice->shutdown(mediaDevice); } diff --git a/release/sysinstall/misc.c b/release/sysinstall/misc.c index 17ce8eb37bd2..af88fe3b2d1f 100644 --- a/release/sysinstall/misc.c +++ b/release/sysinstall/misc.c @@ -1,7 +1,7 @@ /* * Miscellaneous support routines.. * - * $Id: misc.c,v 1.22 1996/07/09 14:28:17 jkh Exp $ + * $Id: misc.c,v 1.23 1996/12/09 08:22:15 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -80,7 +80,7 @@ string_concat(char *one, char *two) char * sstrncpy(char *dst, const char *src, int size) { - *(dst + size) = '\0'; + dst[size - 1] = '\0'; return strncpy(dst, src, size - 1); } diff --git a/release/sysinstall/sysinstall.h b/release/sysinstall/sysinstall.h index 3ebcecfc934d..a121167287ae 100644 --- a/release/sysinstall/sysinstall.h +++ b/release/sysinstall/sysinstall.h @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * - * $Id: sysinstall.h,v 1.90 1996/12/09 08:22:17 jkh Exp $ + * $Id: sysinstall.h,v 1.91 1996/12/11 09:35:05 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -58,10 +58,6 @@ #define PACKAGE_SAMBA "samba-1.9.15p8" #define PACKAGE_LYNX "lynx-2.6" -/* variable limits */ -#define VAR_NAME_MAX 128 -#define VAR_VALUE_MAX 1024 - /* device limits */ #define DEV_NAME_MAX 64 /* The maximum length of a device name */ #define DEV_MAX 100 /* The maximum number of devices we'll deal with */ @@ -173,8 +169,8 @@ typedef struct _dmenu { /* A sysconfig variable */ typedef struct _variable { struct _variable *next; - char name[VAR_NAME_MAX]; - char value[VAR_VALUE_MAX]; + char *name; + char *value; } Variable; /* For attribs */ @@ -183,8 +179,8 @@ typedef struct _variable { #define MAX_VALUE 256 typedef struct _attribs { - char name[MAX_NAME]; - char value[MAX_VALUE]; + char *name; + char *value; } Attribs; typedef enum { @@ -359,6 +355,7 @@ extern int configAnonFTP(dialogMenuItem *self); extern char *attr_match(Attribs *attr, char *name); extern int attr_parse_file(Attribs *attr, char *file); extern int attr_parse(Attribs *attr, FILE *fp); +extern void attr_free(Attribs *attr); /* cdrom.c */ extern Boolean mediaInitCDROM(Device *dev); diff --git a/release/sysinstall/variable.c b/release/sysinstall/variable.c index 013358ece8e1..3b902860652f 100644 --- a/release/sysinstall/variable.c +++ b/release/sysinstall/variable.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: variable.c,v 1.11 1996/06/12 14:02:13 jkh Exp $ + * $Id: variable.c,v 1.12 1996/12/09 08:22:19 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -41,35 +41,36 @@ static void make_variable(char *var, char *value) { - Variable *newvar; + Variable *vp; /* Put it in the environment in any case */ setenv(var, value, 1); /* Now search to see if it's already in the list */ - for (newvar = VarHead; newvar; newvar = newvar->next) { - if (!strcmp(newvar->name, var)) { + for (vp = VarHead; vp; vp = vp->next) { + if (!strcmp(vp->name, var)) { if (isDebug()) - msgDebug("variable %s was %s, now %s\n", newvar->name, newvar->value, value); - SAFE_STRCPY(newvar->value, value); + msgDebug("variable %s was %s, now %s\n", vp->name, vp->value, value); + free(vp->value); + vp->value = strdup(value); return; } } /* No? Create a new one */ - newvar = (Variable *)safe_malloc(sizeof(Variable)); - SAFE_STRCPY(newvar->name, var); - SAFE_STRCPY(newvar->value, value); - newvar->next = VarHead; - VarHead = newvar; + vp = (Variable *)safe_malloc(sizeof(Variable)); + vp->name = strdup(var); + vp->value = strdup(value); + vp->next = VarHead; + VarHead = vp; if (isDebug()) - msgDebug("Setting variable %s to %s\n", newvar->name, newvar->value); + msgDebug("Setting variable %s to %s\n", vp->name, vp->value); } void variable_set(char *var) { - char tmp[VAR_NAME_MAX + VAR_VALUE_MAX], *cp; + char tmp[1024], *cp; if (!var) msgFatal("NULL variable name & value passed."); @@ -102,12 +103,11 @@ void variable_unset(char *var) { Variable *vp; - char name[VAR_NAME_MAX + 1], *cp; + char name[512], *cp; unsetenv(var); if ((cp = index(var, '=')) != NULL) { - strncpy(name, cp, cp - var); - name[cp - var] = '\0'; + sstrncpy(name, cp, cp - var); var = name; } @@ -115,6 +115,8 @@ variable_unset(char *var) if (!VarHead) return; else if (!VarHead->next && !strcmp(VarHead->name, var)) { + safe_free(VarHead->name); + safe_free(VarHead->value); free(VarHead); VarHead = NULL; } @@ -124,6 +126,8 @@ variable_unset(char *var) Variable *save = vp->next; *vp = *save; + safe_free(save->name); + safe_free(save->value); safe_free(save); break; } |