so ive been trying to figure out the basics stuff im reading a tutorial about pointers now At the same time im

lol

Known as SIGSEGV up in userland

?

GPF is i386’s generic “You messed up” exception

or Segmentation Fault to the unexperienced C programmer

(General Protection Fault)

you’ll get an error while accessing a non-enabled page… it’s as simple as that

Accessing missing pages, accessing a page as the wrong type.. Accessing missing segments, using segments as the wrong type,…
All these are GPF

a page fault?

Yes, basically..

not all page faults are errors

Indeed.

0×4

Ah.. my mistake
Accessing a _missing_ page is Page Fault, not GPF

how can i reproduce a page fault in a C user space program, for example?

Hardware makes that different – any other error of that sort is GPF though; present but not the right type, or missing segments, or any of about 200 other miscellanous errors in using segments

fault addresses are stored in %cr2 aren’t they?

Hrm.. sounds familiar; but it’s been a while since I looked at it

char *p; while(1) p=*p;

That’s likely, but not guaranteed
Difficult to guarantee to make one, since you can’t see the tables

this is a seg fault
i want a page fault

That probably is a page fault, at the hardware level
Kernel traps it, decides what to do about it
In your case, it decided the page request wasn’t valid, and sent you a FOAD SEGV

It probably has to be a potentially legal address before you’ll get far enough to trigger a page fault. That’s why you can’t be sure of the result.

“segmentation fault” is just a string, can be a “bus error” in 68k.

SIGSEGV is what kernel sends you.
can be totally unrelated to what hardware sent kernel

you can send it to other processes you own, too

_3dfx now i see: i made the while statement in order to obtain a page fault instead of a seg fault?

Many processor have an illegal address interrupt.

anyway i don’t understand the sense of p = *p : how can a value of a pointer be an address?

i think in a x86 machine all types of errors in memory access will be mapped to SIGSEGV.

On Linux, yes.
SIGBUS isn’t used on Linux, all memory errors are indeed SEGV
Not at all..

your program

Ok, now i’m getting confused. i have to study some basic concepts before making other questions

my netbsd/68k machine is very funny, i get many random SIGSEGVs, SIGFPEs, SIGBUSes, etc.

Remember, that between you and the hardware, is the kernel

yes i know that

What CPU says to the kernel, isn’t always what kernel says to you

yes but i can debug the kernel

Reminds me…
I want to draw a comic strip sometime.. I have all the characters worked out

in order to trap the meaning of kernels msgs

General Exception, Col. Panic., Major Error, Field Marshall Error (his brother), and Private Method.
It’s a military cartoon, naturally.

get comic life

ok please tell me if what i’m saying is more or less correct. when from user space i execute malloc, i do a system call to the kernel. the kernel controls if there’s free space in its virtual memory and, if yes it gives the num. of bytes required by malloc to the user space. if there’s not free
space, the kernel try to allocate (for example) a new page…….

Sortof
malloc works internally in userland.

sortof?

It might have free space anyway.
Kernel only works in pages of 4k
malloc a little tiny block, and maybe there’ll be space in the heap

but is the concept right?

Yes, I suppose…

but what do you mean with ” malloc works internally in userland.” ?

malloc works within the heap.. this is a userland data structure the kernel knows nothing about
malloc deals out and takes back free space within this heap
If it runs out of space, it asks the kernel, in chunks of 4k, for more

I see

(Well, there’s also the recent glibc thing of using mmap() for large areas)

and if i do char mychar[1000] the kernel, for the memory management is much “involved”, right?

The normal heap is in what’s called the break area – socalled because long ago it was defined as just a gap – the stack starts at the top and works down, the heap starts at the bottom and works up. The gap in the middle was called the break
Automatic variables live on the stak
*stack
That’s managed by the kernel without you doing anything from userland

ok, so is it true what
i just wrote?

What it does, is marks the next page after the TOS as not present. Any page fault in there, tells the kernel “I want more stack space”, so it gives some more

it seems in this way that objects in the stacks are elaborated more quickly, irght?
right?

Elaborated? hrm? I don’t get the question

i mean:
since the stack is managed by the kernel, objects allocated in it can be accessed more fastly
but maybe my question doesn’t have sense

Hrm…
Once it’s allocated, it doesn’t matter where it lives – access time is the same

No. Not in practice… and C does not specify any of this.

It might be quicker to allocate in the stack vs. the heap, though

Access times could be very different. You don’t know without understanding the specific implementation and system.

i see Xgc

For instance, there’s not necessarily a stack.

since kernel could use dinamic allocation too?

However, I do believe the entire scope of the preceeding conversation was i386/Linux

i tnhink will be more quicker in stack because many cpus have special asm instructions to link/unlink stack space and a dedicated SP register.

But if you have a stack, it could be found/created in some very fast ram or slow ram for this system.

(General-purpose) kernels usually have their own dynamic allocators, which are likely simpler than the userspace ones.

i see Xgc

Even knowing you’re using Linux wouldn’t necessarily mean you know the behavior. The hardware could make a big difference and you might be at the mercy of whatever bank of ram that stack was placed in.

in fact all is the result of the combination OS+HW

Normally, in practice, the timing of ram access in stack .vs. heap is indistinguishable.

i dind’t know that heap is a user space structure

Much of the significant differences in behavior depends more on how pages are swapped to/from disk.

this was interesting to know

The heap is logical address space and (typically) represents both unallocated regions and allocated regions.
Think of it as a place where physical ram may be mapped.
Not so much different than your stack area.

and what’s the basic difference between them?

We just name them differently because of the different uses we have for them.
None other than the way we manage them.

http://www.os-forum.com/minix/net/images/bh_brk_sbrk.gif

One is most often a “last in first out” area. The other can be logically very fragmented.

thnks _3dfx
but a basical difference is that

The stack tends to be continuous logically in memory. The heap is not necessarily logically continuous in the address space.

stack is accessed by kernel

the addresses start in the text (the binary) and end in the stack.

heap bu user space

Not really. Both are managed by the kernel, in the end.
You can’t map memory into the process address space without the kernel.

all these blocks in the figure are in the userspace.

but the heap less directly, right?

Not really.
The process of mapping physical ram to a logical address space is done for both the heap and the stack in most cases.

well, in this case I have to understand exactly how stack and heap are managed

the task calls brk/sbrk() syscall to resize this userspace. for kernel, is just a big area of memory.

so you don’t agree with LeoNerd when he says that heap is an userspace structure?

teh logical space, once mapped, is controlled by the user. But the actual mapping process is probably not controlled by the user, although the user is responsible for the requests to get/free memory.

ok and the paging process is controlled by kernel, right?

I guess we might be splitting hairs here.
Yes.

ok, so returning to the previous question, when the user tries to access to the value of a pointer of unallocated memory, the segfault is something done , in the origin, in user space
right?

Page fault, kernel will see that page is not mapped for that process…and a segmentation fault signal is sent.
* Hopefully

(since user has, as you said, controls on the mapped logical space)

A segmentation fault is the result of a logical access in user space that the hardware flags as a problem. An interrupt occurs.

Xgc, no.
On most platforms it is the operating system itself that will handle the page fault and deal with the segmentation fault appropriately.
That is the whole basis of SEGMEXEC before NX support.

do you mean that a seg fault corresponds necessarily to a page fault in kernel?

The interrupt generally is caused by the MMU, seeing that there is no page mapped to that logical address.

paolo, usually. Page faults are valid, kernel will see that the page is not provided.
Xgc, some hardware do not have a “static” page table :-) Kernel usually handles that.

There can be other types of interrupts as well.

paolo, s/provided/mapped/

?

The interrupt causes the kernel to take action.

Xgc, you are splitting hairs, rather unevenly now. :-)

Whether it’s an illegal address or a legal address that causes a page fault, there’s an interrupt.

Xgc, yes.

A segmentation fault is the result of a logical access in user space that the hardware flags as a problem. An interrupt occurs.

Read the log. I haven’t changed my comments.

s/as a problem//

ok, but if you don’t agree between yourselves it’s a bit complicated for me

paolo, then buy a book :-)

yes, in fact i’m searching
for some infos on google
about this fucking seg fault and page fault

you can start read about old and simples processors, like Z80, 68000 or 8086, and then read about a more complex processor.

anyway, it seems that at least two or three things are fair:
1) kernel manages pages
2) a page fault is in kernel space
3) a segfault is in user space (but the association to a page fault is not fair)

Usually, the kernel will handle the page fault (assuming, the VM is in kernelspace)

yes but it would be interesting to discover how a segfault is “linked” to kernel

paolo, get a book. D&I of Solaris or D&I of FreeBSD. Several linux kernel books too
paolo, there is also the minix book.

It’s done by interrupt handlers.

fucking seg fault

ok, i see but there are too much books about all i have to get in a better way the infos that i need

That just means you’re lazy.

lazy?
no, i’m really not
but i already have to read too much material
and i’m still trying to understand how to organize it

Then get to it :-)

but is malloc a system call?
or does it encapsulate other system calls?
sbrk is the system call, right?

Yes, sbrk is a syscall
69 I think
You should talk less, and study more, paolo.

ok

hoï

sorry

I’m beginner and I try to compilate my first code I’m using lcc-win32

“compile”
congratulations, on your first attempt.

i want to say execute
lol

do you have a problem?

related to C that is

yep

if your program dont control nuclear weapons, i think you can try compile and execute.

how to use lcc to work with

you forgot linking
this problem is not related to C though

lcc is horid.
all win32 compilers are horrid.

s/compilers//

can you play? …with me!!! try http://s10.bitefight.it/c.php?uid=3145

get out

lol
I’m playing with code
dotatoe my first language that I start to work with was java and I did never learn c

so?

you dont have the make program ? make will know how compile host and link.

did you ever see a girl involved in kernel’s programming?

yes.

really?

i’m sure there are

was she a pretty girl?

yes, the girl that’s lying on my bed right now.
what does this have to do with C

i don’t know
you are always hungry!

are you unable to study?

you are always angry!

how did you know that Im girl :s

*what the hell*
*what the hell too*

dotatoe could you explain me how to execute my first code..
plz

are you using an IDE?

you have the make program ?

lcc

if so, click ‘compile’
I think lcc works by entering lcc prog.c
But I could be wrong.

yes it’s exactly that
but I don’t know where to find it

hmm, cmd.exe?

lol.. oO

what do you want with make without a makefile? make is just dumb and will not know how to build anything

i don’t get it either.

xD

runs cmd.exe, go to directory and type make program (if you have a program.c). if dont work, your computer will self-destroy in 3 seconds

something is wrong here :o
you get outta here

Hello – so that I don’t reinvent the wheel – might you guys have by any chance an already written float-string routine?

make will try all possible combinations. if you type make program, make will search for program.s, program.c, program.cc, etc.

lol

i know you ?

do something, but fast

so, i’ve been trying to figure out the basics stuff, im reading a tutorial about pointers now. At the same time im analyzing the examples programs using gdb, and ive been wondering: typing “print someptr” in Gdb seems to display the exact memory adress, but “print &someptr” always display the same address, like 0×404080… whats the difference?

&someptr is probably not really good

it seems quite random, actually. not that its different everytime I type that

whare are you expecting of &ptr?

AFAIK, lcc-win32 also comes with a manual

& is address-of

thats pretty much what i was thinking, too

so whare are you expecting from &ptr?

basically the address for ptr

I run gmake and gcc, and I aint never called malloc without callin’ free

the address of ptr will no change. ptr can change and *ptr can change, but the address of ptr will never change.

but you said… typing “print someptr” in Gdb seems to display the exact memory adress

my reasoning behind this is: ive tried some basic examples programs from a tutorial, and everytime I compiled and checked the values in gdb, &someptr was always 0×404080, with every example programs I tried, which seemed quite odd from my newbie eyes :P

poor
é_è
I’m leaving
bye

will never change because the pointer is stored in the same position.

Hello

put a printf(“%p\n”,&ptr) in your program

are you saing here that, for instance, the stack always starts at 0×404000 and goes up everytime we add a new variable to the bunch?
(I understand YMMV from a computer to another, dont worry)

if the function is not recursive.
&ptr shows the address of ptr in the stack.

apparantly it actually goes down on most computers

if your function is recursive, &ptr will shows a diferent position in stack.

can anyone recommend me a book to learn c? I have been programming for years, languages like java hosting or php, I mean, I do now need the book to explain me what a while is

The C Programming Language, 2nd edition
k&r

k&r is The C Programming Language, 2nd edition, by Kernighan and Ritchie, http://cm.bell-labs.com/cm/cs/cbook/ – be sure to see the errata as well, at http://cm.bell-labs.com/cm/cs/cbook/2ediffs.html

Does sizeof() return the size of the object in bytes?

yes

but 0×404080 is too small for stack :P

i dont have a book to recommend actually, but ive read a few in a library and I always had a hard time understanding the pointers and stuff. Ive just found a well written tutorial on the net only about the pointers, which I may recommend as an addon to a book: http://home.netcom.com/~tjensen/ptr/pointers.htm

can someone remind me what the system call on Linux is to convert a network byte order ip address into a string?
I’ve forgotten…

Well, I preffer books, i *cant* read a lot in the web

inet_ntop

oh.. (but thats a _tutorial_, not the bible, too :P )

well, I’m reading about paging. it says that paging is a task done by the kernel (as we said before). Now, given that malloc makes a system call to the kernel (through sbrk), are the paging task and sbrk depending one on each other?

oh yeah, thank you

What is a better/safer way of parsing argv[1] for an int other than using atoi() and hoping for the best?

strtol

either way, thanks for the tips

ty
Do you know what debian package contains all the C function man pages?

no

hm I can’t find it – have to keep checking the web ;-)

SamB, yes but, some people says that kr is boring

some people…
why did you come here?
here are some people saying k&r is sufficient good enough
in c++ some people say learn c++ instead of c

this isnt a matter of a specific channel

K&R is good enough to *start* and the people from c++ are loosers, they dont know what are saying

just saying that asking that kind of question is pure asking for a subjective answer
no need to comment on k&r

yes subjective

? :
s/://

I mean, I know that the answer is pure subjetive

good

it’s up now
i’ll get a stage tarball and download.
it should take a while however :/

?

hi, how declarate array

what an insightful question

hi, how book says?

hi, how is sun?

Captain Obvious to the rescue?

sorry, wrong chan.
Bilange:
People become offended by such things.

your /whois and my one have similar things dotatoe :P

ugh
this means we have to be friends now.
i had a problem with my ipw2200 driver, and the 2007.0 installer, so i’m using the 2006.1 livecd now :/

don’t use the installer
rule no. 1

rule no. 2: for each gentoo ricer you exterminate, jesus loves you better!
rule no. 2: for each gentoo ricer you exterminate, jesus loves you better!

there, you’ve found the floor

why do you want to exterminate some gentoo “ricers”? if I had to exterminate one kind, i’d go after the Honda Civic kind of ricers :P

just joking ;-) besides, i don’t want no jesus love, anyhow. tell that nigga that we want forty virgins, like those islamic jihadists get!

i’ll get the minimal shortly.
for now i haven’t an alternative.

why not?

really dumb question, i’m trying to illustrate pointers to someone and i’ve been pampered for too long by c++ streams. gcc doesn’t like my line printf(“&bar: %X”, &bar); why?

i doubt someone can proof that there will be 40 virgins

every os/livecd that has chroot some basic net tools like wget is just fine dotatoe

yeah.
the gui installer is pretty crappy.
i have slow net

means?

it’s taking the minimal sometime to download.

you don’t have to, let’s talk in private jvm java server hosting for a bit since this is coming too much off-topic

and what’s the output ?

compile time error, once sec
ohh, dammit
it was a warning, i should learn to read
lemme see if it behaves as expected before i get too happy though lol
blemme see if it behaves as expected before i get too happy though lol/b

i’d say you need a cast to int to get rid of the warning

oh you’re in a good mood today vorpal

i have my moments ;-)

i’ve send you a message in private :P

is this like “You got mail!!”, but version 2.0?

hmm.

read another day 5.0

i have a dumb question about gets()! — i dont understand how it is possible for gets() to pull the last two bytes after a NULL byte and overwrite cookie in this example
http://community.corest.com/~gera/InsecureProgramming/stack3.html

perl -e ‘print “A”x80 . “\x05\x00\x02\x01″x1′ | ./stack3

it would appear to me that cookie should be overwritten by only one byte, and not all four

buf is undefined, you gets() garbage

madx, ?
im talking about cookie, you think it is contains 01 02 ?

hum
what do you enter in stdin ?

perl -e ‘print “A”x80 . “\x05\x00\x02\x01″x1′ | ./stack3

why do you think, all four bytes are overwritten with the code you pasted?

yes they are in this case

did you check in the debugger?

but not for cases where newlines are
kessel, yea
gdb
kessel, i was just retarded .. gets is newline terminated, not NULL terminated

hi
i am bored

go outside then

hmm

that’s where I’m headed soon

Scorpions, longview…

what’s so good about the outdoors?

read a book

long time no see?

that is fun?

yes :-)
or watch a movie, how about Zeitgeist

i have been reading a book, inside machine

http://digg.com/videos/educational/Zeitgeist_Movie_Must_See_Documentary

the

I’m reading a file into a char** with lines. I’m wondering how I can dynamically expand this. I’m about to try: lines + 1 = malloc(sizeof(cur_line)), then strcpy(lines+1, cur_line) but I’ve a feeling that’s very wrong – how can I do this?

ok this is weird
and why i was having issues before, now i dont know, but i think i found abug in gets()

realloc?

There’s a shock. Why are you using gets?

ok… but is that the best way to do it?

The bugs in gets are by design. You can’t use it.

if gets() receives a stream of non-NULL chars, it copies fine into the buffer

How do you intend to prevent buffer overrun when using gets?

with your type you don’t have much choices, also you can use a linked list

but when ended with a newline and containing NULL chars, they dont necessarily make it into the buffer
Xgc, i dont

ah, ok, I’ll use a linked list I think

Xgc, but still it is broken otherwise

memory/speed

Xgc, my point is it should either be fixed or removed

what are the pros/cons of each?

You can’t have embedded ” chars in the data. That’s not valid.

Xgc, and why not?

a linked list, needs more memory for the link pointers, but additions are more quick

Because there’s no way for you to know where the end of input is.

ah, thank you

Xgc, gets() ends with \x0a not \x00
according to the docs
it is newline or EOF terminated
not NULL

khermans, you mean NUL chars
not NULL

what is the difference?
\x00

NULL = pointer, NUL = 0byte or /terminator

No. The buffer gets fills is terminated by ”. It’s a C string. If you have an embedded ” in the data, this does not form a valid string.

zacs7, well fine, then NUL

khermans, use fgets not gets

Xgc, no!

Yes.

froman page
“gets() reads a line from stdin into the buffer pointed to by s until ither a terminating newline or EOF, which it replaces with . No heck for buffer overrun is performed (see BUGS below).

khermans, fgets isn’t binary safe
It’s not a bug

Xgc, i know how to use fgets, i am asking about bugs in gets

“Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets()
will continue to store characters past the end of the buffer, it is extremely dangerous to use. “

genelisp, yes i know it stores past end of buffer

note the “Never”

genelisp, maybe he’s a risk taker :P

The bugs in gets are by design. It’s not usable by design.

genelisp, ok so if no one should use it, then it should be removed :-)

gets was a mistake. There’s nothing you can do about it.

Xgc, but you are still wrong about NUL

Xgc, it’s not a bug

the terminator is \x0a

stop calling it that

gets reads until a newline is found (or other cases) and replaces the newline with ”

thats right
not other cases…EOF is only other case

khermans, what are you going on about anyway?

zacs7, nothing, just found something interesting about it handling NUL

If you have an embedded ” in the buffer, you can’t know where the real ” (end of line) is.

which is not specified in docs
Xgc, there ya go!

In other words, gets is NOT binary safe

Xgc, but you mean \x0a

It’s obvious. You can’t use it.

that is end of line
zacs7, i dont know what you mean by binary safe?

We call it a newline. No. I’m talking about the end of buffer that gets sets.

if you use ‘+’ incorrectly, is that not binaary safe?
Xgc, you call a newline?

gets replaces the newline found awith ” to show the end of buffer.

i would call \n a new line
Xgc, yes you are correct there
Xgc, but it doesn’

If you have other ” chars you can’t know where the real end of buffer is.

end on \x00

http://stopgeek.com/sense-this-picture-makes-none.html

Xgc, i am looking at source now, wondering why that is though

couldn’t resist linking it

We know we have a brken windmill. Why are you fighting it?

i laughed hard

Xgc, remove it :-)

drdo, lol

remove gets() unless it is there for utility

it’s in the specification. It’s not removable by anyone other than the standards committee.

its obvious that Vader is cleansing the ocean by puttint it through a filter

khermans, it’s there cause it’s fine if you know how to use it and the dangers.

zacs7, right, but my point is that gets() does not operate how it says it does via the documentation
that is the problem

There’s no safe way to use it. You can *hope* the data does not damage your program. But that’s the only option.

although, it also says “NEVER USE IT”
hehe

Xgc, you know what I meant

but last question to solve, why can’t it know the end of buf if it has \x00 ?
ubut last question to solve, why can’t it know the end of buf if it has \x00 ?/u

khermans, do a pastebin :|

zacs7, of the gets() source code?
http://rafb.net/p/gEPxL543.html

Because you can’t tell whether the ‘’s you encounter are your ” data or the end of buffer. How do you know when to stop?

Xgc, omfg we already went over this
Xgc, gets looks for \x0a not \x00

You keep asking the same question.

Xgc, look at the source

Xgc, he’s not asking anything

look at line 19

No. I mean *you* (after gets returns) can’t tell where the end of buffer is.

\n == \x0a
Xgc, why do i care?

There is no \x0a in that buffer.

which one?

khermans, using \x0a instead of \n doesn’t make you hardcore.

Are you just trolling or do you really not understand?

khermans, \n is never added to the buffer

Xgc, i understand quite well
i understand that \x0a is replaced by \x00

gets replaces the \n char. That char is NOT in the returned buffer.

thats right
zacs7, hardcore? i am trying to differentiate between \x0d, which is not \n

I know gets knows where the end of buffer is. But your program can’t.

khermans, you understand stdin is a stream yes!?

zacs7, absolutely

anyway, pie time. Try not to kill each other

zacs7, still havent solved it

khermans, solved what!?

the fact that gets() is document improperly

He’s asking why gets isn’t fixed.

Xgc, not the function, but the docs

Which documentation, linux man pages?

Xgc, gets() man page claims that it will copy everything into buffer until \n
more or less
Xgc, yes

What don’t you line about that?
s/line/like

Xgc, because it is not true
Xgc, in the case of \x00

What do you want it to say?

Xgc, i want it to explain why \x00 are bot allowed in the stream
not
and you still have not shown me why in the code this is the case
i linked you to the gets() source

The C standard also does not talk about ” in the input stream.
The man page is just following the specification.

Xgc, right so it should be allowed in the input stream

khermans, it says it’s not binary safe ffs!

zacs7, and what do you mean by ‘binary safe’ ?
zacs7, of course it is an exploitable function call

hi zacs7 void main()

hi dotatoe int main()

my point is just this, \x00 should be allowed in the buffer, and xgc argument that it can’t determine end of buffe ris not correct, since gets() looks for \x0a not \x00

khermans, gets() – “Reads characters from stdin and stores them as a string” is a give away

zacs7, what docs say that?

http://www.cplusplus.com/reference/clibrary/cstdio/gets.html

The C specification doesn’t mandate you write well defined programs. You are free to feed ” to gets. Nobody said you can’t. Don’t expect good behavior.

zacs7, well what i am saying is that \x00 should be allowed, it wouldn’t be a problem until your program “interprets that buffer”
but the \x00 never make it into the buffer

dotatoe, why are you having a go at me? I said void main was probably C++0x standard

in the first place…

zacs7:

So you think gets() should return any s it finds?

I don’t mean to be mean.

Like I said, don’t expect good behavior.

dotatoe, it’s okay :P

I’m going to cook some ramen now ;D

Xgc, sure, but i think i made my point, its fucked

khermans, then gets() wouldn’t return a string.
rather a valid string

zacs7, sure it would, it would just be a string with extra crap

khermans, a C string stops at the first NUL character

when you interpret that buf, pass to printf whatever, you only get up until the first \x00
right, but gets() never copied that \x00 into the buf!

yes khermans, you only get the first string *clap clap*

zacs7, this is obvious

Is it? Why are you arguing then?

my point is the implementation of gets() and the docs, which are wrong

khermans, so go fix them

zacs7, is houldnt be using them :-)

It goes without saying that you can’t use the “end of buffer” marker in your data. If that isn’t clear to you, you have a problem, apart from arguing about a function you should *never* ue..

well, i came to ask technically why they aren’t remove then

s/ue/use

khermans, cause you’re supposed to steer clear of gets

Xgc, fine fair enough
Xgc, i was just trying to get at the heart of the issue…
Xgc, gets() docs should be rewritten to say “copies a stream from stdin into buf s until a NEWLINE or EOF character is encountered, which is replaced by NUL, but this stream cannot contain any NUL characters preceding the NEWLINE character which signifies the end of this stream”
which is convoluted, but i guess correct implementation
there is no technical reason why gets() couldn’t read in a buf with NULs, then encounter a newline, and replace that with a NUL … your printf would only get up to your first NUL, but gets() would still function properly
gayness

I see khermans !!!!
I see where your coming from, are you arguing that gets() reads more than a valid C-string?

0×41414141 0×41414141 0×00665541 0×53530088
perl -e ‘print “A”x80 . “\x55\x66\x0a\x88″x1′
you see buf \x gets replaced
whatever!
fuckers

that wasn’t very nice.

sorry .. :-(

hi i have a huge problem with the k&r exercise

coming from you dotatoe

1-13

_d which is!?

ow
alguem saka da norma 568 A

English perhaps? :P

it says write a program to print a histogram of the lengths of words in its input
im not sure how to go about that
(

sorry

_d, you know what a histogram is?

a diagram

ya, a bar chart

oh
im still not sure how to go about this, could you give me any pointers?

_d, count words lengths (ie the closest space to the word to the closest space at the end of the word)

*pointer;

It’s probably expecting too much to ask the C specification to provide programming advice. It’s really up to the programmer to make reasonable choices.

Then maybe an array of length ranges (ie, int freq[5]; where freq[0] = [0,2] and freq[1] = [3,5]) or something
then draw a graph of freq (ie with 5 columns)

Xgc, ok ill accept that

_d, understand ? :P

is that c

what C?
[0,2] = maths

int freq[5]; where freq[0] = [0,2] and freq[1] = [3,5]

Ie, 0 to 2 inclusive

is that c

no

bye _d

dotatoe, why are you always sarcastic ? :|

because i’m bored

k

i’m going to cook some ramen now.

you said that before.
You’re such a liar :P

i didn’t leave.
i couldn’t stand up, because i was reviewing some src

dotatoe, then find some 0day
make it interesting

there’s 0day in gnupg.

dotatoe, its not 0day after release
dotatoe, there is 0day in everything
zacs7, btw my point was that gets() is not strcpy()

ahh k

If I have a static function foo in a file and another function bar in the same file sends a pointer to foo to a function in a different file. Is that ok?

peter_12, depends what the pointer points to
and what scope it’s in

the internets failed.

zacs7 the pointer is to the static host function

peter_12, as in a function pointer to that function?
that’s fine

seems like it is sort of breaking the scoping

well, all static means is the name isn’t exported

ahh
thanks. I’ve never worried about this aspect of C before. It is actually a big joy trying something in C after so long

np

so when an object file is created, there is a list of symbols to export?

jesus, people write code horribly.
like they spat all over it

peter_12, yeah, normally a function is exported so that it can be linked from other files, but when it’s static it’s excluded.. if you’re using *nix you can get a list of things that are exported in an object file using nm

ch28h so i can! that is great!

is it wrong to look at someone elses source code, and create your own implementations from them?
like with this histogram program
i’ve found a similar program which i want to study and create my own implementation from

Hi
I’m getting this weird error when I try to compile something with avr-gcc.
/usr/lib/gcc/avr/4.1.2/../../../../avr/bin/ld: crtm168.o: No such file: No such file or directory

Cerin, I suggest visiting the support channels for this “avr-gcc”

I think that’s self-explanatory, eitherway.
No such file or directory
:o

It’s more of a general make/compile question.
you’d think, but it’s not

Cerin, no, it looks like a broken linker.

I’m using -L/usr/local/avr/lib/avr5 when I compile, which is where that .o file exists.

Guh

anyone???

That’s how you specify library paths right? With the -L flag?

_d, all depends on the license associated with the other code

The linker should be able to see the objects in that path.

usually, but that is left to the implementation.

_d, if the license allows it, then that’s fine

I’m using GCC on Linux, so everything should be pretty transparent.

_d, often the only requirement for something like that is that you acknowledge the contributions of the original authors and release the code of your program as well

Cerin, you should try the GCC channel, where people are more likely to know the answer, since it’s actually on topic there.

cn28h, i mean like is it right, as a coder to
look into someone elses source
if their license allows for it

ok, thanks

and make your own implementations off it

code is written to be read.

because im really not sure how to go about making a histogram program

_d, like Draconx says.. code is published to be read.

:P PP

punctuation, proper English, and don’t stick your tongue out at people who are giving you good advice.

Quartus, thanks

can someone explain to me why exit in the PLT defines a a jmp to _init+24, but there is not code there?
_init ends at _init+22 with a ret instruction on x86 gcc

Someone have blog to him see

so init function is 22 bytes long?

blog C…developer, linux ….

fez, yes
fez, _init
c mangled
(gdb) disass 0×080482fa
Dump of assembler code for function exit@plt:
0×080482f4 exit@plt+0: jmp *0×80495c0
0×080482fa exit@plt+6: push $0×18
0×080482ff exit@plt+11: jmp 0×80482b4 _init+24
sorry
(gdb) disassem 0×080482b4 — No function contains specified address.
(gdb) x/x 0×080482b4 — 0×80482b4 _init+24: 0×95ac35ff
weird…

try disassembly the binary with objdump

_3dfx, surei can do that
i was just wondering why gdb doesnt seem to think it is part of the function

gdb is a bad guy :/

I need to use 32 bitmasks where only 1 bit is set, should I pre-create them and keep an array of them or just create them with shifts on the fly?

Ramen!

use anything like #define CPU_FLAG_X (14), for example. the code will be more legible and the compiler (, ops *a good* compiler) will change the shift for a constant.

ahh, good point …
because I need 32 of them :P
what about shift(x) (1x)
with a #define …
or a ahrd-coded table is “better”?

well, how yoda says, use the legibility luke. if the shift is part of the logic, you can use the real shift to enfatize this. if the value is a constante, the define is better.

the masks will be constant
they won’t change

for example for(i=0;i!=32;i++) *p++ = (1i); is more legible than for(i=0;i!=32;i++) *p++ = shift(i);

well, I will be using them in “setting/unsetting” bits in an unsigned int
also for 0, I don’t think the macro will work …
since 10 is 1

i think these masks you use with and/or, p |= (1x) to set the bit x, p &= ~(1x) to unset

yes, that is what I will be doing
and p ^= (1x) to flip
what if I hardcode the array? would the compile hosting still recognise the constants and that they don’t change?

i think the code will be more faster.
if you are coding a videocodec, any nanosecond is good
you must decide if the extra work is valid for your application.

which one?
I will eventually use this for my own huffman implementation
I have an older version of my try when I wasn’t so good :P

ohh, huffman ? make the array! hehehe

?

this is part of it … I want to actually have a bitarray, not an array of chars or ints

if you will use, make faster hehehe

thing is I need random access (mask(x)) …

you can declare a struct with individual bits.

why not an array of masks?

http://www.cs.cf.ac.uk/Dave/C/node13.html
because looks more evil and obfuscated ?

something like mask[x] and you know that the xth bit is set

see the bit field struct
hmm ok, will work too. i used this in a palmpilot video driver.

interesting …
I’ll stick to the array …
because x can be (and probably will be) an expression

you can create two arrays, to avoid the ~ operation when unset a bit.

consider a[x3] & ((1(x&7)))

http://www.firstcoastnews.com/news/strange/news-article.aspx?storyid=76141
An 84-year-old woman who confessed to having sex with an 11-year-old boy in her foster care reached a deal with prosecutors and pleaded guilty Thursday to attempted sex abuse, officials said.
she got 3 years. old hag

Hi, I have a simple if instructions, http://pastebin.com/m7c8c793f, but when I compile it under gcc, I get “error: expected identifier or ( before if” and “error: expected identifier or ( before else” what seems to be missing?

do you think I should?

don’t hate the player — hate the game.

Zhivago-: I will not be doing things like that

if it was a man he’d be serving life

i think you can test all these options and choice the faster.

it’s typing of the code :P

then you will probably be disappointed in C.

Zhivago-: how come?

because C doesn’t have bit arrays

Zhivago-: that is exactly what I intend to “fix”

how long do you think it will take to change the standard?

Zhivago-: I don’t care about the standard, I need it for myself :P

Zhivago, when C 3089 comes out

jbjuly, your code seems to be missing parts.

“Incurred fault #5, FLTACCESS ” is this a generic error that causes a bus error? i know what i changed that caused it but not sure why it is happening any ideas?

jbalint, that’s a horrid brace style too

Received signal #10, SIGBUS [default]

I got a quick question on goto.
and lables
can I assign a label to a variable somehow and make the goto use it?
somewhere b: somewhere

gtp, don’t use goto or labels

gtp, not in C.

k thanks Draconx

SIGBUS ? what cpu are you using ?

spark

zacs I need gotos for an iterative alphabeta search

sparc
sorry

gtp, you can design it so you don’t…

bigjohnto, most common cause of SIGBUS is probably unaligned memory accesses.

it happens when i am reading strings from a file

so I’ve decided to switch majors
2 semesters of CS and I’ve had enough
man the CS programs in the US really need to be overhauled

rbrown, what you doing now?

why do they spend time teaching all this useless crap
zacs7, CIS programming track
with a few hand picked electives from compsci

The problem is that people often confuse computer science with programming.

you are using gcc ?

Draconx, compsci is a joke

The CS dept at my school is horrible.
I had a TA who didn’t understand English.

I think universities are out of touch with the needs of the business world of today
they teach CS like we’re still living in the 80’s

LOL
It’s because computer programming shouldn’t be academic. It’s like plumbing.

this has nothing to do with programming

I mean, there is an engineering component, certainly, but there’s no “plumbing science” program at any university.

i think sparc is like 68k and all pointers must be on a 4 byte boundary :P
what is wrong with 80’s ? :~

I just ate some home-made boston baked beans

Can I use “$HOME/file” in fopen()?

jbalint, no, see getenv()
er
jbjuly, rather

thanks

np

if it wasn’t for one prof I’d have no idea how to actually write parallel code with semaphores and mutex …
my OS prof was a grad student and didn’t assign a single programming hw …

ride on

oh yea … and there were only 5 people in that class

And the other 4 were hot chicks? :P

no
only 1 and she was taken
the prof had to say “lady and gentlemen” … it was funny

there are none here

Was she hot?

she was ok
this isn’t #geek-issues

slavil, did she have a boyfriend mutex? :P

it was a named semaphore, that was woned by root

Invalid breeding parameter “root”

umm, I only had to look at the protection bits and who the owner was
yay, my bit array is done

so you went for a bit array eh!?

that doesn’t make sense
try again

is anyone interested in nt syscall emulator?

no

maybe reactos

but they make a whole kernel
and this runs on linux

Goran_, maybe Wine!?

if int a[3] is an array then printf (“%p”, a) and printf (“%p”, &a) why are the same address ? because ‘&a’ must to be the address where the a pointer is and in ‘a’ must to be a memory address where the first member can be found

kantor, &a is the address of the first element.. that *is* where the array is stored
arrays != pointers

if I want to know the memory address of ‘a’ if a is an array, how can I do that ?
cn28h,

a

“the memory address of a” are the words of someone not writing c or trying for an exploit.
but, for an array a both a and &a point at the same place — the first byte of the first element. but each has a different type.

I’m really new to C, and I want to get started on user input/output. (like, events), can someone link me to a good tutorial?

other than a book?
and C is not event driven :P

Well, there must a library, right?
I’ve been reading some ebooks, too.

a library for what?

for accepting user input?

alamar, http://www.cprogramming.com/tutorial.html
alamar, it’s in the standard library

oh, ok.
I’m new to C, but I’m loving it so far…
When the user says “echo”
I want the program to printf(“echo”);
Having trouble though.

well, if(strncmp(buff, “echo”, 4) == 0) printf(“echo”);
and before that, char buff[BUFSIZ]; fgets(buff, sizeof(buff), stdin);
include stdio.h and your done

wow
cool!
strncmp()?
what does that function do?

compares a string (upto n characters)

which is to say, is usually annoying.

yeah, I can imagine…
what does buff[BUFSIZ] do?

alecw1, read http://www.cplusplus.com/reference/clibrary/cstring/strncmp.html

ok

dinner time, cya

C ftw!

dinner time, crazy timezone you’re in :P
/
it’s just a wee bit higher level than assembly

well, it’s very efficient, right?
small file sizes?

that really depends on your program and the compiler

hmm.
That link zacs7 gave me is for c ++, is that function in C?

yes, it’s part of the C standard

ok
well, if(strncmp(buff, “echo”, 4) == 0) printf(“echo”);
and before that, char buff[BUFSIZ]; fgets(buff, sizeof(buff), stdin);
include stdio.h and your done
What part of that gets the user text?

fgets()

ok, ok, cool.
and what is the “buff”

a name

just a variable?

yes

ok, and “BUFSIZ”
what is that for?
the size of the buffer?
how is that calculated?

that’s also a name

ok, thanks a lot!

alecw1, it’s a macro defined in stdio.h (It’s value is 200 something)

cool.
What book do you recommend?
It’s a lot easier for me to read paper than internet stuff.

K&R also

K&R?

ya

a link mb?

alecw1, look for “The C Programming language”
second edition

http://en.wikipedia.org/wiki/The_C_Programming_Language_(book)

ok, thanks.
does this cover user input and everything?

it expands to some value, not necessarily 200 something.

possibly GTK? _
guessing not.

no.

alecw1, no way lol

A book for that?

no ideia
there’s plenty of stuff online though

ok cool.
Any recommandations for a beginner?

yes
stop thinking about GTK
learn C and gain experience

ok, I’m just very excited to start some programs…

hehe

how long do you think before I’ll have my own GUI?

gtk is quite complex

I mean, does it take years?

alecw1, well you can use some designer software

really? what?

alecw1, depends, do you plan on using it just on Windows? Unix? Both?

glade is a possibility

I sort of want to learn it freehand…

i read somewhere libglade is being merged into gtk

Win32 FTW :P

Windows?
I’m a linux hosting user…
Sorry zacs7, Unix only
Sorry zacs7, unix host only

Well GTK+ then :P
and you can go Windows with it too! :O!

pfff

all

screw windows…

alecw1, code for POSIX, the gods will be pleased
^^

and BSD :P

POSIX? Is that Unix?
/noob

last time i checked they were posix compliant
http://en.wikipedia.org/wiki/POSIX
wikipedia is your friend

It’s a standard [that some of us care little about].

ok, well, thanks for your help! I’m off.

xystic, i care a lot about it !!!!
because me loves standards and portability

ForceFollow :o :P

hey zacs7

drdo, I couldn’t agree more :P

hrmm… anyone got a BSD/public piece of code that’ll let you make a URL request and store the result in buffer?
mm.. maybe it’s simpler if I just brush up on Beej’s again

cURL :P

hallo
i’ve a c question
i have a char-array and i want transmit it as a parameter to a function
i tried it with a pointer but i only get to first char
if i try to get [1] the compilers says:
wrong type-argument of unary *
(the first 2 line a mistypted)

show us some code. rafb.net

http://rafb.net/p/NtOTPh96.html

first of all, there is an operator precendence problem
i.e. change it to (*keyword)[1]
second, your function protoype indicates that you are passing a char pointer, not an array pointer
prototype*

hmm
jo mean:

in this case, it is sufficient to call your function “myfunction(keyword)”, since keyword is a pointer to the first element in the array. you can then use array subscripts on it in your funciton

hmm
that don’t work
http://rafb.net/p/gXjhFb83.html
thats wrong too

without the [1] it will. in myfunction keyword is a pointer to char, and both * and [] dereference.
uh, char keyword* is not a valid declaration.

ok that was my second version but whats with the first? http://rafb.net/p/NtOTPh96.html

did you consider what vorpal told you?

in the second version i tried to implement it

*keyword[1] tries to dereference keyword twice.

wow
that works
void myfunction(char *keyword) {
thanks for the information

gonna sleep now, gnight

hey

how would one compare against the number 0×00000000?

like anything else I guess

hi guys, I’m trying to use pcre for the first time… when I compile my program, what options should I add so that it compiles with pcre support?

prce-config will tell you

cool. thanks, light!

*
To prove that you're not a bot, enter this code
Anti-Spam Image

Comments are closed.