[PATCH rtems-tools v2 2/7] TraceReader: Convert to C++

Ryan Long ryan.long at oarcorp.com
Fri Sep 24 13:20:06 UTC 2021


Whoops. Not sure what happened there. I had it in earlier. I'll change it to sizeof() and resubmit.

-----Original Message-----
From: Chris Johns <chrisj at rtems.org> 
Sent: Thursday, September 23, 2021 9:24 PM
To: Ryan Long <ryan.long at oarcorp.com>; devel at rtems.org
Subject: Re: [PATCH rtems-tools v2 2/7] TraceReader: Convert to C++

On 24/9/21 7:26 am, Ryan Long wrote:
> -bool ReadUntilFound( FILE *file, const char *line )
> +bool ReadUntilFound( std::ifstream& file, const char* line )
>  {
> -  char discardBuff[100];
> -  size_t  len = strlen( line );
> +  #define BUFFER_LENGTH

There is no value?

> +  char   discardBuff[BUFFER_LENGTH] = {};

In most cases I prefer this because it saves adding a define ...

  char   discardBuff[100] = {}

> +  size_t len = strlen( line );
> +
> +  if ( len > BUFFER_LENGTH ) {

then ...

  if ( len > sizeof(discardBuff) ) {

> +    std::cerr << "ReadUntilFound(): parameter 'line' is too long" << std::endl;
> +    return false;
> +  }
>  
>    do {
> -    if ( !fgets( discardBuff, 99, file ) )
> +    file.read( discardBuff, BUFFER_LENGTH - 2 );

sizeof(discardBuff) here as well.

Chris


More information about the devel mailing list