[PATCH v2] covoar/ Explanations.cc: Handle newline at end of file

Chris Johns chrisj at rtems.org
Fri Jun 25 08:08:14 UTC 2021


OK

On 25/6/21 1:37 pm, Alex White wrote:
> ---
>  tester/covoar/Explanations.cc | 24 +++++++++++-------------
>  1 file changed, 11 insertions(+), 13 deletions(-)
> 
> diff --git a/tester/covoar/Explanations.cc b/tester/covoar/Explanations.cc
> index 1449fb2..4d177eb 100644
> --- a/tester/covoar/Explanations.cc
> +++ b/tester/covoar/Explanations.cc
> @@ -85,26 +85,24 @@ namespace Coverage {
>        line++;
>  
>        // Get the explanation
> -      while (1) {
> -        explain.getline( inputBuffer, MAX_LINE_LENGTH );
> -        // fprintf( stderr, "%d - %s\n", line, inputBuffer );
> -        if (explain.fail()) {
> -          std::ostringstream what;
> -          what << "line " << line
> -               << "out of sync at the explanation";
> -          throw rld::error( what, "Explanations::load" );
> -        }
> -        inputBuffer[ strlen(inputBuffer) - 1] = '\0';
> +      for (std::string input_line; std::getline( explain, input_line ); ) {
>          line++;
>  
> -        const char delimiter[4] = "+++";
> -        if (!strncmp( inputBuffer, delimiter, 3 )) {
> +        const std::string delimiter = "+++";
> +        if (input_line.compare( delimiter ) == 0) {
>            break;
>          }
>          // XXX only taking last line.  Needs to be a vector
> -        e.explanation.push_back( inputBuffer );
> +        e.explanation.push_back( input_line );
>        }
>  
> +        if (explain.fail()) {
> +          std::ostringstream what;
> +          what << "line " << line
> +               << "out of sync at the explanation";
> +          throw rld::error( what, "Explanations::load" );
> +        }
> +
>        // Add this to the set of Explanations
>        set[ e.startingPoint ] = e;
>      }
> 


More information about the devel mailing list