summaryrefslogtreecommitdiff
path: root/src/gsmd
diff options
context:
space:
mode:
authorlaforge <laforge@99fdad57-331a-0410-800a-d7fa5415bdb3>2007-08-23 04:44:29 +0000
committerlaforge <laforge@99fdad57-331a-0410-800a-d7fa5415bdb3>2007-08-23 04:44:29 +0000
commite1e1b68385af90843e962b68526d679796af78c0 (patch)
treec8f5dab6d8108e1d64972e2f6d08d4d8ddb9861b /src/gsmd
parent7814f977e3043f64c1a80f0449a2e26147510caf (diff)
fix mlbuf handling (Phillip Zabel)
git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@2806 99fdad57-331a-0410-800a-d7fa5415bdb3
Diffstat (limited to 'src/gsmd')
-rw-r--r--src/gsmd/atcmd.c10
-rw-r--r--src/gsmd/gsmd.c4
2 files changed, 9 insertions, 5 deletions
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;
}
personal git repositories of Harald Welte. Your mileage may vary