summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2003-01-19 03:05:01 +0000
committerache <ache@FreeBSD.org>2003-01-19 03:05:01 +0000
commitc60183cc58664a0b709021eed9f05b4ba68d3f18 (patch)
tree005d6ee1aed30a85d7137a7233fbfa9ae42c436a /lib/libutil
parent665cbf9fac61158be10859f4301dbac1e617b213 (diff)
downloadFreeBSD-src-c60183cc58664a0b709021eed9f05b4ba68d3f18.zip
FreeBSD-src-c60183cc58664a0b709021eed9f05b4ba68d3f18.tar.gz
Add (unsigned char) cast to ctype macros
Handle NULL return from malloc and strdup
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/property.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/lib/libutil/property.c b/lib/libutil/property.c
index 57383f9..91270f8 100644
--- a/lib/libutil/property.c
+++ b/lib/libutil/property.c
@@ -46,11 +46,25 @@ property_alloc(char *name, char *value)
{
properties n;
- n = (properties)malloc(sizeof(struct _property));
+ if ((n = (properties)malloc(sizeof(struct _property))) == NULL)
+ return (NULL);
n->next = NULL;
- n->name = name ? strdup(name) : NULL;
- n->value = value ? strdup(value) : NULL;
- return n;
+ if (name != NULL) {
+ if ((n->name = strdup(name)) == NULL) {
+ free(n);
+ return (NULL);
+ }
+ } else
+ n->name = NULL;
+ if (value != NULL) {
+ if ((n->value = strdup(value)) == NULL) {
+ free(n->name);
+ free(n);
+ return (NULL);
+ }
+ } else
+ n->value = NULL;
+ return (n);
}
properties
@@ -88,14 +102,14 @@ properties_read(int fd)
/* FALLTHROUGH deliberately since we already have a character and state == LOOK */
case LOOK:
- if (isspace(ch))
+ if (isspace((unsigned char)ch))
continue;
/* Allow shell or lisp style comments */
else if (ch == '#' || ch == ';') {
state = COMMENT;
continue;
}
- else if (isalnum(ch) || ch == '_') {
+ else if (isalnum((unsigned char)ch) || ch == '_') {
if (n >= PROPERTY_MAX_NAME) {
n = 0;
state = COMMENT;
@@ -121,7 +135,7 @@ properties_read(int fd)
v = n = 0;
state = COMMIT;
}
- else if (isspace(ch))
+ else if (isspace((unsigned char)ch))
continue;
else if (ch == '=') {
hold_n[n] = '\0';
@@ -138,7 +152,7 @@ properties_read(int fd)
v = n = 0;
state = COMMIT;
}
- else if (v == 0 && isspace(ch))
+ else if (v == 0 && isspace((unsigned char)ch))
continue;
else if (ch == '{') {
state = MVALUE;
@@ -180,10 +194,14 @@ properties_read(int fd)
break;
case COMMIT:
- if (!head)
- head = ptr = property_alloc(hold_n, hold_v);
- else {
- ptr->next = property_alloc(hold_n, hold_v);
+ if (head == NULL) {
+ if ((head = ptr = property_alloc(hold_n, hold_v)) == NULL)
+ return (NULL);
+ } else {
+ if ((ptr->next = property_alloc(hold_n, hold_v)) == NULL) {
+ properties_free(head);
+ return (NULL);
+ }
ptr = ptr->next;
}
state = LOOK;
@@ -195,7 +213,7 @@ properties_read(int fd)
break;
}
}
- return head;
+ return (head);
}
char *
OpenPOWER on IntegriCloud