473,804 Members | 3,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Request

As a consequence of a heavy discussion in another thread,
I wrote this program:
#include <stdlib.h>
int main(void)
{
char *p=calloc(65521 ,65552);
if (p)
printf("BUG!!!! \n");
}

The multiplication will give an erroneus result
in 32 bit size_t systems. I have tested this
in several systems with several compilers.

Maybe people with other compilers/implementations
would compile this program and send the results?

The results I have so far are:

LINUX
GCC 2.95
HAS THE BUG

GCC-4.02
NO BUGS

GCC-3.x
NO BUGS

WINDOWS
cygwin gcc 3.4.4
NO bugs
pelles c:
HAS THE BUG
Microsoft
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42
for 80x86
NO BUGS (If the multiplication overflows it will trap. Very good
behavior)

AIX
IBM-cc (compiling in 32 bit mode)
NO BUGS
gcc 4.0.0 (compiling in 32 bit mode)
NO BUGS
Thanks in advance for your cooperation

Jan 2 '07
149 4313
av
On Wed, 03 Jan 2007 09:58:35 +0100, av wrote:
>the "problem" is not in calloc or malloc but it is in the mathemaical
model ("modello matematico") used for size_t
possible i'm the only one in think that standard C is wrong on
definition of size_t?
Jan 11 '07 #141
av said:
On Wed, 03 Jan 2007 09:58:35 +0100, av wrote:
>>the "problem" is not in calloc or malloc but it is in the mathemaical
model ("modello matematico") used for size_t

possible i'm the only one in think that standard C is wrong on
definition of size_t?
That's unlikely. There are plenty of people who don't understand C.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 11 '07 #142
av wrote:
On Wed, 03 Jan 2007 09:58:35 +0100, av wrote:
>>the "problem" is not in calloc or malloc but it is in the mathemaical
model ("modello matematico") used for size_t

possible i'm the only one in think that standard C is wrong on
definition of size_t?
Yes.

--
Chris "first on the Underground!" Dollin
"No-one here is exactly what he appears." G'kar, /Babylon 5/

Jan 11 '07 #143
In article <2v************ *************** *****@4ax.com>, av <av@ala.awrot e:
>possible i'm the only one in think that standard C is wrong on
definition of size_t?
Certainly the modular arithmetic used for unsigned types is usually
inappropriate for sizes, but so are signed types. And presumably the
standards committee would not be willing to invent a new kind of
integer for this purpose.

-- Richard

--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jan 11 '07 #144
Richard Tobin said:
In article <2v************ *************** *****@4ax.com>, av <av@ala.a>
wrote:
>>possible i'm the only one in think that standard C is wrong on
definition of size_t?

Certainly the modular arithmetic used for unsigned types is usually
inappropriate for sizes,
Why?
but so are signed types. And presumably the
standards committee would not be willing to invent a new kind of
integer for this purpose.
And it's easy to see why not, if you try doing so for yourself. What
characteristics should such an integer type have?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 11 '07 #145
In article <vI************ *************** ***@bt.com>,
Richard Heathfield <rj*@see.sig.in validwrote:
>Certainly the modular arithmetic used for unsigned types is usually
inappropriat e for sizes,
>Why?
Because the space required for A bytes and B bytes is A+B bytes, not
(A+B) mod (SIZE_MAX+1).
>but so are signed types. And presumably the
standards committee would not be willing to invent a new kind of
integer for this purpose.
>And it's easy to see why not
Yes.

-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jan 11 '07 #146
av
On Thu, 11 Jan 2007 12:31:53 +0100, av wrote:
>On Wed, 03 Jan 2007 09:58:35 +0100, av wrote:
>>the "problem" is not in calloc or malloc but it is in the mathemaical
model ("modello matematico") used for size_t

possible i'm the only one in think that standard C is wrong on
definition of size_t?
because i have some time to troll, here it is the right model for your
"beloved" ssize_t and size_t
------------------------------------------
Signed
int32_t a,b;
/ INT32_MIN, if a or b or both are INT32_MIN
/ INT32_MIN, if the result is not the usual mathematic result
a@b=v{
\ mathematical correct result

where @ is in { +, -, *, /, %}
If i want to see if the computatiton that use +-*/%
is correct is enought to prove
result is in [INT32_MIN+1..IN T32_MAX]
------------------------------------------
unsigned
uns32_t a, b;
/ UNS32_MAX, if a or b or both are UNS32_MAX
/ UNS32_MAX, if the result is not the usual mathematic result
a@b=v{
\ mathematical correct result

where @ is in { +, -, *, /, %, <<, >>, &, |, ~}
If i want to see if the computatiton that use +-*/%<<>>&|~
is correct is enought to prove
result is in [0..UNS32_MAX-1]
------------------------------------------
i say i trolling because i'm not sure to be right
can i say only that it seems to me useful
Jan 11 '07 #147
Richard Tobin said:
In article <vI************ *************** ***@bt.com>,
Richard Heathfield <rj*@see.sig.in validwrote:
>>Certainly the modular arithmetic used for unsigned types is usually
inappropria te for sizes,
>>Why?

Because the space required for A bytes and B bytes is A+B bytes, not
(A+B) mod (SIZE_MAX+1).
Sure, but at some point you have to accept that A+B doesn't make sense. It
may well be that implementations need to supply a wider size_t than they do
at present, but when all's said and done, there are (according to
Schneier's "Applied Cryptography", 2nd edition) only 2^265 atoms in the
Universe (not including dark matter). If we could store a megabyte of data
in each atom (ha! why not?), that would be 2^285 bytes, right? So if we had
a 285-bit size_t, it would be able to store the sum total of the sizes of
all the objects it is possible to create in a Universe-sized computer, so
there is simply no point in having a size_t wider than that (unless you're
into parallel universes). If we confine ourselves to the Earth, we have a
mere 2^170 atoms to play with, so - even given that rather optimistic
megabyte per atom - a 190-bit size_t would do the trick nicely, and modular
arithmetic would become rather irrelevant.

We live in a real world with real limits, and it's high time that computer
programmers got used to the fact.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 11 '07 #148
Richard Heathfield <rj*@see.sig.in validwrites:
We live in a real world with real limits, and it's high time that computer
programmers got used to the fact.
But integers are *so* much easier!
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Jan 11 '07 #149
In article <eb************ *********@bt.co m>,
Richard Heathfield <rj*@see.sig.in validwrote:
>Because the space required for A bytes and B bytes is A+B bytes, not
(A+B) mod (SIZE_MAX+1).
>Sure, but at some point you have to accept that A+B doesn't make sense.
I'm not really arguing that size_t ought to be a different type, just
agreeing with someone that it has a problem. And we've seen that this
problem is not illusory, because several implementations have a bug in
calloc() because of it.

There are various ways it could be improved, some more and some less
C-like:

- use an arbitrary-precision type. Handy, but not really C.
- use a larger but fixed-size integer type. This is happening anyway
with 64-bit systems, but is still susceptible to the calloc() mistake.
- use an integer type that is required to signal overflow. This
seems like a plausible extension.

The overflow-signalling solution seems like a good idea to me; I imagine
the main problem is that it is not efficient to implement on all systems.
>We live in a real world with real limits, and it's high time that computer
programmers got used to the fact.
Having programming languages check these limits has advantages.

-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jan 11 '07 #150

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

Similar topics

5
2201
by: Jack | last post by:
Hi, I am trying to get a thorough understanding of a code where a addition or deletion of records can be done from a list of records. For addition part of the form, data is being obtained from set of input boxes. The following is the code being used: If Len(Request.Form("ID_0"))>0 Then AuthorID=Request.Form("ID_0") FName=Request.Form("fName_0") LName=Request.Form("lName_0")
4
2885
by: SP | last post by:
Hi I have a problem with a customer's XML being submitting to me in a non-well-format XML. They said that there are 18 other partners who has been able to tweak the XML to make it work. So I guess here is my question, in ASP, when working with XML, how do you handle non-well-formed XML documents on the "listener" response side? Here's the scenerio: Customer post XML Data to us (non-well-formed XML)
7
4148
by: Shapiro | last post by:
I have a scenario where I log a resquest to a database table and update the request with a corresponding response including the response time. I am using an HttpModule to do this. My challenge is how to corelate the response to a corresponding request. I am looking for a sure proof threadsafe way to corelate a response to a coresponding request message. Two things that concerns me:-
4
1580
by: Nalaka | last post by:
Hi, I have some request specific data that gets created in a "early event", that I need to pass around to many other events. I need access to this data during that request. (and more importantly disapears after the request is completed). But... asp.net "Request" is read only. Is there a request specific global place, where I can put this data into?
5
20090
by: dougwig | last post by:
I'm trying to handle the scenario where a user's session times out and and their ajax request triggers a redirection by the webserver (302 error?). I'm using Prototype 1.4 and the my works great with Firefox,but with IE6 the onFailure never gets called and the request never completes. My code: var ajaxReq = new Ajax.Request( url, {method: 'post', parameters:
4
3772
by: Michael Kujawa | last post by:
I am using the following to create an SQL statement using the names and values from request.form. The loop goes through each item in request.form The issue comes in having an additional "and" at the end of the loop and the value of x3 as not all options may be selected from the form yet the loop goes through the entire request.form list I have to add addtional code to strip off the last "and" and was wondering if there is a way to...
6
4984
by: santhoskumara | last post by:
How to request to servlet from Ajax and also I got the DOM object in the servlet through Business Logic. Now how will i pass the DOM object from serlvet to Clientside. Where in the client Side i am using Ajax. kindly advice me.
2
6311
by: MDANH2002 | last post by:
Hi From VB.NET I want to simulate the POST request of the following HTML form <html> <title>HTTP Post Testing</title> <body> <form action=http://www.example.com/postdata enctype="multipart/form-data" method="post" name="testform">
5
6138
by: chromis | last post by:
Hi there, I've recently been updating a site to use locking on application level variables, and I am trying to use a commonly used method which copies the application struct into the request scope. Application variables are then accessed in this manner Request.App.<Var>. To begin with I had a simple functioning login system inside a subdirectory named admin, this subdirectory had it's own application.cfm, I wasn't sure whether to duplicate...
3
1773
by: Joseph Geretz | last post by:
I'm using the Request Filter documentation which can be found here: http://msdn.microsoft.com/en-us/library/system.web.httprequest.filter.aspx In this example, two filters are installed, one filter uppercases every alphabetic character and then the second filter replaces every 'E' with "#'. OK, very nice. What's trivial about these examples is that the returned string is exactly the same length as the string which is actually read...
0
9705
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
10568
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
10323
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
10311
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
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.