diff options
author | Matthias Bolte <matthias.bolte@googlemail.com> | 2011-04-25 00:25:10 +0200 |
---|---|---|
committer | Matthias Bolte <matthias.bolte@googlemail.com> | 2011-04-30 19:59:52 +0200 |
commit | 9ba4eb3c081027846637acf20b17ec801dc66b72 (patch) | |
tree | 12eaeebaeeb298f17c8f009d1c08c43a590eda27 /tests/xencapstest.c | |
parent | tests: Update valgrind suppressions file (diff) | |
download | libvirt-9ba4eb3c081027846637acf20b17ec801dc66b72.tar.gz libvirt-9ba4eb3c081027846637acf20b17ec801dc66b72.tar.bz2 libvirt-9ba4eb3c081027846637acf20b17ec801dc66b72.zip |
tests: Lower stack usage below 4096 bytes
Make virtTestLoadFile allocate the buffer to read the file into.
Fix logic error in virtTestLoadFile, stop reading on the first empty line.
Use virFileReadLimFD in virtTestCaptureProgramOutput to avoid manual
buffer handling.
Diffstat (limited to 'tests/xencapstest.c')
-rw-r--r-- | tests/xencapstest.c | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/tests/xencapstest.c b/tests/xencapstest.c index 36946cf10..3f96cf2a3 100644 --- a/tests/xencapstest.c +++ b/tests/xencapstest.c @@ -11,32 +11,27 @@ #include "xen/xen_hypervisor.h" #include "files.h" -#define MAX_FILE 4096 - -static int testCompareFiles(const char *hostmachine, - const char *xml_rel, - const char *cpuinfo_rel, - const char *capabilities_rel) { - char xmlData[MAX_FILE]; - char *expectxml = &(xmlData[0]); +static int +testCompareFiles(const char *hostmachine, const char *xml_rel, + const char *cpuinfo_rel, const char *capabilities_rel) +{ + char *expectxml = NULL; char *actualxml = NULL; FILE *fp1 = NULL, *fp2 = NULL; virCapsPtr caps = NULL; int ret = -1; - char xml[PATH_MAX]; - char cpuinfo[PATH_MAX]; - char capabilities[PATH_MAX]; + char *xml = NULL; + char *cpuinfo = NULL; + char *capabilities = NULL; - snprintf(xml, sizeof xml - 1, "%s/%s", - abs_srcdir, xml_rel); - snprintf(cpuinfo, sizeof cpuinfo - 1, "%s/%s", - abs_srcdir, cpuinfo_rel); - snprintf(capabilities, sizeof capabilities - 1, "%s/%s", - abs_srcdir, capabilities_rel); + if (virAsprintf(&xml, "%s/%s", abs_srcdir, xml_rel) < 0 || + virAsprintf(&cpuinfo, "%s/%s", abs_srcdir, cpuinfo_rel) < 0 || + virAsprintf(&capabilities, "%s/%s", abs_srcdir, capabilities_rel) < 0) + goto fail; - if (virtTestLoadFile(xml, &expectxml, MAX_FILE) < 0) + if (virtTestLoadFile(xml, &expectxml) < 0) goto fail; if (!(fp1 = fopen(cpuinfo, "r"))) @@ -59,8 +54,11 @@ static int testCompareFiles(const char *hostmachine, ret = 0; fail: - + free(expectxml); free(actualxml); + free(xml); + free(cpuinfo); + free(capabilities); VIR_FORCE_FCLOSE(fp1); VIR_FORCE_FCLOSE(fp2); |