RE: [PATCH rtems-tools v1 4/7] TraceReaderLogQEMU.cc: Fix formatting

2021-09-23 Thread Ryan Long
Both of those definitions of discardBuff do the same thing. The form of value 
initializing in the example I showed was introduced in C++11. It was put in to 
zero out templated objects evidently. I just saw it on stackoverflow. :)

-Original Message-
From: Chris Johns  
Sent: Wednesday, September 22, 2021 7:24 PM
To: Ryan Long ; devel@rtems.org
Subject: Re: [PATCH rtems-tools v1 4/7] TraceReaderLogQEMU.cc: Fix formatting

On 23/9/21 12:35 am, Ryan Long wrote:
> I changed the definition of discardBuff to
> 
> char discardBuff[100]{};

char discardBuff[100] = {};

?

> So that every element will be initialized to \0. This function is only 
> used in TraceReaderLogQEMU.cc, and the values that are passed in are
> 
> #define QEMU_LOG_IN_KEY "IN: "
> #define QEMU_LOG_SECTION_END ""
> 
> Neither are close to going over the size of discardBuff, but I can add a 
> check and return false if it does happen to go over that length.

Checking how the call is being used is cheating ... :)

Lets make the code robust and if someone makes a change and makes a mistake it 
is caught.

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH rtems-tools v1 4/7] TraceReaderLogQEMU.cc: Fix formatting

2021-09-22 Thread Chris Johns
On 23/9/21 12:35 am, Ryan Long wrote:
> I changed the definition of discardBuff to
> 
> char discardBuff[100]{};

char discardBuff[100] = {};

?

> So that every element will be initialized to \0. This function is only used 
> in TraceReaderLogQEMU.cc, and the values that are passed in are
> 
> #define QEMU_LOG_IN_KEY "IN: "
> #define QEMU_LOG_SECTION_END ""
> 
> Neither are close to going over the size of discardBuff, but I can add a 
> check and return false if it does happen to go over that length.

Checking how the call is being used is cheating ... :)

Lets make the code robust and if someone makes a change and makes a mistake it
is caught.

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


RE: [PATCH rtems-tools v1 4/7] TraceReaderLogQEMU.cc: Fix formatting

2021-09-22 Thread Ryan Long
I changed the definition of discardBuff to

char discardBuff[100]{};

So that every element will be initialized to \0. This function is only used in 
TraceReaderLogQEMU.cc, and the values that are passed in are

#define QEMU_LOG_IN_KEY "IN: "
#define QEMU_LOG_SECTION_END ""

Neither are close to going over the size of discardBuff, but I can add a check 
and return false if it does happen to go over that length.

-Original Message-
From: Chris Johns  
Sent: Tuesday, September 21, 2021 6:16 PM
To: Ryan Long ; devel@rtems.org
Subject: Re: [PATCH rtems-tools v1 4/7] TraceReaderLogQEMU.cc: Fix formatting

On 22/9/21 2:45 am, Ryan Long wrote:
> ---
>  tester/covoar/TraceReaderLogQEMU.cc | 25 +
>  1 file changed, 13 insertions(+), 12 deletions(-)
> 
> diff --git a/tester/covoar/TraceReaderLogQEMU.cc 
> b/tester/covoar/TraceReaderLogQEMU.cc
> index c303d08..91ed5c7 100644
> --- a/tester/covoar/TraceReaderLogQEMU.cc
> +++ b/tester/covoar/TraceReaderLogQEMU.cc
> @@ -53,8 +53,8 @@
>  
>  bool ReadUntilFound( std::ifstream& file, const char* line )  {
> -  char discardBuff[100];
> -  size_t  len = strlen( line );
> +  char   discardBuff[100];

100 bytes on the stack and not initialised ...

> +  size_t len = strlen( line );>
>do {
>  file.read( discardBuff, 99 );

Read one less than the buffer so index 99 is still not initialised ...

> @@ -62,9 +62,11 @@ bool ReadUntilFound( std::ifstream& file, const char* line 
> )
>return false;
>  }
>  
> -if ( strncmp( discardBuff, line, len ) == 0 )
> +if ( strncmp( discardBuff, line, len ) == 0 ) {

Making a call that assumes index 99 is '\0'! Does the discard buffer need to be 
memset to 0?

What if the length of line is greater than 100? Is that a valid find and so a 
partial match is OK? Do the lengths need to match?

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH rtems-tools v1 4/7] TraceReaderLogQEMU.cc: Fix formatting

2021-09-21 Thread Chris Johns
On 22/9/21 2:45 am, Ryan Long wrote:
> ---
>  tester/covoar/TraceReaderLogQEMU.cc | 25 +
>  1 file changed, 13 insertions(+), 12 deletions(-)
> 
> diff --git a/tester/covoar/TraceReaderLogQEMU.cc 
> b/tester/covoar/TraceReaderLogQEMU.cc
> index c303d08..91ed5c7 100644
> --- a/tester/covoar/TraceReaderLogQEMU.cc
> +++ b/tester/covoar/TraceReaderLogQEMU.cc
> @@ -53,8 +53,8 @@
>  
>  bool ReadUntilFound( std::ifstream& file, const char* line )
>  {
> -  char discardBuff[100];
> -  size_t  len = strlen( line );
> +  char   discardBuff[100];

100 bytes on the stack and not initialised ...

> +  size_t len = strlen( line );>
>do {
>  file.read( discardBuff, 99 );

Read one less than the buffer so index 99 is still not initialised ...

> @@ -62,9 +62,11 @@ bool ReadUntilFound( std::ifstream& file, const char* line 
> )
>return false;
>  }
>  
> -if ( strncmp( discardBuff, line, len ) == 0 )
> +if ( strncmp( discardBuff, line, len ) == 0 ) {

Making a call that assumes index 99 is '\0'! Does the discard buffer need to be
memset to 0?

What if the length of line is greater than 100? Is that a valid find and so a
partial match is OK? Do the lengths need to match?

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel