Re: pointer q




"RSoIsCaIrLiIoA" <zz@xxxx> wrote in message
news:9odg62tc13dv6m60mlsq19h4caf5ff06ij@xxxxxxxxxx
On Sun, 14 May 2006 08:48:41 -0400, Eric Sosman
<esosman@xxxxxxxxxxxxxxxxxxx> wrote:
Joe Smith wrote:
[motivation]
Assume sizeof(int) < sizeof(long), and consider

long l = 42;
int *ip = &l; /* illegal, but Let's Pretend */
*ip = 76;

What value is now stored in `l'?

That's why int* and long* aren't interchangeable.

and so where is the problem?
the problem is different cpus store data in different ways

here

#include <stdio.h>

int main ( void )
{int l = 42;
short *ip = &l; /* illegal, but Let's Pretend */

*ip = 76;
printf(" sizeof(short)==%u sizeof(int)==%u \n",
(unsigned) sizeof(short), (unsigned) sizeof(int));
printf("l==%d\n", l);
return 0;
}

sizeof(short)==2 sizeof(int)==4
l==76

all ok

the problem is "it is easy to obfuscate and make difficult
what it is easy" and it is in the cpu design

another example could be why not exchange "str* and sprintf, etc"
with a secure
int s?prinf(char* strig, int size_of_string, char* fmt, ...);?

because it is easier "to do difficult what is easy" then
Bugtraq is full of error for the C language

#include <stdio.h>

int main ( void )
{long l = 420000;
long *lp = &l;

short *sp;
*sp = (short)*lp; /* ill-advised, but Let's Pretend */

printf(" sizeof(short)==%u sizeof(int)==%u \n",
(unsigned) sizeof(short), (unsigned) sizeof(int));
printf("in order, ell then the short %ld %hdh\n", l, *sp);
return 0;
}
/* end source */
Now that you bring this snippet up again, I think this code shows why it's
usually a bad idea to do things along this line. I'm not sure that this is
what Mr. Sosman was getting at. As to the syntax on the printf, I've done
everything short of Dedekind cuts on table B-1 and am still pulling out my
hair. I'm afraid that I don't know what Bugtraq is ... probably at my own
peril. Am I correct to think that a type of masking occurs here? joe


.



Relevant Pages