Re: [SLUG] [OT] C pointer allocation

2004-06-20 Thread Jamie Wilkinson
This one time, at band camp, Benno wrote:
>On Mon Jun 21, 2004 at 14:28:15 +1000, Rajnish Tiwari wrote:
>>int foo()
>>{
>>  char* bar;
>>
>>
>>};

>Anyway, unitialised means undefined. If you want it to be zero you
>need
>
>char *bar = NULL;

you can add -Wall to the gcc command line and it'll let you know if you're
using an uninitialised variable:

willow% gcc -Wall -Werror -c foo.c
foo.c: In function `foo':
foo.c:3: warning: unused variable `bar'

and the -Werror will make that warning an error and refuse to generate
an object file or executable.

-- 
[EMAIL PROTECTED]   http://spacepants.org/jaq.gpg
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] [OT] C pointer allocation

2004-06-20 Thread Rajnish Tiwari

Ian Wienand wrote:
From there, try to learn about ELF and things like sections and
symbols, and understand how the compiler, assembler and linker work
together.
Hmm ... I certainly should have been paying more attention
and showing more interest back in uni days !!
Thanks for the pointers - this is the kind of stuff I need.
In particular, I am trying to determine why a program is
behaving differently on 2 machines with same OS but different number
of cpus (2 cpu vs 8 cpu).
Regards,
Raj
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] [OT] C pointer allocation

2004-06-20 Thread Ian Wienand
On Mon, Jun 21, 2004 at 02:28:15PM +1000, Rajnish Tiwari wrote:
> Any thoughts, suggestions, weblinks etc will be appreciated.
> Thanks in advance.

I'm sure you've got answers to the specific questions.  But if you
want to learn exactly what is happening, start googling for "stack
overflow phrack" (especially something like Smashing the Stack for Fun
And Profit) and you'll get some really useful tutorials to start
learning how the stack works (and maybe be able to write your own
buffer overflows).

From there, try to learn about ELF and things like sections and
symbols, and understand how the compiler, assembler and linker work
together.

Have fun!

-i
[EMAIL PROTECTED]
http://www.gelato.unsw.edu.au


signature.asc
Description: Digital signature
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] [OT] C pointer allocation

2004-06-20 Thread Benno
On Mon Jun 21, 2004 at 14:28:15 +1000, Rajnish Tiwari wrote:
>Hi All,
>
>In C, I have the following declaration:
>
>int foo()
>{
>  char* bar;
>
>
>};
>
>If unitialised, what the the value of variable "bar" ?
>Will it get initialised to 0 or be a random value ?
>Is the value allocated at runtime or compile time ?

Well it isn't going to be random exactly. But it is going
to be undefined. (It will be whatever happens to be on your
stack at the time.)

Anyway, unitialised means undefined. If you want it to be zero you
need

char *bar = NULL;

Cheers,

Benno
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] [OT] C pointer allocation

2004-06-20 Thread Rick Welykochy
Rajnish Tiwari wrote:
In C, I have the following declaration:
int foo()
{
  char* bar;
};
If unitialised, what the the value of variable "bar" ?
printf("%x",bar);
Will it get initialised to 0 or be a random value ?
see above
Is the value allocated at runtime or compile time ?
what value? you did not initialise bar.
cheers
rickw
--
_
Rick Welykochy || Praxis Services
For years, Microsoft has had a policy of announcing products that don't
exist yet, to cause customers to stop buying a competitor's product.
That's Vapourware.  Is it really any shock that they would want to prevent
customers from using more robust OSs and tools, by offering Vapoursecurity?
 -- David Maxwell on Full Disclosure
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] [OT] C pointer allocation

2004-06-20 Thread Jan Schmidt

> In C, I have the following declaration:
> 
> int foo()
> {
>   char* bar;
> 
> 
> };
> 
> If unitialised, what the the value of variable "bar" ?
> Will it get initialised to 0 or be a random value ?
> Is the value allocated at runtime or compile time ?

It will be essentially a random value, but often 0. 
C won't do any initialisation for you, but if it's the first time your
process has used that particular piece of stack, the kernel will
have initialised it to 0. 

If you need a variable to have a particular value in C, always initialise it
explicitly.

J.
-- 
Jan Schmidt  [EMAIL PROTECTED]

Have you been half-asleep? Have you heard voices?
I've heard them calling my name...
 -Kermit the Frog (Rainbow Connection)
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


[SLUG] [OT] C pointer allocation

2004-06-20 Thread Rajnish Tiwari
Hi All,
In C, I have the following declaration:
int foo()
{
  char* bar;
};
If unitialised, what the the value of variable "bar" ?
Will it get initialised to 0 or be a random value ?
Is the value allocated at runtime or compile time ?
Am using gcc on both linux and solaris.
Any thoughts, suggestions, weblinks etc will be appreciated.
Thanks in advance.
Regards,
Raj
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html