473,760 Members | 9,717 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Diff b/w the working of exe from within the VS and console

Hi All,

I have written the 'c' code for specific purpose and tested it over
many files and it is crashing in only one case. When I ran the same
code in the debug mode within the VS against the same file it works
well and it also works well in the release mode with in the VS. It get
crashed only when I run it from the console.

I have checked my code against the heap correction and memory leaks and
its perfectly fine. I have tried every option and none of them is
working and also if I put up some printf in my code, it start working
from the console mode.

In short, this is a bouncer for me.

Does any one have some ideas how the working of the exe is different
when we ran it from the VS as comapred to console. or the points whihc
i should consider regarding my code?
Thanks
Gaurav Vashishth

Oct 11 '06 #1
8 1658
Gaurav wrote:
Hi All,

I have written the 'c' code for specific purpose and tested it over
many files and it is crashing in only one case. When I ran the same
code in the debug mode within the VS against the same file it works
well and it also works well in the release mode with in the VS. It get
crashed only when I run it from the console.

I have checked my code against the heap correction and memory leaks and
its perfectly fine. I have tried every option and none of them is
working and also if I put up some printf in my code, it start working
from the console mode.

In short, this is a bouncer for me.

Does any one have some ideas how the working of the exe is different
when we ran it from the VS as comapred to console. or the points whihc
i should consider regarding my code?

Please see the
FAQ(http://www.parashift.com/c++-faq-lit...t.html#faq-5.8 in
particular) and post a minimal, compilable version of your code.

Regards,
Sumit.
Oct 11 '06 #2

"Gaurav" <va********@gma il.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
Hi All,

I have written the 'c' code for specific purpose and tested it over
many files and it is crashing in only one case.
You do know this is a C++ newsgroup, not a C newsgroup, right?

I'm not sure what you mean when you say you "tested it over many files".
Are you talking about some kind of input data file your program reads?
When I ran the same
code in the debug mode within the VS against the same file it works
well and it also works well in the release mode with in the VS. It get
crashed only when I run it from the console.

I have checked my code against the heap correction and memory leaks and
its perfectly fine. I have tried every option and none of them is
working and also if I put up some printf in my code, it start working
from the console mode.

In short, this is a bouncer for me.
"bouncer"? :-)
>
Does any one have some ideas how the working of the exe is different
when we ran it from the VS as comapred to console. or the points whihc
i should consider regarding my code?
Given that you said it works if you add in printf statements, then a highly
likely cause is that you're overwriting a buffer (i.e., assigning values to
positions past the end of an array). Check if your code contains any
arrays, and make sure that there is no way your code can write past the end
(including C-string-related code which may tack on a NULL-terminator behind
the scenes).

It could be that the file which exhibits the problem has data in it which
isn't the expected format. For example, you might be expecting CR/LF line
terminators, but it contains only CR terminators, or none at all. Or some
line in the file may be one character longer than you expect. Or you may be
expecting it to be pure ASCII, but it contains a non-ASCII character
somewhere.

Of course, without seeing any code, it's impossible for us to tell if you've
got a logic or coding error somewhere.

-Howard

Oct 11 '06 #3
Howard wrote:
"Gaurav" <va********@gma il.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
>In short, this is a bouncer for me.
>
"bouncer"? :-)
<OT>

Not the nightclub type of bouncer.

A cricketing term(http://en.wikipedia.org/wiki/Bouncer_%28cricket%29)
which can also be used to describe anything that's tough to "play". :-).
</OT>
Oct 12 '06 #4

Howard wrote:
"Gaurav" <va********@gma il.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
Hi All,

I have written the 'c' code for specific purpose and tested it over
many files and it is crashing in only one case.

You do know this is a C++ newsgroup, not a C newsgroup, right?

I'm not sure what you mean when you say you "tested it over many files".
Are you talking about some kind of input data file your program reads?
Yes you are right.
When I ran the same
code in the debug mode within the VS against the same file it works
well and it also works well in the release mode with in the VS. It get
crashed only when I run it from the console.

I have checked my code against the heap correction and memory leaks and
its perfectly fine. I have tried every option and none of them is
working and also if I put up some printf in my code, it start working
from the console mode.

In short, this is a bouncer for me.

"bouncer"? :-)

Does any one have some ideas how the working of the exe is different
when we ran it from the VS as comapred to console. or the points whihc
i should consider regarding my code?

Given that you said it works if you add in printf statements, then a highly
likely cause is that you're overwriting a buffer (i.e., assigning values to
positions past the end of an array). Check if your code contains any
arrays, and make sure that there is no way your code can write past the end
(including C-string-related code which may tack on a NULL-terminator behind
the scenes).

It could be that the file which exhibits the problem has data in it which
isn't the expected format. For example, you might be expecting CR/LF line
terminators, but it contains only CR terminators, or none at all. Or some
line in the file may be one character longer than you expect. Or you may be
expecting it to be pure ASCII, but it contains a non-ASCII character
somewhere.

Of course, without seeing any code, it's impossible for us to tell if you've
got a logic or coding error somewhere.
Well, if I'm overwriting the buffers then my heapcheck test should fail
but it is not and secondly test file is perfectly ok and it is in the
binary format

I'm using this for checking the heap
_ASSERTE(_CrtCh eckMemory());
heapstatus = _heapchk();

-Howard
Oct 12 '06 #5

"Gaurav" <va********@gma il.comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
>
Howard wrote:
>"Gaurav" <va********@gma il.comwrote in message
news:11******* *************** @i42g2000cwa.go oglegroups.com. ..
>>
Given that you said it works if you add in printf statements, then a
highly
likely cause is that you're overwriting a buffer (i.e., assigning values
to
positions past the end of an array). Check if your code contains any
arrays, and make sure that there is no way your code can write past the
end
(including C-string-related code which may tack on a NULL-terminator
behind
the scenes).

It could be that the file which exhibits the problem has data in it which
isn't the expected format. For example, you might be expecting CR/LF
line
terminators, but it contains only CR terminators, or none at all. Or
some
line in the file may be one character longer than you expect. Or you may
be
expecting it to be pure ASCII, but it contains a non-ASCII character
somewhere.

Of course, without seeing any code, it's impossible for us to tell if
you've
got a logic or coding error somewhere.

Well, if I'm overwriting the buffers then my heapcheck test should fail
but it is not and secondly test file is perfectly ok and it is in the
binary format

I'm using this for checking the heap
_ASSERTE(_CrtCh eckMemory());
heapstatus = _heapchk();
I'm not positive, but I don't think that a "heap check" will tell you if you
wrote past the end of a locally declared array. I think that has to do with
dynamic memory allocation. I'm talking about writing past the end of local
(or possibly even member) arrays, such as this:

int arr[10];
for (int i = 0; i <= 10; ++i)
arr[i] = i;

That will write 10 at arr[10], which is illegal (specifically, it's
"Undefined Behavior").

Writing past the end of an array simply puts new values in locations which
may or may not be ok to write in. And from a lot of experience, I can say
that this is probably the most likely kind of error to exhibit the behavior
you describe.

The reason buffer overruns exhibit this behavior is that when you add other
code (such as a printf), or run within a debugger, what resides in the
memory immediately after a local array is likely to be different, so the
behavior when changing those memory locations is different. Everything may
be fine for your testing, but one or more customers may complain about
crashes. The crashing may appear random, or may happen whenever a specific
set of actions is taken or specific data is used. And it often crashes at a
location in the code that has nothing to do with the code that overwrote the
array.

Every thing you've described about the symptoms fits this pattern. I
strongly suggest that you check out the code carefully. (Also, you might
want to isolate portions of the code and test their boundary conditions
thoroughly, with unit tests.)

Another possibility is using uninitialized variables, or dereferencing
pointers after they've been deleted.

I've given you the most likely culprit(s). So now it's up to you: either
post code which exhibits the problem, or find the problem yourself. Nobody
here can simply guess what's wrong, especially if you're just going to
respond that we've guessed wrong.

-Howard


Oct 12 '06 #6
Gaurav wrote:
[snip]
Well, if I'm overwriting the buffers then my heapcheck test should fail
but it is not and secondly test file is perfectly ok and it is in the
binary format
Maybe, maybe not. Heapcheck tests cannot be perfect.

Consider something like the following snippet.

char someChars = new char[10];
integer someInts = new int[10];

// ... stuff happens

someChars[12] = 'c';

Maybe this gets caught by a heapcheck test. Maybe it simply
corrupts the "stuff" involved in keeping track of where these
memory allocs have been put in memory. Maybe it just messes
up the contents of someInts. It's really not possible to say what
will happen. But it's quite highly likely it won't be good.
Socks

Oct 12 '06 #7
Thanks for your suggestion, I have figured out my problem. It was
buffer overwriting.

But still I have one doubt, when we execute the code in the debug mode
the compiler writes the four byte, fd fd fd fd, at the end of every
buffer and this is what heapcheck performs. It checks that whether the
four bytes padding after every buffer is there or not and it intimate
us accordingly.

Then how my heapchek functions not able to locate my problem

Reards,
Gaurav

Howard wrote:
"Gaurav" <va********@gma il.comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .

Howard wrote:
"Gaurav" <va********@gma il.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
>
Given that you said it works if you add in printf statements, then a
highly
likely cause is that you're overwriting a buffer (i.e., assigning values
to
positions past the end of an array). Check if your code contains any
arrays, and make sure that there is no way your code can write past the
end
(including C-string-related code which may tack on a NULL-terminator
behind
the scenes).

It could be that the file which exhibits the problem has data in it which
isn't the expected format. For example, you might be expecting CR/LF
line
terminators, but it contains only CR terminators, or none at all. Or
some
line in the file may be one character longer than you expect. Or you may
be
expecting it to be pure ASCII, but it contains a non-ASCII character
somewhere.

Of course, without seeing any code, it's impossible for us to tell if
you've
got a logic or coding error somewhere.
Well, if I'm overwriting the buffers then my heapcheck test should fail
but it is not and secondly test file is perfectly ok and it is in the
binary format

I'm using this for checking the heap
_ASSERTE(_CrtCh eckMemory());
heapstatus = _heapchk();

I'm not positive, but I don't think that a "heap check" will tell you if you
wrote past the end of a locally declared array. I think that has to do with
dynamic memory allocation. I'm talking about writing past the end of local
(or possibly even member) arrays, such as this:

int arr[10];
for (int i = 0; i <= 10; ++i)
arr[i] = i;

That will write 10 at arr[10], which is illegal (specifically, it's
"Undefined Behavior").

Writing past the end of an array simply puts new values in locations which
may or may not be ok to write in. And from a lot of experience, I can say
that this is probably the most likely kind of error to exhibit the behavior
you describe.

The reason buffer overruns exhibit this behavior is that when you add other
code (such as a printf), or run within a debugger, what resides in the
memory immediately after a local array is likely to be different, so the
behavior when changing those memory locations is different. Everything may
be fine for your testing, but one or more customers may complain about
crashes. The crashing may appear random, or may happen whenever a specific
set of actions is taken or specific data is used. And it often crashes at a
location in the code that has nothing to do with the code that overwrote the
array.

Every thing you've described about the symptoms fits this pattern. I
strongly suggest that you check out the code carefully. (Also, you might
want to isolate portions of the code and test their boundary conditions
thoroughly, with unit tests.)

Another possibility is using uninitialized variables, or dereferencing
pointers after they've been deleted.

I've given you the most likely culprit(s). So now it's up to you: either
post code which exhibits the problem, or find the problem yourself. Nobody
here can simply guess what's wrong, especially if you're just going to
respond that we've guessed wrong.

-Howard
Oct 12 '06 #8

"Gaurav" <va********@gma il.comwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
Thanks for your suggestion, I have figured out my problem. It was
buffer overwriting.

But still I have one doubt, when we execute the code in the debug mode
the compiler writes the four byte, fd fd fd fd, at the end of every
buffer and this is what heapcheck performs. It checks that whether the
four bytes padding after every buffer is there or not and it intimate
us accordingly.

Then how my heapchek functions not able to locate my problem

Reards,
Gaurav
HI Guarav,

please don't top-post. Replies belong either below or interspersed with
what you're responding to, ok? Thanks.

I'm glad I could help. The symptoms sounded like a buffer overwrite,
and it turns out it was.

I don't know exactly how that heap check tool works, or what the
contents of your memory looks like before and after you write past the end,
but apparently the heap check isn't catching it. You could write their tech
support and ask them why not, I suppose.

Regards,
Howard

Oct 12 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
399
by: Viviana Vc | last post by:
Hi all, I am using Win2k, VS. NET 7.1 (MS development Environment 2003 7.1.3088) and I noticed that by building the exact same code twice the generated binaries are different (not much, but they are). To be sure I tried a simple console application like void main(){} and 2 times rebuilding the project gets 2 different binaries. Has anybody any clue why this happens? Could I somehow change a setting or something to remove those diff (I
6
4486
by: Lionel van den Berg | last post by:
Hi all, I'm wondering if there is a diff function like the unix command in C++? In fact I would like to know if you can call the unix (I should say *nix) command from within a c++ application? Also I have a binary that has been compiled by a friend, is there a way to call it from within a C++ application and pass it a parameter?
9
6519
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the delta binary is pretty huge in size. I have 1 byte file and 2 bytes file, the delta should be 1 byte but somehow it turns out to be 249 bytes using binary formatter. I guess serialization has some other things added to the delta file.
4
4955
by: Andreas Kasparek | last post by:
Hola! I'm preparing my master thesis about a XML Merge Tool implementation and was wondering if there is any open standard for XML diff regarding topics like: - is a diff result computed on the ordered or unordered xml node tree of the compared documents? - what identifiers/criteria should be used by default to match elements of the same type in different documents? - should a diff tool consider move operations or only insert/delete
3
2962
by: Csaba Gabor | last post by:
I'm comparing the text of (snippets of) web pages which I expect to be quite different or quite similar. In the case where they are similar, I would like to display the more recent one and say something like: Word 2 added : "Jack be nimble" Words 10-11 changed to: "the quick brown fox" : "the brown fast quick fox" Words before word 20 removed: "sat in a corner on"
0
1323
by: mariat101 | last post by:
I am collecting patient information when they do not show for an apt. I've created 4 tables linked by autonum b/c I have 3 of them in a form as subforms b/c they want to be able to see everything on one screen. Each table has a date attached to it 1) data entry date 2) pt type date 3) intervention date 4) outcome date (all on diff tables). I need to create a report or multiply reports on for example: pt type = "no show" and intervention = total...
0
1049
by: sriNani | last post by:
Whats the diff bitween console app performance and windows sevice performance..? which can suggestable to follow from .net 2005?
1
3137
by: erikcw | last post by:
Hi, I'm trying to create an undo/redo feature for a webapp I'm working on (django based). I'd like to have an undo/redo function. My first thought was to use the difflib to generate a diff to serve as the "backup", and then if someone wants to undo their operation, the diff could just be merged/patched with the current text. However, I've not be able to find a patch library. Are there any
6
3317
by: Aaron Gray | last post by:
Hi, I am working on an HTML WYSISYG Wiki and need to display a diff page like WikiPedia does if two people edit a file at the same time to give the second user the diff. Basically with additions in red and deletions in red strike though. There seem to be several in Perl and Python and many diff programs which all seem to be line based and work on text written in PHP.
0
9521
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9333
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10107
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9945
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9900
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5361
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.