diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2013-10-13 11:44:26 +0200 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2013-10-13 11:44:26 +0200 |
commit | 1dc9569e31717aefab8e05b858122f433dab1698 (patch) | |
tree | 1367e5dcbdb785a4fd2c34c936a9f780b565e3e6 /src/modules/systemlib/mixer/mixer_load.c | |
parent | 42b75ae8963b2f711a72ac1cb6cfd1b44bd826b2 (diff) | |
download | px4-firmware-1dc9569e31717aefab8e05b858122f433dab1698.tar.gz px4-firmware-1dc9569e31717aefab8e05b858122f433dab1698.tar.bz2 px4-firmware-1dc9569e31717aefab8e05b858122f433dab1698.zip |
Fixed mixer chunk load and line ending detection for good.
Diffstat (limited to 'src/modules/systemlib/mixer/mixer_load.c')
-rw-r--r-- | src/modules/systemlib/mixer/mixer_load.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/modules/systemlib/mixer/mixer_load.c b/src/modules/systemlib/mixer/mixer_load.c index 18c4e474a..a55ddf8a3 100644 --- a/src/modules/systemlib/mixer/mixer_load.c +++ b/src/modules/systemlib/mixer/mixer_load.c @@ -38,22 +38,22 @@ */ #include <nuttx/config.h> -#include <systemlib/err.h> #include <string.h> #include <stdio.h> #include <ctype.h> #include "mixer_load.h" -int load_mixer_file(const char *fname, char *buf) +int load_mixer_file(const char *fname, char *buf, unsigned maxlen) { FILE *fp; char line[120]; /* open the mixer definition file */ fp = fopen(fname, "r"); - if (fp == NULL) - err(1, "can't open %s", fname); + if (fp == NULL) { + return 1; + } /* read valid lines from the file into a buffer */ buf[0] = '\0'; @@ -70,7 +70,7 @@ int load_mixer_file(const char *fname, char *buf) /* compact whitespace in the buffer */ char *t, *f; - for (f = buf; *f != '\0'; f++) { + for (f = line; *f != '\0'; f++) { /* scan for space characters */ if (*f == ' ') { /* look for additional spaces */ @@ -87,8 +87,9 @@ int load_mixer_file(const char *fname, char *buf) } /* if the line is too long to fit in the buffer, bail */ - if ((strlen(line) + strlen(buf) + 1) >= sizeof(buf)) - break; + if ((strlen(line) + strlen(buf) + 1) >= maxlen) { + return 1; + } /* add the line to the buffer */ strcat(buf, line); |