This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "uClibc-ng - small C library for embedded systems".
The branch, master has been updated via e1eceda87b2fa64ab17f3e32c81b9a97edc7cac7 (commit) via 96f2821683ec41a28b5aa6ec92245e47dfee989b (commit) via 568ceebf6adfc58c64a95133311268db626cdec2 (commit) from 0f541b5c48b7b0df80e2aaa8fdbf653a8b8bcd03 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- commit e1eceda87b2fa64ab17f3e32c81b9a97edc7cac7 Author: Max Filippov jcmvbkbc@gmail.com Date: Thu Jun 2 18:24:28 2016 +0300
tests: add %ms scanf format test
Signed-off-by: Max Filippov jcmvbkbc@gmail.com
commit 96f2821683ec41a28b5aa6ec92245e47dfee989b Author: Jan Vangorp jan.vangorp_ext@softathome.com Date: Thu Jun 9 00:00:49 2016 +0200
Fix return value of fwrite when a 'hard' error occurs
When a 'hard' error occurs, fwrite reports that all data was written or buffered even if that is not the case. It should report how much data was actually written and buffered.
Signed-off-by: Jan Vangorp jan.vangorp_ext@softathome.com
commit 568ceebf6adfc58c64a95133311268db626cdec2 Author: Jan Vangorp jan.vangorp_ext@softathome.com Date: Thu Jun 9 00:00:18 2016 +0200
Fix infinite loop when fopencookie custom write returns 0 on error
The man page for fopencookie prescribes that custom write functions should return 0 on error (and should definitely not return a negative value) [1].
However, the uClibc implementation expects a negative return value in case of an error (libc/stdio/_WRITE.c). If the write function returns 0 on error, we drop into an infinite loop if the error persists.
This patch wraps the user supplied write function such that a 0 return value is converted to -1. errno is first set to EAGAIN such that if the custom write function does not set errno in case of error, this is treated as a "soft" error.
Custom write functions that cater towards uClibc and _do_ return a negative value are not affected.
If no custom write function is supplied, set errno to EINVAL such that this condition is treated as a "hard" error. Previously the behaviour depended on whether the last error before the write happened to be a "hard" or a "soft" error.
[1] http://git.kernel.org/cgit/docs/man-pages/man-pages.git/tree/man3/fopencooki...
Signed-off-by: Jan Vangorp jan.vangorp_ext@softathome.com
-----------------------------------------------------------------------
Summary of changes: libc/stdio/_WRITE.c | 1 + libc/stdio/_stdio.h | 15 ++++++++++++++- test/stdio/scanf_m.c | 17 ++++++++++------- 3 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/libc/stdio/_WRITE.c b/libc/stdio/_WRITE.c index 113f0eb..f95bd1b 100644 --- a/libc/stdio/_WRITE.c +++ b/libc/stdio/_WRITE.c @@ -76,6 +76,7 @@ size_t attribute_hidden __stdio_WRITE(register FILE *stream, */ if (errno != EINTR && errno != EAGAIN) { /* do we have other "soft" errors? */ + bufsize -= todo; break; } #ifdef __STDIO_BUFFERS diff --git a/libc/stdio/_stdio.h b/libc/stdio/_stdio.h index 310510d..727e331 100644 --- a/libc/stdio/_stdio.h +++ b/libc/stdio/_stdio.h @@ -110,6 +110,18 @@ do { \ cfile->__gcs.NAME(cfile->__cookie, ##ARGS); \ }
+#define __STDIO_STREAM_CUSTOM_WRITE_FUNC(S, ARGS...) \ + if (__STDIO_STREAM_IS_CUSTOM((S))) { \ + _IO_cookie_file_t *cfile = (_IO_cookie_file_t *) (S); \ + if (cfile->__gcs.write == NULL) { \ + __set_errno(EINVAL); \ + return -1; \ + } \ + __set_errno(EAGAIN); \ + ssize_t w = cfile->__gcs.write(cfile->__cookie, ##ARGS); \ + return (w == 0 ? -1 : w); \ + } + typedef struct { struct __STDIO_FILE_STRUCT __fp; void *__cookie; @@ -121,6 +133,7 @@ typedef struct { #undef __STDIO_STREAM_GLIBC_CUSTOM_FILEDES #define __STDIO_STREAM_IS_CUSTOM(S) (0) #define __STDIO_STREAM_CUSTOM_IO_FUNC(S, NAME, RC, ARGS...) +#define __STDIO_STREAM_CUSTOM_WRITE_FUNC(S, ARGS...)
#endif /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
@@ -135,7 +148,7 @@ static inline ssize_t __READ(FILE *stream, char *buf, size_t bufsize)
static inline ssize_t __WRITE(FILE *stream, const char *buf, size_t bufsize) { - __STDIO_STREAM_CUSTOM_IO_FUNC(stream, write, -1, buf, bufsize); + __STDIO_STREAM_CUSTOM_WRITE_FUNC(stream, buf, bufsize);
return write(stream->__filedes, buf, bufsize); } diff --git a/test/stdio/scanf_m.c b/test/stdio/scanf_m.c index 0ce78b6..e1dde27 100644 --- a/test/stdio/scanf_m.c +++ b/test/stdio/scanf_m.c @@ -5,20 +5,23 @@ int main(void) { const char *buf = "hello world"; - char *ps = NULL, *pc = NULL; - char s[6], c; + char *ps = NULL, *pc = NULL, *ps2 = NULL; + char s[6], c, s2[5];
- /* Check that %[...]/%c work. */ - sscanf(buf, "%[a-z] %c", s, &c); - /* Check that %m[...]/%mc work. */ - sscanf(buf, "%m[a-z] %mc", &ps, &pc); + /* Check that %[...]/%c/%s work. */ + sscanf(buf, "%[a-z] %c %s", s, &c, s2); + /* Check that %m[...]/%mc/%ms work. */ + sscanf(buf, "%m[a-z] %mc %ms", &ps, &pc, &ps2);
if (strcmp(ps, "hello") != 0 || *pc != 'w' || - strcmp(s, "hello") != 0 || c != 'w') + strcmp(ps2, "orld") != 0 || + strcmp(s, "hello") != 0 || c != 'w' || + strcmp(s2, "orld") != 0) return 1;
free(ps); free(pc); + free(ps2);
return 0; }
hooks/post-receive