chiark
/
gitweb
/
~ianmdlvl
/
adns.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
regress: hfuzzraw: Introduce P_read_dump
[adns.git]
/
regress
/
hfuzzraw.c.m4
diff --git
a/regress/hfuzzraw.c.m4
b/regress/hfuzzraw.c.m4
index 3dad0879f40f52f450929df8bee0a170aa7a974e..a1a9d0fb7645520e2ad8cefadfa2e12ba76c2ca3 100644
(file)
--- a/
regress/hfuzzraw.c.m4
+++ b/
regress/hfuzzraw.c.m4
@@
-49,10
+49,14
@@
static vbuf fdtab;
static FILE *Tinputfile;
static int stdout_enable;
static FILE *Tinputfile;
static int stdout_enable;
+static void Tflushstdout( void) {
+ if (fflush(stdout)) Toutputerr();
+}
+
void Q_vb(void) {
if (!adns__vbuf_append(&vb,"",1)) Tnomem();
if (fprintf(stdout," %s\n",vb.buf) == EOF) Toutputerr();
void Q_vb(void) {
if (!adns__vbuf_append(&vb,"",1)) Tnomem();
if (fprintf(stdout," %s\n",vb.buf) == EOF) Toutputerr();
-
if (fflush(stdout)) Toutputerr
();
+
Tflushstdout
();
}
static void Pformat(const char *what) {
}
static void Pformat(const char *what) {
@@
-93,13
+97,32
@@
void Tensurerecordfile(void) {
if (proutstr) stdout_enable= atoi(proutstr);
}
if (proutstr) stdout_enable= atoi(proutstr);
}
-static void P_read(void *p, size_t sz) {
+
+static void P_read_dump(const unsigned char *p0, size_t count, ssize_t d) {
+ fputs(" | ",stdout);
+ while (count) {
+ fprintf(stdout,"%02x", *p0);
+ p0 += d;
+ count--;
+ }
+}
+
+static void P_read(void *p, size_t sz, const char *what) {
ssize_t got = fread(p,1,sz,Tinputfile);
Pcheckinput();
assert(got==sz);
ssize_t got = fread(p,1,sz,Tinputfile);
Pcheckinput();
assert(got==sz);
+ if (stdout_enable && sz) {
+ fprintf(stdout,"%s:",what);
+ P_read_dump(p, sz, +1);
+ if (sz<=16) {
+ P_read_dump((const unsigned char *)p+sz-1, sz, -1);
+ }
+ fputs(" |\n",stdout);
+ Tflushstdout();
+ }
}
}
-#define P_READ(x) (P_read(&(x), sizeof((x))))
+#define P_READ(x) (P_read(&(x), sizeof((x))
, #x
))
static unsigned P_fdf(int fd) {
assert(fd>=0 && fd<fdtab.used);
static unsigned P_fdf(int fd) {
assert(fd>=0 && fd<fdtab.used);
@@
-133,7
+156,7
@@
static int Pbytes(byte *buf, int maxlen) {
int l;
P_READ(l);
if (l<0 || l>maxlen) Pformat("bad byte block len");
int l;
P_READ(l);
if (l<0 || l>maxlen) Pformat("bad byte block len");
- P_read(buf, l);
+ P_read(buf, l
, "bytes"
);
return l;
}
return l;
}