cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, STM Community, Error in TouchGFX example with STM32F769NI.

Vins
Senior

Errors are:

1) C:/Users/info/STM32CubeIDE/workspace_1.7.0/TouchGFX/Gui/gui/src/audio_player_screen/AudioPlayerPresenter.cpp:102:12: error: 'char* strncpy(char*, const char*, size_t)' specified bound 50 equals destination size [-Werror=stringop-truncation]

2) C:/Users/info/STM32CubeIDE/workspace_1.7.0/TouchGFX/Gui/gui/src/audio_player_screen/AudioPlayerPresenter.cpp:266:12: error: 'char* strncpy(char*, const char*, size_t)' specified bound 50 equals destination size [-Werror=stringop-truncation]

3)

C:/Users/info/STM32CubeIDE/workspace_1.7.0/TouchGFX/Gui/gui/src/audio_player_screen/AudioPlayerPresenter.cpp:550:20: error: 'char* strncpy(char*, const char*, size_t)' specified bound 50 equals destination size [-Werror=stringop-truncation]

4)

C:/Users/info/STM32CubeIDE/workspace_1.7.0/TouchGFX/Gui/gui/src/audio_player_screen/AudioPlayerPresenter.cpp:138:12: error: 'char* strncpy(char*, const char*, size_t)' output may be truncated copying 40 bytes from a string of length 49 [-Werror=stringop-truncation]

5)

C:/Users/info/STM32CubeIDE/workspace_1.7.0/TouchGFX/Gui/gui/src/audio_player_screen/AudioPlayerPresenter.cpp:476:11: error: 'char* strcat(char*, const char*)' accessing 3325 or more bytes at offsets [1296, 2512] and 4620 may overlap 1 byte at offset [4620, 2147483647] [-Werror=restrict]

6)

make: *** [Application/User/TouchGFX/gui/subdir.mk:240: Application/User/TouchGFX/gui/AudioPlayerPresenter.o] Error 1

7)

make: *** Waiting for unfinished jobs....

1 ACCEPTED SOLUTION

Accepted Solutions
RKOUKI
Associate

Hi @Vins​,

First I would like to thank you for having reported this point.

In fact, these compilation errors are related to the requirement that the destination buffer be determined by a null character.  Indeed, if the length of source string is less than the size n of the destination buffer, strncpy() function writes an additional null character at the end of the destination buffer to ensure that a total of n bytes are written. In order to solve the detected errors, the following update should be proposed:

  • For errors N°1, 2, & 3 (Lines 102, 266 & 550) in the AudioPlayerPresenter.cpp file:

  - char copy[50];

+ char copy[60];

char unknown[10];

- strncpy(copy, fullname, 50);

+ strncpy(copy, fullname, sizeof(copy) - 1);

  • For error N°4 (Line 138) in the AudioPlayerPresenter.cpp file:

The size of the FOLDERNAME_LENGTH parameter could be updated in the CommonDefinitions.hpp file from 40 to 50.

On the other hand, using the strncat() function instead of the strcat() function can resolve other detected errors that are related to the strcat() function. In fact, the strncat() function is similar to strcat() , except that the first one will use at most n bytes of the source string and does not need to be terminated by a null character if it contains n or more bytes. So, the proposed update could be:

  • Concerning the error N°5 (Line 476) in the AudioPlayerPresenter.cpp file and the error N°6 (Line 234) in the VideoPlayerView.cpp file:

- strcat(playlist[pl_index].filename, currentFolder);

+ strncat(playlist[pl_index].filename, currentFolder, sizeof(playlist[pl_index].filename) - 1);

I hope the fix I provided you with was helpful. Thank you again for your report. Do not hesitate in case you have other questions. 

With regards,

View solution in original post

5 REPLIES 5
Amel NASRI
ST Employee

Hi @Vins​ ,

Could you please precise:

  1. the example you are using?
  2. the STM32CubeF7 package version (latest one is 1.16.1)?

Thanks.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Vins
Senior

Hi @Amel NASRI​ ,

  1. The example - TouchGFX- STM32F769I-Discovery.
  2. STM32Cube_FW_F7_V1.16.0 / STM32Cube_FW_F7_V1.16.1 (Errors in both)

Thanks.

Vinayak.

Hi @Vins​ ,

It seems that the project wasn't imported properly from SW4STM32 to STM32CubeIDE.

I reproduced the issue and reported it to development team.

Internal ticket number: 112273 (PS: This is an internal tracking number and is not accessible or usable by customers)

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Vins
Senior

Hi @Amel NASRI​ ,

Thank you for your reply.

Checked with 2-3 engineers in different systems, but getting the same errors.

Looking forward for the solution.

Thank you.

Vinayak.

RKOUKI
Associate

Hi @Vins​,

First I would like to thank you for having reported this point.

In fact, these compilation errors are related to the requirement that the destination buffer be determined by a null character.  Indeed, if the length of source string is less than the size n of the destination buffer, strncpy() function writes an additional null character at the end of the destination buffer to ensure that a total of n bytes are written. In order to solve the detected errors, the following update should be proposed:

  • For errors N°1, 2, & 3 (Lines 102, 266 & 550) in the AudioPlayerPresenter.cpp file:

  - char copy[50];

+ char copy[60];

char unknown[10];

- strncpy(copy, fullname, 50);

+ strncpy(copy, fullname, sizeof(copy) - 1);

  • For error N°4 (Line 138) in the AudioPlayerPresenter.cpp file:

The size of the FOLDERNAME_LENGTH parameter could be updated in the CommonDefinitions.hpp file from 40 to 50.

On the other hand, using the strncat() function instead of the strcat() function can resolve other detected errors that are related to the strcat() function. In fact, the strncat() function is similar to strcat() , except that the first one will use at most n bytes of the source string and does not need to be terminated by a null character if it contains n or more bytes. So, the proposed update could be:

  • Concerning the error N°5 (Line 476) in the AudioPlayerPresenter.cpp file and the error N°6 (Line 234) in the VideoPlayerView.cpp file:

- strcat(playlist[pl_index].filename, currentFolder);

+ strncat(playlist[pl_index].filename, currentFolder, sizeof(playlist[pl_index].filename) - 1);

I hope the fix I provided you with was helpful. Thank you again for your report. Do not hesitate in case you have other questions. 

With regards,