Skip to content

Differential code coverage: genhtml - range error #408

@smallSwed

Description

@smallSwed

genhtml throws range error when the baseline source file had coverage data for lines with larger numbers than the size of the current version of the file.
Scenario: there is a refactor of a code, some functions/code are removed so those are no longer exists, but in the baseline .info file still has coverage data for it.
I can workaround it by using the --ignore-error range option, but I would assume this should work because the udiff.txt contains the information on the line changes.

I'm using the lcov 2.3.1.

The Error log

...
Processing file exampleRepo/methods/iterate.c (source code changed)
  lines=7 hit=5 functions=1 hit=1 branches=4 hit=3
genhtml: ERROR: (range) /home/sok/Downloads/lcov-2.3.1/example/exampleRepo/methods/iterate.c contains only 38 lines but coverage data refers to line 48
        (use "genhtml --ignore-errors range ..." to bypass this error)
make: *** [Makefile:177: test_differential] Error 1

Small reproducible example, using the "example" from lcov repository itself:

  1. copy paste the content below to the iterate.c file (baseline)

iterate.c

 /*
 *  methods/iterate.c
 *  
 *  Calculate the sum of a given range of integer numbers.
 *
 *  This particular method of implementation works by way of brute force,
 *  i.e. it iterates over the entire range while adding the numbers to finally
 *  get the total sum. As a positive side effect, we're able to easily detect
 *  overflows, i.e. situations in which the sum would exceed the capacity
 *  of an integer variable.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "iterate.h"

int some_execution(int a);
int iterate_get_sum (int min, int max)
{
        int i, total;
        total = some_execution(max);
        total = 0;

        /* This is where we loop over each number in the range, including
           both the minimum and the maximum number. */

        for (i = min; i <= max; i++)
        {
                /* We can detect an overflow by checking whether the new
                   sum would exceed the maximum integer value. */

                if (total > INT_MAX - i)
                {
                        printf ("Error: sum too large!\n");
                        exit (1);
                }

                /* Everything seems to fit into an int, so continue adding. */

                total += i;
        }

        return total;
}

int some_execution(int a)
{
        return a+a;
}

  1. execute the make for the example project
  2. see error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions