[PATCH rtems-tools v2 2/7] TraceReader: Convert to C++
Chris Johns
chrisj at rtems.org
Fri Sep 24 02:24:17 UTC 2021
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