diff options
author | Jonas Suhr Christensen <jsc@umbraculum.org> | 2012-03-08 08:43:26 +0100 |
---|---|---|
committer | Jonas Suhr Christensen <jsc@umbraculum.org> | 2012-03-08 08:43:26 +0100 |
commit | 0621a9d2fa2428b15d8e775c8c37b600c592cc57 (patch) | |
tree | 14b160f6ff1b0dd7223bc206fea78259a1088a4c /src | |
parent | 3f048887a4bd12eb7d3ecd972560e2cdfef57405 (diff) |
Using asprintf instead of snprintf.
Diffstat (limited to 'src')
-rw-r--r-- | src/msgparser.cc | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/msgparser.cc b/src/msgparser.cc index c6f83d5..d8c47f7 100644 --- a/src/msgparser.cc +++ b/src/msgparser.cc @@ -249,24 +249,29 @@ msg_t create_msg(cmd::cmd_t type, task_t t) { return m; } -#define BUF_SIZE 4096 +//#define BUF_SIZE 4096 std::string msg_tostring(msg_t m) { - char buf[4096]; +// char buf[4096]; +// buf[0] = '\0'; + char* buf = NULL; switch(m.cmd) { case cmd::add: { - printf("msg: %d, %d, %d, %s, %s\n", m.add.id, m.add.x, m.add.y, m.add.title, m.add.desc); - snprintf(buf, BUF_SIZE, "add %d %s %s %d %d;", + // printf("msg: %d, %d, %d, %s, %s\n", m.add.id, m.add.x, m.add.y, m.add.title, m.add.desc); + // snprintf(buf, BUF_SIZE, "add %d %s %s %d %d;", + asprintf(&buf, "add %d %s %s %d %d;", m.add.id, m.add.title, m.add.desc, m.add.x, m.add.y); break; } case cmd::del: { - snprintf(buf, BUF_SIZE, "del %d;", m.del.id); +// snprintf(buf, BUF_SIZE, "del %d;", m.del.id); + asprintf(&buf, "del %d;", m.del.id); break; } case cmd::move: { - snprintf(buf, BUF_SIZE, "move %d %d %d;", m.move.id, m.move.x, m.move.y); +// snprintf(buf, BUF_SIZE, "move %d %d %d;", m.move.id, m.move.x, m.move.y); + asprintf(&buf, "move %d %d %d;", m.move.id, m.move.x, m.move.y); break; } case cmd::update: { @@ -277,15 +282,15 @@ std::string msg_tostring(msg_t m) { break; } - printf("buffer: %s\n", buf); - + std::string r; if(buf) { - std::string str(buf); - return str; - } - else { - return ""; + r = buf; + free(buf); } + + return r; + +// return buf; } #ifdef TEST_MSGPARSER |