[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[patch;debian-installer/anna] OBO in malloc computation, whitespace, typedef



 Compiles; have not run it yet.

 How many of these before I can get back in the keyring, folks?

2001-11-22  Karl M. Hegbloom  <karlheg@microsharp.com>

	* retriever.c: 	Whitespace fixups - space around operators please.
	Cast of void * returned by malloc unrequired in ANSI C.
        Checked the constants to ensure they match string lengths.
        (get_package): Fix OBO in malloc size computation for command buffer

	* packages.h: typedef package_t

Index: retriever.c
===================================================================
RCS file: /cvs/debian-boot/debian-installer/anna/retriever.c,v
retrieving revision 1.8
diff -u -u -r1.8 retriever.c
--- retriever.c	2000/12/21 22:28:53	1.8
+++ retriever.c	2001/11/23 04:15:27
@@ -10,18 +10,19 @@
 
 /* Returns the filename of the retriever to use. */
 /* TODO: handle more than one, and don't hard-code. */
-char *chosen_retriever (void) {
+char * chosen_retriever (void) {
 	return "/usr/lib/debian-installer/retriever/wget-retriever";
 }
 
 /* Ask the chosen retriever to download a particular package to to dest. */
-int get_package (struct package_t *package, char *dest) {
+int get_package (package_t *package, char *dest) {
 	int ret;
-	char *retriever=chosen_retriever();
-	char *command=malloc(strlen(retriever) + 1 + strlen(package->filename) +
-				     strlen(dest) + 1);
+	char *retriever = chosen_retriever();
+	char *command = malloc(strlen(retriever) + 1 /* space */
+			     + strlen(package->filename) + 1 /* space */
+			     + strlen(dest) + 1); /* sentinel null byte */
 	sprintf(command, "%s %s %s", retriever, package->filename, dest);
-	ret=! system(command);
+	ret = !system(command);
 	free(command);
 	return ret;
 }
@@ -32,13 +33,13 @@
  *
  * TODO: compressed Packages files?
  */
-struct package_t *get_packages (void) {
-	char *retriever=chosen_retriever();
+package_t* get_packages (void) {
+	char *retriever = chosen_retriever();
 	FILE *packages;
 	char buf[BUFSIZE];
-	struct package_t *p = NULL, *newp;
+	package_t *p = NULL, *newp;
 	static char tmp_packages[] = DOWNLOAD_DIR "/Packages";
-	char *command=malloc(strlen(retriever) + 10 + sizeof(tmp_packages) + 1);
+	char *command = malloc(strlen(retriever) + 10 + sizeof(tmp_packages) + 1);
 
 	unlink(tmp_packages);
 	sprintf(command, "%s Packages %s", retriever, tmp_packages);
@@ -46,13 +47,13 @@
 		free(command);
 		return NULL;
 	}
-	packages=fopen(tmp_packages, "r");
+	packages = fopen(tmp_packages, "r");
 	free(command);
 
 	while (fgets(buf, BUFSIZE, packages) && !feof(packages)) {
-		buf[strlen(buf)-1] = 0;
+		buf[strlen(buf) - 1] = 0; /* \n into \0 */
 		if (strstr(buf, "Package: ") == buf) {
-			newp=(struct package_t *) malloc(sizeof(struct package_t));
+			newp = malloc(sizeof(package_t));
 			newp->next = p;
 			p = newp;
 			p->package = strdup(buf + 9);

Index: packages.h
===================================================================
RCS file: /cvs/debian-boot/debian-installer/anna/packages.h,v
retrieving revision 1.1
diff -u -u -r1.1 packages.h
--- packages.h	2000/11/28 23:58:23	1.1
+++ packages.h	2001/11/23 04:17:59
@@ -1,9 +1,9 @@
 #define BUFSIZE		4096
 
-struct package_t {
+typedef struct package_t {
 	char *package;
 	char *filename;
 	char *md5sum;
 	int installer_menu_item;
 	struct package_t *next;
-};
+} package_t;

-- 
mailto: (Karl M. Hegbloom) karlheg@microsharp.com
http://www.microsharp.com
phone://USA/WA/360-260-2066
jabber: karlheg@jabber.org



Reply to: