MSVC warns:
C:\GitLab-Runner\builds\graphviz\graphviz\cmd\tools\gxl2gv.c(694): warning
C6262: Function uses '20020' bytes of stack: exceeds /analyze:stacksize
'16384'. Consider moving some data to heap.
[C:\GitLab-Runner\builds\graphviz\graphviz\cmd\tools\gxl2gv.vcxproj]
So this function attempts to allocate ~20KB of stack data. Most of this is due
to the `buf` array. Using this much stack can cause crashes in constrained
environments. The buffer in question is used to read XML data in chunks, so we
can instead use the C standard library’s constant `BUFSIZ` that tells us the
optimal chunk size with which to perform I/O.
This change avoids the described problem as well as being a performance
optimization.
#include <cgraph/likely.h>
#include <cgraph/stack.h>
#include <common/memory.h>
+#include <stdio.h>
#ifdef HAVE_EXPAT
#include <expat.h>
#include <ctype.h>
#define XML_STATUS_ERROR 0
#endif
-#define BUFSIZE 20000
#define SMALLBUF 1000
#define NAMEBUF 100
Agraph_t *gxl_to_gv(FILE * gxlFile)
{
- char buf[BUFSIZE];
+ char buf[BUFSIZ];
int done;
userdata_t *udata = genUserdata();
XML_Parser parser = XML_ParserCreate(NULL);