X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgmemoryoutputstream.c;h=a89701d6010dc1d0c5aa2b2541a01216743ed61d;hb=d9ad40b4eaf1a9197ab363de4346a8d84f45f5c1;hp=bef639778519d924e25db2291425bb5a3b8edfdc;hpb=078dbda148a81af1b3a76fbda72f089b963087f1;p=platform%2Fupstream%2Fglib.git diff --git a/gio/gmemoryoutputstream.c b/gio/gmemoryoutputstream.c index bef6397..a89701d 100644 --- a/gio/gmemoryoutputstream.c +++ b/gio/gmemoryoutputstream.c @@ -367,19 +367,19 @@ g_memory_output_stream_init (GMemoryOutputStream *stream) * @size as 0 (allowing #GMemoryOutputStream to do the initial * allocation for itself). * - * |[ - * /* a stream that can grow */ + * |[ + * // a stream that can grow * stream = g_memory_output_stream_new (NULL, 0, realloc, free); * - * /* another stream that can grow */ + * // another stream that can grow * stream2 = g_memory_output_stream_new (NULL, 0, g_realloc, g_free); * - * /* a fixed-size stream */ + * // a fixed-size stream * data = malloc (200); * stream3 = g_memory_output_stream_new (data, 200, NULL, free); * ]| * - * Return value: A newly created #GMemoryOutputStream object. + * Returns: A newly created #GMemoryOutputStream object. **/ GOutputStream * g_memory_output_stream_new (gpointer data, @@ -594,12 +594,12 @@ array_resize (GMemoryOutputStream *ostream, return TRUE; } -static gint -g_nearest_pow (gint num) +static gsize +g_nearest_pow (gsize num) { - gint n = 1; + gsize n = 1; - while (n < num) + while (n < num && n > 0) n <<= 1; return n; @@ -639,12 +639,10 @@ g_memory_output_stream_write (GOutputStream *stream, * much memory. */ new_size = g_nearest_pow (priv->pos + count); - /* Check for overflow again. We have only checked if - pos + count > G_MAXSIZE, but it only catches the case of writing - more than 4GiB total on a 32-bit system. There's still the problem - of g_nearest_pow overflowing above 0x7fffffff, so we're - effectively limited to 2GiB. */ - if (new_size < priv->len) + /* Check for overflow again. We have checked if + pos + count > G_MAXSIZE, but now check if g_nearest_pow () has + overflowed */ + if (new_size == 0) goto overflow; new_size = MAX (new_size, MIN_ARRAY_SIZE);