summaryrefslogtreecommitdiffstats
path: root/src/dmixml.c
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2009-04-30 16:07:43 +0200
committerDavid Sommerseth <davids@redhat.com>2009-04-30 16:07:43 +0200
commitcea1270777d0a5bd42284011307fe183a67f8ada (patch)
tree484fe523e3d8ccb36aa0bd6ba437926b3b6ab7c2 /src/dmixml.c
parent6453a1131547b71c4a21a978fd9588d67d056233 (diff)
downloadpython-dmidecode-cea1270777d0a5bd42284011307fe183a67f8ada.tar.gz
python-dmidecode-cea1270777d0a5bd42284011307fe183a67f8ada.tar.xz
python-dmidecode-cea1270777d0a5bd42284011307fe183a67f8ada.zip
Rewritten dmixml_GetXPathContent(...) and _get_key_value(...)
This rewrite was to handle XPATH_NUMBER more correctly. Now these functions needs an preallocated memory buffer for the result.
Diffstat (limited to 'src/dmixml.c')
-rw-r--r--src/dmixml.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/dmixml.c b/src/dmixml.c
index f8a6219..8228bf3 100644
--- a/src/dmixml.c
+++ b/src/dmixml.c
@@ -210,8 +210,8 @@ inline char *dmixml_GetNodeContent(xmlNode *node, const char *key) {
return dmixml_GetContent(dmixml_FindNode(node, key));
}
-char *dmixml_GetXPathContent(xmlXPathObject *xpo, int idx) {
- char *ret = NULL;
+char *dmixml_GetXPathContent(char *buf, size_t buflen, xmlXPathObject *xpo, int idx) {
+ memset(buf, 0, buflen);
if( xpo == NULL ) {
return NULL;
@@ -219,26 +219,25 @@ char *dmixml_GetXPathContent(xmlXPathObject *xpo, int idx) {
switch( xpo->type ) {
case XPATH_STRING:
- ret = (char *)xpo->stringval;
+ strncpy(buf, (char *)xpo->stringval, buflen-1);
break;
case XPATH_NUMBER:
- ret = (char *) malloc(34);
- memset(ret, 0, 34);
- snprintf(ret, 32, "%f", xpo->floatval);
+ snprintf(buf, buflen-1, "%f", xpo->floatval);
break;
case XPATH_NODESET:
- ret = ( (xpo->nodesetval->nodeNr >= (idx+1))
- ? dmixml_GetContent(xpo->nodesetval->nodeTab[idx])
- : NULL);
+ if( xpo->nodesetval->nodeNr >= (idx+1) ) {
+ strncpy(buf, dmixml_GetContent(xpo->nodesetval->nodeTab[idx]), buflen-1);
+ }
break;
default:
fprintf(stderr, "dmixml_GetXPathContent(...):: "
"Do not know how to handle XPath type %i\n",
xpo->type);
+ return NULL;
}
- return ret;
+ return buf;
}