2021-08-10 06:13 AM
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....
Solved! Go to Solution.
2021-09-30 09:13 AM
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:
- char copy[50];
+ char copy[60];
char unknown[10];
- strncpy(copy, fullname, 50);
+ strncpy(copy, fullname, sizeof(copy) - 1);
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:
- 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,
2021-08-19 07:26 AM
Hi @Vins ,
Could you please precise:
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.
2021-08-23 03:03 AM
Hi @Amel NASRI ,
Thanks.
Vinayak.
2021-08-24 03:42 AM
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.
2021-08-25 05:07 AM
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.
2021-09-30 09:13 AM
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:
- char copy[50];
+ char copy[60];
char unknown[10];
- strncpy(copy, fullname, 50);
+ strncpy(copy, fullname, sizeof(copy) - 1);
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:
- 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,