From e1e1b68385af90843e962b68526d679796af78c0 Mon Sep 17 00:00:00 2001 From: laforge Date: Thu, 23 Aug 2007 04:44:29 +0000 Subject: fix mlbuf handling (Phillip Zabel) git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@2806 99fdad57-331a-0410-800a-d7fa5415bdb3 --- src/gsmd/atcmd.c | 10 +++++----- src/gsmd/gsmd.c | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'src/gsmd') diff --git a/src/gsmd/atcmd.c b/src/gsmd/atcmd.c index 37c8538..2ef6a10 100644 --- a/src/gsmd/atcmd.c +++ b/src/gsmd/atcmd.c @@ -370,8 +370,8 @@ static int ml_parse(const char *buf, int len, void *ctx) if (g->mlbuf_len) g->mlbuf[g->mlbuf_len ++] = '\n'; DEBUGP("Appending buf to mlbuf\n"); - if (len > sizeof(g->mlbuf) - g->mlbuf_len) - len = sizeof(g->mlbuf) - g->mlbuf_len; + if (len > MLPARSE_BUF_SIZE - g->mlbuf_len) + len = MLPARSE_BUF_SIZE - g->mlbuf_len; memcpy(g->mlbuf + g->mlbuf_len, buf, len); g->mlbuf_len += len; @@ -470,7 +470,7 @@ static int atcmd_select_cb(int fd, unsigned int what, void *data) if (cr) len = cr - pos->cur; else - len = pos->buflen; + len = pos->buflen - 1; /* assuming zero-terminated strings */ rc = write(fd, pos->cur, len); if (rc == 0) { gsmd_log(GSMD_ERROR, "write returns 0, aborting\n"); @@ -480,8 +480,8 @@ static int atcmd_select_cb(int fd, unsigned int what, void *data) fd, rc); return rc; } - if (cr && rc == len) - rc ++; /* Skip the \n */ + if (!cr || rc == len) + rc ++; /* Skip the \n or \0 */ pos->buflen -= rc; pos->cur += rc; write(fd, "\r", 1); diff --git a/src/gsmd/gsmd.c b/src/gsmd/gsmd.c index 2be6d79..51b4f2c 100644 --- a/src/gsmd/gsmd.c +++ b/src/gsmd/gsmd.c @@ -301,6 +301,10 @@ static int gsmd_initialize(struct gsmd *g) { INIT_LLIST_HEAD(&g->users); + g->mlbuf = talloc_array(gsmd_tallocs, unsigned char, MLPARSE_BUF_SIZE); + if (!g->mlbuf) + return -ENOMEM; + return 0; } -- cgit v1.2.3