Thread: help with visual studio release

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    146

    help with visual studio release

    Hi,

    I wrote a program and debugged it as a build...the executable works fine on my pc, to make it work on other pcs as well I debugged it as release & it works too..but gives totally different behaviour..I don't understand why...pls help..

    Thanks
    Edesign

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Perhaps post your code. You may be stepping into the realm of undefined, such as buffer overruns.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    146
    hi..I don't think there's anything wrong with the code..this one is tested by you already..

    Code:
    #include "stdafx.h"
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    #include<limits.h>
    #include<math.h>
    #include<string.h>
    unsigned char *buffer;
    char *name,*etemp,*key1;
    //void clear_line();
    void getkey(unsigned char pw[]);
    int main(int argc,char *argv[])
    {	
    	long sizeoffile(FILE *fp);
    	void encoffile(FILE *fp,FILE *fw,long int size);
    	//void decoffile(FILE *fr,FILE *fn,long int esize);
    	FILE *fp,*fw;
    	long int size;
    	name=argv[1];
    	etemp=argv[2];	
    	key1=argv[3];
    	fp=fopen(name,"rb");								
    	size=sizeoffile(fp);									
    	fw=fopen(etemp,"wb");
    	encoffile(fp,fw,size);
    	fclose(fw);
    	fclose(fp);
    	return 0;
    }
    void encoffile(FILE *fp,FILE *fw,long int size)
    {
    	unsigned char key[9];
    	int i=0,j=0;
    	buffer=(unsigned char*)malloc(size);
    	if(buffer==NULL){
    		printf("\nCould not allocate memory");
    		exit(1);
    	}
    	getkey(key);
    	fread(buffer,1,size,fp);	
    	for(i=0;i<size;i++)
    	   {
    	   for(j=0;j<=7;j++)
    	   buffer[i]=(buffer[i]^key[j]);	
    	   }
          fwrite(buffer,1,size,fw);
          return;
    }
    long sizeoffile(FILE *fp){
       long curpos, length;
       curpos = ftell(fp);
       fseek(fp, 0L, SEEK_END);
       length = ftell(fp);
       fseek(fp, curpos, SEEK_SET);
       return(length);
    }
    //void clear_line()
    //{
    //   int ch;
    //   while ((ch = getchar()) != '\n' && ch != EOF) ; 
    //}
    void getkey(unsigned char pw[])
    {	int ctr=0,i=0,j=0,k=0;
    	do
    	{
    		pw[ctr]=key1[ctr];
    		ctr++;
    		k=ctr-1;
    	}while(ctr<=8 && (pw[k])!=' ');
    	ctr--;
    	if(ctr<8)
    	{
    		for(j=ctr;j<8;j++)
    		{
    		pw[j]=pw[i];
    		i++;
    		}
    	}
    	pw[j]='\0';
    	printf("\n&#37;s",pw);
    	return;
    }
    also how can I debug this kind of program step by step when I am using commandline arguements??

    Thanks
    Edesign
    Last edited by edesign; 04-03-2008 at 07:49 AM. Reason: unused variable removed

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    To debug with command lines, you can go into project options and select the "Debugging" section. There you can enter command lines. Also beware that if the user enters less than 3 arguments, you can get a crash because you aren't checking if the user entered 3 arguments and will thus access out of bounds memory.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    146
    The problem is there in getkey..if I debug as release...it does not take the key char by char, directly assign key to pw...i don't know why..

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    In release, the compiler can optimize things which can throw off the debugger. For example, use registers or optimize away loops and stuff. The only real safe answer to know what's going on is to look at the assembly, which be a bit daunting to new programmers.

    You could also try debugging a crash dump. I've never tried before, but if you get the program to crash on the other computer and post the crash dump, perhaps it can be analyzed to give a hint where the problem is.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Feb 2008
    Posts
    146
    Hello

    Quote Originally Posted by Elysia View Post
    You could also try debugging a crash dump. I've never tried before, but if you get the program to crash on the other computer and post the crash dump, perhaps it can be analyzed to give a hint where the problem is.
    I am not getting it..can you explain in more detail...
    Also do you think there is anything wrong with the getkey function i wrote??

    Thanks
    Edesign

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What I can see is that you never check the length of key1, so you if the user supplies a key less than 9 or 8 chars, you get a buffer overrun.
    By crashdump I mean the files created when you get a bluescreen or a program crashes.

    What you do is crash the program on the other machine. Look in the temp folder for a file name ".dmp". Use a program such as "Unlocker" to unlock the file (otherwise the crash dialog is denying access to it).
    Then copy it and upload it here.
    I just tried crashing the program and analyzing the crash dump and found the problem immediately:

    Loading Dump File [D:\Documents and Settings\Azura\Lokala inst&#228;llningar\Temp\97CF1B1.dmp]
    User Mini Dump File: Only registers, stack and portions of memory are available

    Symbol search path is: srv*;symsrv*;D:\Windows\Symbols\dll;D:\Program\Sym bols
    Executable search path is:
    Windows XP Version 2600 (Service Pack 2) UP Free x86 compatible
    Debug session time: Thu Apr 3 16:55:18.000 2008 (GMT+2)
    System Uptime: not available
    Process Uptime: not available
    ....................
    Loading unloaded module list
    ..
    This dump file has an exception of interest stored in it.
    The stored exception information can be accessed via .ecxr.
    (f0f0f0f0.a58): Unknown exception - code c0000417 (first/second chance not available)
    eax=00a00000 ebx=0013debc ecx=00001000 edx=7c90eb94 esi=00000000 edi=7ffdd000
    eip=7c90eb94 esp=0013de94 ebp=0013df30 iopl=0 nv up ei pl zr na pe nc
    cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
    *** ERROR: Symbol file could not be found. Defaulted to export symbols for ntdll.dll -
    ntdll!KiFastSystemCallRet:
    7c90eb94 c3 ret
    0:000> k
    ChildEBP RetAddr
    WARNING: Stack unwind information not available. Following frames may be wrong.
    0013df30 7c809c86 ntdll!KiFastSystemCallRet
    *** ERROR: Symbol file could not be found. Defaulted to export symbols for faultrep.dll -
    0013df4c 699d763c kernel32!WaitForMultipleObjects+0x18
    0013e8e0 699d82b1 faultrep!ReportFaultDWM+0x14cf
    0013f954 7c863059 faultrep!ReportFault+0x533
    0013fbc8 7858c8ac kernel32!UnhandledExceptionFilter+0x4cf
    0013ff00 7854fdb5 MSVCR90!_invoke_watson+0xf9 [f:\dd\vctools\crt_bld\self_x86\crt\src\invarg.c @ 229]
    0013ff48 7854fe5c MSVCR90!_fsopen+0x34 [f:\dd\vctools\crt_bld\self_x86\crt\src\fopen.c @ 54]
    0013ff5c 00401020 MSVCR90!fopen+0x12 [f:\dd\vctools\crt_bld\self_x86\crt\src\fopen.c @ 124]
    0013ff7c 0040131c Test!main+0x20 [g:\w00t\visual studio 2008\projects\test\test.cpp @ 26]
    0013ffc0 7c816d4f Test!__tmainCRTStartup+0x10f [f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c @ 582]
    0013fff0 00000000 kernel32!RegisterWaitForInputIdle+0x49
    In main, a call to fopen failed. It threw some sort of exception.
    Last edited by Elysia; 04-03-2008 at 08:58 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Feb 2008
    Posts
    146
    Ok..I found out my mistake I didn't give the " " after key...so it accessed garbage after reading the key...giving " " solved the problem....

    Thanks
    Edesign

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM