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 | |
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')
-rw-r--r-- | scanf/sscanf.c | 5 | ||||
-rw-r--r-- | scanf/vsscanf.c | 18 |
2 files changed, 23 insertions, 0 deletions
diff --git a/scanf/sscanf.c b/scanf/sscanf.c index 90824f9a0..64cb976b2 100644 --- a/scanf/sscanf.c +++ b/scanf/sscanf.c @@ -53,7 +53,12 @@ gmp_sscanf (va_alist) fmt = va_arg (ap, const char *); #endif +#if SSCANF_WRITABLE_INPUT + /* let gmp_vsscanf handle the copying */ + ret = gmp_vsscanf (s, fmt, ap); +#else ret = __gmp_doscan (&__gmp_sscanf_funs, (void *) &s, fmt, ap); +#endif va_end (ap); return ret; } 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 } |