https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92076
Bug ID: 92076 Summary: strange strcpy Product: gcc Version: 6.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: georg.chambert at telia dot com Target Milestone: --- Created attachment 47026 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47026&action=edit screenshot of strange strcpy buffer shift, note first two printf -----------------------snippet of code ---------------------v printf("%s\n",prev_buff); strcpy(str,prev_buff); str[2]=0;// take first part an put endmark lastHour = atoi(str); printf("%s\n",prev_buff); str[0]=prev_buff[3]; str[1]=prev_buff[4];str[2]=0;// hittar inget bra i clib lastMin = atoi(str); printf(">>>%d<<<%s>>>%d<<<\n",lastHour,str,lastMin); printf("%s\n",prev_buff); ------------------------ the bugg (well strangeity then) occur (as per screenshot) between the first and the second printf, the prev_buff gets "shifted left", 10positions, BY the strcpy( ) CALL(!!??) ; in my naive world the prev_buff should be unaltered. exactly the same sequence of code works without problem in an earlier location, albeit with other variables (and without the issue-confining/indicating printouts) (which is worrying); ---------------------------------just preceeding strcpy(str,inbuffer); str[2]=0;// take first part an put endmark firstHour = atoi(str); str[0]=inbuffer[3]; str[1]=inbuffer[4];str[2]=0;// hittar inget bra i clib firstMin = atoi(str); printf(">>>%d<<<>>>%d<<<\n",firstHour,firstMin); ---------------------declaration earlier in program-----------------------v #define WIN32_LEAN_AND_MEAN #include <stdio.h> #include <stdlib.h> #include <windows.h> using namespace std; .... char inbuffer[80]; char prev_buff[80]; char str[10]; ---------------------------------------------------------------------------- ---- has been compiled with following, making no diff -----------v C:\Users\Micron 2.0.DESKTOP-OKJ8P06\Desktop\logg_read>gcc -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations measProc.cpp ------------------------------------------------------------------ AS for the GCC version used: C:\Users\Micron 2.0.DESKTOP-OKJ8P06>gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/6.3.0/lto-wrapper.exe Target: mingw32 Configured with: ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 --with-gmp=/mingw --with-mpfr --with-mpc=/mingw --with-isl=/mingw --prefix=/mingw --disable-win32-registry --with-arch=i586 --with-tune=generic --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-pkgversion='MinGW.org GCC-6.3.0-1' --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --enable-libgomp --disable-libvtv --enable-nls Thread model: win32 gcc version 6.3.0 (MinGW.org GCC-6.3.0-1) THE machine is a laptop ASUS (in search of increadable; which they will never find) with Windows 10 (worst OS ever)