From d09be0d5fc3231ccbe2159f704ba8e7ff38d9949 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 21 May 2018 23:05:39 -0400 Subject: [PATCH] Fixed bugs in hresultwrap.cpp. --- windows/tools/hresultwrap.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/windows/tools/hresultwrap.cpp b/windows/tools/hresultwrap.cpp index 05388837..aef118da 100644 --- a/windows/tools/hresultwrap.cpp +++ b/windows/tools/hresultwrap.cpp @@ -3,11 +3,9 @@ #include #include -#define nbuf 1024 - bool generate(std::vector *genline, FILE *fout) { - std::vector genout(nbuf); + std::vector genout; size_t nw; genout.push_back('/'); @@ -18,7 +16,7 @@ bool generate(std::vector *genline, FILE *fout) genout.push_back('\n'); nw = fwrite(genout.data(), sizeof (char), genout.size(), fout); - return nw != genout.size(); + return nw == genout.size(); } struct process { @@ -73,7 +71,7 @@ size_t stateGenerate(struct process *p, const char *buf, size_t n, FILE *fout) size_t j; if (p->genline == NULL) - p->genline = new std::vector(n); + p->genline = new std::vector; for (j = 0; j < n; j++) if (buf[j] == '\n') // do NOT include the newline this time @@ -82,9 +80,11 @@ size_t stateGenerate(struct process *p, const char *buf, size_t n, FILE *fout) if (j == n) // '\n' not found; not finished with the line yet return j; // finished with the line; process it and continue - p->state = stateNewLine; - if (!generate(p->genline, fout)) + if (!generate(p->genline, fout)) { p->state = stateError; + return 0; + } + p->state = stateNewLine; delete p->genline; p->genline = NULL; // buf[j] == '\n' and generate() took care of printing a newline @@ -106,9 +106,11 @@ bool process(struct process *p, const char *buf, size_t n, FILE *fout) buf += np; n -= np; } - return p->error; + return !p->error; } +#define nbuf 1024 + int main(int argc, char *argv[]) { FILE *fin = NULL, *fout = NULL;