FSCORE-608 (2nd issue pertaining to parsing an empty xml file)

This commit is contained in:
Anthony Minessale 2010-05-14 11:27:29 -05:00
parent 349abc3fd0
commit 9da349213b

View File

@ -1505,15 +1505,20 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file_simple(const char *file)
if ((fd = open(file, O_RDONLY, 0)) > -1) { if ((fd = open(file, O_RDONLY, 0)) > -1) {
fstat(fd, &st); fstat(fd, &st);
if (!st.st_size) goto error;
m = malloc(st.st_size); m = malloc(st.st_size);
switch_assert(m); switch_assert(m);
l = read(fd, m, st.st_size); if (!(l = read(fd, m, st.st_size))) goto error;
root = (switch_xml_root_t) switch_xml_parse_str((char *) m, l); if (!(root = (switch_xml_root_t) switch_xml_parse_str((char *) m, l))) goto error;
root->dynamic = 1; root->dynamic = 1;
close(fd); close(fd);
return &root->xml; return &root->xml;
} }
error:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing File [%s]\n", file);
return NULL; return NULL;
} }