summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorenge <enge@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2009-03-19 18:26:02 +0000
committerenge <enge@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2009-03-19 18:26:02 +0000
commit1421de48321354f493ac5fe173a89824bf27c0ae (patch)
tree6a5779c10e016c46e8ab645c11c554b87beb5c33
parent32d1a5f3854f6705982545a17694ae4e33a902ca (diff)
downloadmpc-1421de48321354f493ac5fe173a89824bf27c0ae.tar.gz
inp_str:
bug fix with string freeing prepared for returning nonary value git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@485 211d60ee-9f03-0410-a15a-8952a2c7a4e4
-rw-r--r--src/inp_str.c28
1 files changed, 11 insertions, 17 deletions
diff --git a/src/inp_str.c b/src/inp_str.c
index 5986bce..4f7cec4 100644
--- a/src/inp_str.c
+++ b/src/inp_str.c
@@ -55,18 +55,10 @@ mpc_realloc_str (char * str, size_t oldlen, size_t newlen) {
}
-static void
-mpc_free_str_len (char *str, size_t len) {
- void (*freefunc) (void *, size_t);
- mp_get_memory_functions (NULL, NULL, &freefunc);
- (*freefunc) (str, len * sizeof (char));
-}
-
-
-
size_t
mpc_inp_str (mpc_ptr rop, FILE *stream, int base, mpc_rnd_t rnd_mode) {
size_t white, nread;
+ int inex = -1;
int c;
int par = 0;
@@ -102,16 +94,18 @@ mpc_inp_str (mpc_ptr rop, FILE *stream, int base, mpc_rnd_t rnd_mode) {
else /* put whitespace back into stream */
ungetc (c, stream);
str = mpc_realloc_str (str, strsize, nread + 1);
+ strsize = nread + 1;
str [nread] = '\0';
- if (mpc_set_str (rop, str, base, rnd_mode) != -1) {
- mpc_free_str_len (str, strsize);
- return white + nread;
- }
+ inex = mpc_set_str (rop, str, base, rnd_mode);
}
- mpc_free_str_len (str, strsize);
+ mpc_free_str (str);
}
- mpfr_set_nan (MPC_RE(rop));
- mpfr_set_nan (MPC_IM(rop));
- return 0;
+ if (inex == -1) {
+ mpfr_set_nan (MPC_RE(rop));
+ mpfr_set_nan (MPC_IM(rop));
+ return 0;
+ }
+ else
+ return white + nread;
}