> As suggested by Honza, avoid bloating libgcov from gcc_assert by using
> a new macro gcov_nonruntime_assert in gcov-io.c that is only mapped to
> gcc_assert when not in libgcov.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu. Ok for trunk?
> 
> Thanks,
> Teresa
> 
> 2014-01-09  Teresa Johnson  <tejohn...@google.com>
> 
>         * gcov-io.c (gcov_position): Use gcov_nonruntime_assert.
>         (gcov_is_error): Ditto.
>         (gcov_rewrite): Ditto.
>         (gcov_open): Ditto.
>         (gcov_write_words): Ditto.
>         (gcov_write_length): Ditto.
>         (gcov_read_words): Ditto.
>         (gcov_read_summary): Ditto.
>         (gcov_sync): Ditto.
>         (gcov_seek): Ditto.
>         (gcov_histo_index): Ditto.
>         (static void gcov_histogram_merge): Ditto.
>         (compute_working_sets): Ditto.
>         * gcov-io.h (gcov_nonruntime_assert): Define.
> 

> @@ -481,14 +481,14 @@ gcov_read_words (unsigned words)
>    const gcov_unsigned_t *result;
>    unsigned excess = gcov_var.length - gcov_var.offset;
> 
> -  gcc_assert (gcov_var.mode > 0);
> +  gcov_nonruntime_assert (gcov_var.mode > 0);
>    if (excess < words)
>      {
>        gcov_var.start += gcov_var.offset;
>  #if IN_LIBGCOV
>        if (excess)
>         {
> -         gcc_assert (excess == 1);
> +         gcov_nonruntime_assert (excess == 1);

It probably makes no sense to put nonruntime access into IN_LIBGCOV defines.

>           memcpy (gcov_var.buffer, gcov_var.buffer + gcov_var.offset, 4);
>         }
>  #else
> @@ -497,7 +497,7 @@ gcov_read_words (unsigned words)
>        gcov_var.offset = 0;
>        gcov_var.length = excess;
>  #if IN_LIBGCOV
> -      gcc_assert (!gcov_var.length || gcov_var.length == 1);
> +      gcov_nonruntime_assert (!gcov_var.length || gcov_var.length == 1);
>        excess = GCOV_BLOCK_SIZE;
>  #else
>        if (gcov_var.length + words > gcov_var.alloc)
> @@ -614,7 +614,7 @@ gcov_read_summary (struct gcov_summary *summary)
>            while (!cur_bitvector)
>              {
>                h_ix = bv_ix * 32;
> -              gcc_assert (bv_ix < GCOV_HISTOGRAM_BITVECTOR_SIZE);
> +              gcov_nonruntime_assert (bv_ix < GCOV_HISTOGRAM_BITVECTOR_SIZE);
>                cur_bitvector = histo_bitvector[bv_ix++];
>              }
>            while (!(cur_bitvector & 0x1))
> @@ -622,7 +622,7 @@ gcov_read_summary (struct gcov_summary *summary)
>                h_ix++;
>                cur_bitvector >>= 1;
>              }
> -          gcc_assert (h_ix < GCOV_HISTOGRAM_SIZE);
> +          gcov_nonruntime_assert (h_ix < GCOV_HISTOGRAM_SIZE);

How many of those asserts can be triggered by a corrupted gcda file?
I would like to make libgcov more safe WRT file corruptions, too, so in that
case we should produce an error message.

The rest of changes seems OK.

Honza

Reply via email to