NO

Author Topic: this bug (with memmove) killed me :(  (Read 3941 times)

whatsup

  • Guest
this bug (with memmove) killed me :(
« on: November 18, 2010, 08:48:21 PM »
i post here an example code
two functions use the same code
except one thing
one function uses PellesC memmove
the other uses Mymemmove
watch the results:

Code: [Select]
// *********************************************************************
// Created with BCX - BASIC To C/C++ Translator (V) 7.00 (10.11.15)
//                 BCX (c) 1999 - 2009 by Kevin Diggins
// *********************************************************************
//              Translated for compiling with a C Compiler
// *********************************************************************
#include <windows.h>    // Win32 Header File
#include <windowsx.h>   // Win32 Header File
#include <commctrl.h>   // Win32 Header File
#include <commdlg.h>    // Win32 Header File
#include <mmsystem.h>   // Win32 Header File
#include <shellapi.h>   // Win32 Header File
#include <shlobj.h>     // Win32 Header File
#include <richedit.h>   // Win32 Header File
#include <wchar.h>      // Win32 Header File
#include <objbase.h>    // Win32 Header File
#include <ocidl.h>      // Win32 Header File
#include <winuser.h>    // Win32 Header File
#include <olectl.h>     // Win32 Header File
#include <oaidl.h>      // Win32 Header File
#include <ole2.h>       // Win32 Header File
#include <oleauto.h>    // Win32 Header File
#include <winsock.h>    // Win32 Header File
#include <conio.h>
#include <direct.h>
#include <ctype.h>
#include <io.h>
#include <fcntl.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include <setjmp.h>
#include <time.h>
#include <stdarg.h>
#include <process.h>

// ***************************************************
// Compiler Defines
// ***************************************************

// C++
#if defined( __cplusplus )
  #define overloaded
  #define C_EXPORT EXTERN_C __declspec(dllexport)
  #define C_IMPORT EXTERN_C __declspec(dllimport)
#else
  #define C_EXPORT __declspec(dllexport)
  #define C_IMPORT __declspec(dllimport)
#endif

// Open Watcom defs
#if defined( __WATCOM_CPLUSPLUS__ ) || defined( __TINYC__ )
  #define atanl atan
  #define sinl  sin
  #define cosl  cos
  #define tanl  tan
  #define asinl asin
  #define acosl acos
  #define log10l log10
  #define logl   log
  #define _fcloseall fcloseall
#endif

// Borland C++ 5.5.1 defs - bcc32.exe
#if defined( __BCPLUSPLUS__ )
  // ===== Borland Libraries ==========
  #include <dos.h>
  #pragma comment(lib,"import32.lib")
  #pragma comment(lib,"cw32.lib")
  // ==================================
#endif

// Microsoft VC++
#ifndef DECLSPEC_UUID
  #if (_MSC_VER >= 1100) && defined ( __cplusplus )
    #define DECLSPEC_UUID(x)    __declspec(uuid(x))
  #else
    #define DECLSPEC_UUID(x)
  #endif
#endif

#define BCX_STRING_SIZE  2048
// *************************************************


#if !defined( __LCC__ )
// *************************************************
// Instruct Linker to Search Object/Import Libraries
// *************************************************
#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"user32.lib")
#pragma comment(lib,"gdi32.lib")
#pragma comment(lib,"comctl32.lib")
#pragma comment(lib,"advapi32.lib")
#pragma comment(lib,"winspool.lib")
#pragma comment(lib,"shell32.lib")
#pragma comment(lib,"ole32.lib")
#pragma comment(lib,"oleaut32.lib")
#pragma comment(lib,"uuid.lib")
#pragma comment(lib,"odbc32.lib")
#pragma comment(lib,"odbccp32.lib")
#pragma comment(lib,"winmm.lib")
#pragma comment(lib,"comdlg32.lib")
#pragma comment(lib,"imagehlp.lib")
#pragma comment(lib,"version.lib")
#else
#pragma lib <winspool.lib>
#pragma lib <shell32.lib>
#pragma lib <ole32.lib>
#pragma lib <oleaut32.lib>
#pragma lib <uuid.lib>
#pragma lib <odbc32.lib>
#pragma lib <odbccp32.lib>
#pragma lib <winmm.lib>
#pragma lib <imagehlp.lib>
#pragma lib <version.lib>
// *************************************************
// End of Object/Import Libraries To Search
// *************************************************
#endif




// *************************************************
//            User Global Initialized Arrays
// *************************************************



// *************************************************
//                 Runtime Functions
// *************************************************

// *************************************************
//                  Main Program
// *************************************************

char myBuf[100];
char *MyPtr1;
#define TranslateSlash 1


void Mymemmove(char *dest,char *src,int sze) {
  register int i = sze;
  dest+=i;
  src+=i;
  while(i) {
    src--;
    dest--;
    dest[0]=src[0];
    i--;
  }
}


void Test1(void)
{
int j,eStr = 1;
  MyPtr1 = myBuf;
strcpy(MyPtr1,"\"0rntx\\\"");

          printf("the token is =%s=\n",MyPtr1);

REPEAT0000:;
          do {
            ++MyPtr1;
            if(MyPtr1[0]==92)
            {
              ++MyPtr1;
              if(TranslateSlash)
              {
                if(eStr)
                {
                  j=strlen(MyPtr1);
                  printf("MyPtr =%s=  Len=%d\n",MyPtr1,(int)j);
                  memmove(MyPtr1+1,MyPtr1,j+1);
                  printf("the token after poke is =%s=\n    ptr after poke is=%s=\n",myBuf,MyPtr1);
                  MyPtr1[0] = 92;
                }
                goto REPEAT0000;
              }
              goto EndSelect_3;
            }
            if(MyPtr1[0]==2)
            {
              MyPtr1[0] = 92;
              goto REPEAT0000;
            }
            EndSelect_3:;
          }while(!(MyPtr1[0]==0));
          printf("the token after slash =%s=\n",myBuf);
}


void Test2(void)
{
int j,eStr = 1;
  MyPtr1 = myBuf;
strcpy(MyPtr1,"\"0rntx\\\"");

          printf("the token is =%s=\n",MyPtr1);

REPEAT0000:;
          do {
            ++MyPtr1;
            if(MyPtr1[0]==92)
            {
              ++MyPtr1;
              if(TranslateSlash)
              {
                if(eStr)
                {
                  j=strlen(MyPtr1);
                  printf("MyPtr =%s=  Len=%d\n",MyPtr1,(int)j);
                  Mymemmove(MyPtr1+1,MyPtr1,j+1);
                  printf("the token after poke is =%s=\n    ptr after poke is=%s=\n",myBuf,MyPtr1);
                  MyPtr1[0] = 92;
                }
                goto REPEAT0000;
              }
              goto EndSelect_3;
            }
            if(MyPtr1[0]==2)
            {
              MyPtr1[0] = 92;
              goto REPEAT0000;
            }
            EndSelect_3:;
          }while(!(MyPtr1[0]==0));
          printf("the token after slash =%s=\n",myBuf);
}

int __cdecl main(int argc, char** argv)
{
printf("using PellesC memmove\n");
Test1();
printf("\n\nnow using my memmove\n");
Test2();
}  // End of main program



the output of this is:
Quote
using PellesC memmove
the token is ="0rntx\"=
MyPtr ="=  Len=1
the token after poke is ="0rntx\"=
    ptr after poke is="=
the token after slash ="0rntx\\=


now using my memmove
the token is ="0rntx\"=
MyPtr ="=  Len=1
the token after poke is ="0rntx\""=
    ptr after poke is=""=
the token after slash ="0rntx\\"=
the second output (mymemmove) is the correct one


the output of this when using other compiler is:
Quote
using PellesC memmove
the token is ="0rntx\"=
MyPtr ="=  Len=1
the token after poke is ="0rntx\""=
    ptr after poke is=""=
the token after slash ="0rntx\\"=


now using my memmove
the token is ="0rntx\"=
MyPtr ="=  Len=1
the token after poke is ="0rntx\""=
    ptr after poke is=""=
the token after slash ="0rntx\\"=
both outputs identical as expected

this is a bigggggg bug for me, since pellesC is my main compiler,
please fix this as soon as possible, and let me know
« Last Edit: November 18, 2010, 08:56:36 PM by whatsup »

whatsup

  • Guest
Re: this bug (with memmove) killed me :(
« Reply #1 on: November 20, 2010, 11:06:16 PM »
thanks for the fix in the new release, it works.

what i didn't mention last time is that before memmove, i used:
Code: [Select]
strcpy(MyPtr+1,MyPtr)
and had a crash.

i thought that this because strcpy don't support overlapped buffers.

i also checked strcpy with the last release, and there is still a crash.

so if i'm wrong and strcpy should support overlapped, there is a bug with it.

with other compiler, there is no crash.

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: this bug (with memmove) killed me :(
« Reply #2 on: November 21, 2010, 05:18:59 PM »
i post here an example code
two functions use the same code
except one thing
one function uses PellesC memmove
the other uses Mymemmove
watch the results:

In such a case, when a function of the library of Pelles C does not work correct you can try to link the Microsoft runtime DLL msvcrt.dll, which is a part of Windows (this lib was part of the older versions of Pelles C, now you must create it from msvcrt.dll - look into forum how to create a lib from a dll).
best regards
 Alex ;)