Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-6]: src/lib/libmenu Pull up revision 1.10 (requested by blymn i...
details: https://anonhg.NetBSD.org/src/rev/58aa49c9d6d3
branches: netbsd-1-6
changeset: 530786:58aa49c9d6d3
user: tron <tron%NetBSD.org@localhost>
date: Thu Oct 02 09:58:28 2003 +0000
description:
Pull up revision 1.10 (requested by blymn in ticket #1489):
new_item fixes:
* return NULL to indicate an error if a NULL name is passed
* fix a crash if description is NULL
Thanks to Julian Coleman for finding and fixing these.
diffstat:
lib/libmenu/item.c | 34 +++++++++++++++++++++++-----------
1 files changed, 23 insertions(+), 11 deletions(-)
diffs (65 lines):
diff -r 65b3ee6b6620 -r 58aa49c9d6d3 lib/libmenu/item.c
--- a/lib/libmenu/item.c Thu Oct 02 09:57:17 2003 +0000
+++ b/lib/libmenu/item.c Thu Oct 02 09:58:28 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: item.c,v 1.7 2001/06/13 10:45:59 wiz Exp $ */
+/* $NetBSD: item.c,v 1.7.2.1 2003/10/02 09:58:28 tron Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn (blymn%baea.com.au@localhost, brett_lymn%yahoo.com.au@localhost)
@@ -248,6 +248,9 @@
{
ITEM *new_one;
+ if (name == NULL)
+ return NULL;
+
/* allocate a new item structure for ourselves */
if ((new_one = (ITEM *)malloc(sizeof(ITEM))) == NULL)
return NULL;
@@ -267,18 +270,26 @@
strcpy(new_one->name.string, name);
+ if (description == NULL)
+ new_one->description.length = 0;
+ else {
/* fill in the description structure, stash the length then
allocate room for description string and copy it in */
- new_one->description.length = strlen(description);
- if ((new_one->description.string = (char *)
- malloc(sizeof(char) * new_one->description.length + 1)) == NULL) {
- /* malloc has failed - free up allocated memory and return */
- free(new_one->name.string);
- free(new_one);
- return NULL;
+ new_one->description.length = strlen(description);
+ if ((new_one->description.string =
+ (char *) malloc(sizeof(char) *
+ new_one->description.length + 1)) == NULL) {
+ /*
+ * malloc has failed
+ * - free up allocated memory and return
+ */
+ free(new_one->name.string);
+ free(new_one);
+ return NULL;
+ }
+
+ strcpy(new_one->description.string, description);
}
-
- strcpy(new_one->description.string, description);
return new_one;
}
@@ -298,7 +309,8 @@
/* no connections, so free storage starting with the strings */
free(item->name.string);
- free(item->description.string);
+ if (item->description.length)
+ free(item->description.string);
free(item);
return E_OK;
}
Home |
Main Index |
Thread Index |
Old Index