#include <stdio.h> /* need sprintf() */
#include <ctype.h>
#include <cgraph/cghdr.h>
+#include <cgraph/likely.h>
#include <cgraph/strcasecmp.h>
#include <inttypes.h>
req = MAX(2 * strlen(str) + 2, BUFSIZ);
if (req > len) {
- rv = realloc(rv, req);
+ char *r = realloc(rv, req);
+ if (UNLIKELY(r == NULL))
+ return NULL;
+ rv = r;
len = req;
}
return rv;
*/
char *agcanonStr(char *str)
{
- return agstrcanon(str, getoutputbuffer(str));
+ char *buffer = getoutputbuffer(str);
+ if (UNLIKELY(buffer == NULL))
+ return NULL;
+ return agstrcanon(str, buffer);
}
/*
char *agcanon(char *str, int html)
{
char* buf = getoutputbuffer(str);
+ if (UNLIKELY(buf == NULL))
+ return NULL;
if (html)
return agcanonhtmlstr(str, buf);
else
static int _write_canonstr(Agraph_t * g, iochan_t * ofile, char *str,
int chk)
{
- if (chk)
+ if (chk) {
str = agcanonStr(str);
- else
- str = _agstrcanon(str, getoutputbuffer(str));
+ } else {
+ char *buffer = getoutputbuffer(str);
+ if (UNLIKELY(buffer == NULL))
+ return EOF;
+ str = _agstrcanon(str, buffer);
+ }
return ioput(g, ofile, str);
}