diff options
author | Kevin Ryde <user42@zip.com.au> | 2001-11-24 22:08:33 +0100 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2001-11-24 22:08:33 +0100 |
commit | 3c08878a3730e8a76369977262a5a8ab534fde7b (patch) | |
tree | 793221864d1b710504d8454241984c9f1f4ef8d8 /scanf/vsscanf.c | |
parent | b87e10c51477ff6d5fd300529485206b2a2dac0a (diff) | |
download | gmp-3c08878a3730e8a76369977262a5a8ab534fde7b.tar.gz |
* acinclude.m4, configure.in (GMP_FUNC_SSCANF_WRITABLE_INPUT): New
test.
* scanf/sscanf.c, scanf/vsscanf.c: Use it to ensure sscanf input is
writable, if necessary.
Diffstat (limited to 'scanf/vsscanf.c')
-rw-r--r-- | scanf/vsscanf.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/scanf/vsscanf.c b/scanf/vsscanf.c index d9d2a9c16..62e378004 100644 --- a/scanf/vsscanf.c +++ b/scanf/vsscanf.c @@ -34,5 +34,23 @@ MA 02111-1307, USA. */ int gmp_vsscanf (const char *s, const char *fmt, va_list ap) { +#if SSCANF_WRITABLE_INPUT + /* We only actually need this if there's standard C types in fmt, and if + "s" is not already writable, but it's too much trouble to check that, + and in any case this writable sscanf input business is only for a few + old systems. */ + size_t size; + char *alloc; + int ret; + size = strlen (s) + 1; + alloc = (char *) (*__gmp_allocate_func) (size); + memcpy (alloc, s, size); + s = alloc; + ret = __gmp_doscan (&__gmp_sscanf_funs, (void *) &s, fmt, ap); + (*__gmp_free_func) (alloc, size); + return ret; + +#else return __gmp_doscan (&__gmp_sscanf_funs, (void *) &s, fmt, ap); +#endif } |