Hi,
I have found a bug in generated code in debug build. I have Visual C++ .NET
7.1.3088. Function Buggy::isBug() returns true and it should return false.
The sample is contrived to exhibit the bug in small code. The expression
m_array + sizeof(Buggy) * m_used
is actualy compiled as
m_array + sizeof(Buggy) * sizeof(Buggy) * m_used
If you look into assembly you should see something like this:
00411276 mov eax,dword ptr [this]
00411279 mov ecx,dword ptr [eax+1F8h]
0041127F imul ecx,ecx,1FCh
00411285 imul ecx,ecx,1FCh // <<<<<<<< ????
0041128B mov edx,dword ptr [this]
0041128E add ecx,dword ptr [edx+1F4h]
Thanks for any feedback, Jan
The sample code
===============
struct Buggy
{
char ch[500];// must be bigger otherwise shl will be used instead of imul
Buggy* m_array;
int m_used;
bool isBug()
{
m_array = 0;
m_used = 1;
return sizeof(Buggy) != int(m_array + sizeof(Buggy) * m_used);
}
};
int main()
{
Buggy test;
test.isBug();
return 0;
} 2 1320
Jan Bares wrote: Hi,
I have found a bug in generated code in debug build. I have Visual C++ .NET
Actually, you haven't. See below for the source of your misunderstanding.
7.1.3088. Function Buggy::isBug() returns true and it should return false. The sample is contrived to exhibit the bug in small code. The expression
m_array + sizeof(Buggy) * m_used
is actualy compiled as
m_array + sizeof(Buggy) * sizeof(Buggy) * m_used
Actually, it's not. If you look into assembly you should see something like this:
00411276 mov eax,dword ptr [this] 00411279 mov ecx,dword ptr [eax+1F8h] 0041127F imul ecx,ecx,1FCh 00411285 imul ecx,ecx,1FCh // <<<<<<<< ???? 0041128B mov edx,dword ptr [this] 0041128E add ecx,dword ptr [edx+1F4h]
Thanks for any feedback, Jan
The sample code =============== struct Buggy { char ch[500]; Buggy* m_array; int m_used;
bool isBug() { m_array = 0; m_used = 1;
return sizeof(Buggy) != int(m_array + sizeof(Buggy) * m_used);
The compiler is doing exactly what you told it. m_array is of type Buggy*.
m_array+sizeof(Buggy) is also of type Buggy* - its value is computed by
multiplying (*m_array) by sizeof(Buggy) and then adding the result to
m_array. Remember, you're doing pointer math here. The compiler correctly
observed that m_used==1 and didn't emit any code to perform that
calculation.
Presumably you meant to write:
return sizeof(Buggy) != int(m_array) + sizeof(Buggy) * m_used;
.... or something like that. It's not clear what this code is supposed to
do, but then you did say it's contrived.
} };
int main() { Buggy test;
test.isBug();
return 0; }
If you still have problems with some uncontrived code, please post again.
-cd
Thanks Carl, I just realized that and wanted to disregard this stupidity, I
must be off my brain.
Jan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Martin |
last post by:
The original question is at the bottom:
> What OS are you using?
Windows 2000 Server SP3 with VS.NET 2003
> How much memory do you have?
512MB, of which typically at least half is...
|
by: paul calvert |
last post by:
I hope somewhere here has encountered and solved a similar problem in
the past.
1) on a new Win2000 PC:
installed Visual C++ 6.0
download & install single file Service Pack 5.0
2) try to...
|
by: Mark Rockman |
last post by:
------ Build started: Project: USDAver2, Configuration: Debug .NET ------
Preparing resources...
Updating references...
Performing main compilation...
error CS0583: Internal Compiler Error...
|
by: JTrigger |
last post by:
When I compile my project using the IDE on a development machine it works
just fine. When I compile it on the server using csc.exe, I get the
following error when I try to bring it up in the web...
|
by: Razzie |
last post by:
Hi all,
I was working on a little project, worked fine, but now all of a sudden I
get:
The compiler failed with error code -1073741502
as an error message (when running the site, not...
|
by: Don Kim |
last post by:
Ok, so I posted a rant earlier about the lack of marketing for C++/CLI,
and it forked over into another rant about which was the faster
compiler. Some said C# was just as fast as C++/CLI, whereas...
|
by: Miroslaw Makowiecki |
last post by:
Where can I download Comeau compiler as a trial version?
Thanks in advice.
|
by: jacob navia |
last post by:
http://slashdot.org/
"The leaner, lighter, faster, and most importantly, BSD Licensed,
Compiler PCC has been imported into OpenBSD's CVS and NetBSD's pkgsrc.
The compiler is based on the...
|
by: rkcons |
last post by:
Any ideals what would cause this ?
Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |