Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Sun, 25 Oct 2015 15:09:21 UTC Commit: 4335804d236bd43d7545a48272fd313adc36ce1f https://github.com/geany/geany/commit/4335804d236bd43d7545a48272fd313adc36ce...
Log Message: ----------- Merge branch 'mio/update'
Manually import some upstream MIO changes.
Modified Paths: -------------- tagmanager/mio/mio-file.c tagmanager/mio/mio-memory.c tagmanager/mio/mio.h
Modified: tagmanager/mio/mio-file.c 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -92,6 +92,7 @@ file_puts (MIO *mio, return fputs (s, mio->impl.file.fp); }
+G_GNUC_PRINTF (2, 0) static gint file_vprintf (MIO *mio, const gchar *format,
Modified: tagmanager/mio/mio-memory.c 41 lines changed, 21 insertions(+), 20 deletions(-) =================================================================== @@ -73,34 +73,34 @@ mem_free (MIO *mio)
static gsize mem_read (MIO *mio, - void *ptr, + void *ptr_, gsize size, gsize nmemb) { gsize n_read = 0;
if (size != 0 && nmemb != 0) { - if (mio->impl.mem.ungetch != EOF) { - *((guchar *)ptr) = (guchar)mio->impl.mem.ungetch; - mio->impl.mem.ungetch = EOF; - mio->impl.mem.pos++; - if (size == 1) { - n_read++; - } else if (mio->impl.mem.pos + (size - 1) <= mio->impl.mem.size) { - memcpy (&(((guchar *)ptr)[1]), - &mio->impl.mem.buf[mio->impl.mem.pos], size - 1); - mio->impl.mem.pos += size - 1; - n_read++; - } + gsize size_avail = mio->impl.mem.size - mio->impl.mem.pos; + gsize copy_bytes = size * nmemb; + guchar *ptr = ptr_; + + if (size_avail < copy_bytes) { + copy_bytes = size_avail; } - for (; n_read < nmemb; n_read++) { - if (mio->impl.mem.pos + size > mio->impl.mem.size) { - break; - } else { - memcpy (&(((guchar *)ptr)[n_read * size]), - &mio->impl.mem.buf[mio->impl.mem.pos], size); - mio->impl.mem.pos += size; + + if (copy_bytes > 0) { + n_read = copy_bytes / size; + + if (mio->impl.mem.ungetch != EOF) { + *ptr = (guchar) mio->impl.mem.ungetch; + mio->impl.mem.ungetch = EOF; + copy_bytes--; + mio->impl.mem.pos++; + ptr++; } + + memcpy (ptr, &mio->impl.mem.buf[mio->impl.mem.pos], copy_bytes); + mio->impl.mem.pos += copy_bytes; } if (mio->impl.mem.pos >= mio->impl.mem.size) { mio->impl.mem.eof = TRUE; @@ -241,6 +241,7 @@ mem_puts (MIO *mio, return rv; }
+G_GNUC_PRINTF (2, 0) static gint mem_vprintf (MIO *mio, const gchar *format,
Modified: tagmanager/mio/mio.h 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -145,7 +145,7 @@ struct _MIO { const gchar *s); gint (*v_vprintf) (MIO *mio, const gchar *format, - va_list ap); + va_list ap) G_GNUC_PRINTF (2, 0); void (*v_clearerr) (MIO *mio); gint (*v_eof) (MIO *mio); gint (*v_error) (MIO *mio); @@ -198,7 +198,7 @@ gint mio_puts (MIO *mio,
gint mio_vprintf (MIO *mio, const gchar *format, - va_list ap); + va_list ap) G_GNUC_PRINTF (2, 0); gint mio_printf (MIO *mio, const gchar *format, ...) G_GNUC_PRINTF (2, 3);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).