strrchr() - return 0 when you search '\0' char
:sample test code
void test(void) { char * ptr; char testString[8] = "hello"; ptr = strrchr( testString, '\0' ); if(ptr) { *(ptr - 1) = '~'; } printf("%s\n",testString); }
Expected output : hell~ (Tested and works on standard libraries on windows and Linux)
Actual output:hello. (On KEIL, Not ok)
IDE-Version:µVision V5.28.0.0Copyright (C) 2019 ARM Ltd and ARM Germany GmbH. All rights reserved.
Tool Version Numbers:Toolchain: MDK Professional 5.28 (Flex) Version: 5.28.0.0Toolchain Path: C:\Keil_MDK528a\ARM\ARMCC\BinC Compiler: Armcc.exe V5.06 update 6 (build 750)Assembler: Armasm.exe V5.06 update 6 (build 750)Linker/Locator: ArmLink.exe V5.06 update 6 (build 750)Library Manager: ArmAr.exe V5.06 update 6 (build 750)Hex Converter: FromElf.exe V5.06 update 6 (build 750)CPU DLL: SARMCM3.DLL V5.28.0.0Dialog DLL: TCM.DLL V1.36.2.0Target DLL: STLink\ST-LINKIII-KEIL_SWO.dll V3.0.6.0Dialog DLL: TCM.DLL V1.36.2.0
My guess is that you are using microlib.
Microlib is not compliant with the C library standard. Some features are not supported and some are supported with reduced functionality.
strrchr seems to be implemented in the microlib with reduced functionality.
If you don't use microlib, strrchr will behave as you expect. If you do use microlib, strrchr has the issue that it cannot be used to find the end of a string.