login
Login
/
Register
Search
Search this site:
Forums
News
Blogs
Features
Site
Home
»
Mailing list archives
»
openbsd-misc
»
2010
»
April
»
11
Re: SOLVED OT - C compiler, assignement on double-declared variable with different types
view
thread
Previous message: [
thread
] [
date
] [
author
]
Next message: [
thread
] [
date
] [
author
]
[view in full thread]
From: Jesus Sanchez
Subject:
Re: SOLVED OT - C compiler, assignement on double-declared variable with different types
Date: Saturday, April 10, 2010 - 11:37 pm
El 11/04/2010 8:37, Jesus Sanchez escribis:
quoted text
> >> i don't think so. Use gdb and see where you are writing to. >> >> Based on your description of your a.c and b.c, I assume in a.c you >> have "char foo;" (global), and in b.c you by mistake have "extern int >> foo;". >> >> If your foo variable is at address, say 0x11111111, and you write two >> bytes to that address, where foo is in fact a char (single byte), the >> other byte will be written to address 0x11111112. >> >> You can test this with a simple example program, where you can declare >> other char variables around your foo variable and print all of them >> after the foo assignment and see which ones got clobbered. >> >> Then again, maybe I'm misunderstanding your initial problem, you >> didn't show your code. >> >> --patrick >> >> >> Breakpoint 1, main (argc=1, argv=0xfffc8c8c) at a.c:30 >> 30 bar(); >> (gdb) p&f >> = (int *) 0x1842116 >> (gdb) x/4b 0x1842116 >> 0x1842116<f>: 0x00 0x00 0x00 0x00 >> bar () at b.c:14 >> 14 f = 0x44332211; >> (gdb) n >> 16 } >> (gdb) x/4b 0x1842116 >> 0x1842116<f>: 0x44 0x33 0x22 0x11 >> (gdb) p&g >> = 0x1842117 "3\"1" >> (gdb) p&k >> = 0x1842119 "1" >> (gdb) p&l >> = 0x1842118 "\"1" >> (gdb) p/x f >> = 0x44332211 >> (gdb) p/x g >> = 0x33 >> (gdb) p/x l >> = 0x22 >> (gdb) p/x k >> = 0x11 >> >> Looks like the "extern int foo;" confused gdb. >> > > I'm not using extern for the variables, anyway > here is the code (to a extremely basic level) using your hint about > making more char variables around foo to show them later: > > all compiled with gcc -Wall -W without warning > > ---------- a.c ------------------------------------------ > #include <stdio.h> > > char foo; > char foo1; > char foo2; > char foo3; > > void overfoo(); /* the func that will overflow the foo variable */ > > int main(){ > > overfoo(); /* after calling we have 0x2211 on foo variable */ > > printf("%x\n",foo); > printf("%x\n",foo1); > printf("%x\n",foo2); > printf("%x\n",foo3); > return 0; > } > > ---------- b.c ------------------------------------------ > > int foo; /* here the problem begins */ > > void overfoo(){ > foo=0x2211; > } > > --------------------------------------------------------------- > > after compiling and executing , foo showed 0x11 and other 0x0. > > thanks for your time. > -J
Previous message: [
thread
] [
date
] [
author
]
Next message: [
thread
] [
date
] [
author
]
Messages in current thread:
OT - C compiler, assignement on double-declared variable w ...
, Jesus Sanchez
, (Sat Apr 10, 9:14 pm)
Re: SOLVED OT - C compiler, assignement on double-declared ...
, Jesus Sanchez
, (Sat Apr 10, 10:14 pm)
Re: SOLVED OT - C compiler, assignement on double-declared ...
, patrick keshishian
, (Sat Apr 10, 10:49 pm)
Re: SOLVED OT - C compiler, assignement on double-declared ...
, Jesus Sanchez
, (Sat Apr 10, 11:37 pm)
Re: SOLVED OT - C compiler, assignement on double-declared ...
, patrick keshishian
, (Sun Apr 11, 12:06 am)
Re: SOLVED OT - C compiler, assignement on double-declared ...
, Jesus Sanchez
, (Sun Apr 11, 12:23 am)
Re: SOLVED OT - C compiler, assignement on double-declared ...
, Philip Guenther
, (Sun Apr 11, 12:41 am)
Re: SOLVED OT - C compiler, assignement on double-declared ...
, Jesus Sanchez
, (Sun Apr 11, 1:16 am)
Re: OT - C compiler, assignement on double-declared variab ...
, James Hartley
, (Sun Apr 11, 3:49 am)
Re: OT - C compiler, assignement on double-declared variab ...
, Otto Moerbeek
, (Sun Apr 11, 4:11 am)
Re: SOLVED OT - C compiler, assignement on double-declared ...
, Michael Small
, (Sun Apr 11, 5:47 am)
Re: SOLVED OT - C compiler, assignement on double-declared ...
, Ted Unangst
, (Sun Apr 11, 10:41 am)
Re: OT - C compiler, assignement on double-declared variab ...
, patrick keshishian
, (Sun Apr 11, 12:27 pm)
Navigation
Create content
Mailing list archives
Recent posts
Popular discussions
linux-kernel
:
David Howells
[PATCH] KEYS: Use the variable 'key' in keyctl_describe_key()
Dave Jones
Re: OT: character encodings (was: Linux 2.6.20-rc4)
Greg Kroah-Hartman
[PATCH 17/36] sysdev: detect multiple driver registrations
Sam Ravnborg
Re: [PATCH] kbuild: fix make V=1
Nick Piggin
Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
git
:
Stephen R. van den Berg
Re: [RFC] origin link for cherry-pick and revert
Junio C Hamano
Re: [PATCH 1/2] Teach git-describe to display distances from tags.
Johannes Schindelin
Re: [PATCH 2/2] git-svn: support fetch with autocrlf on
Junio C Hamano
Re: [PATCH 6/6] Teach core object handling functions about gitlinks
Michael S. Tsirkin
git-kill: rewrite history removing a commit
linux-netdev
:
Jarek Poplawski
Re: [PATCH] flush_work_sync vs. flush_scheduled_work Re: [PATCH] PHYLIB: IRQ event...
Lennert Buytenhek
Re: Distributed Switch Architecture(DSA)
Daniel Schaffrath
Re: tcp bw in 2.6
Matt Mackall
Re: [regression] nf_iterate(), BUG: unable to handle kernel NULL pointer dereference
Guo-Fu Tseng
Re: jme: UDP checksum error, and lots of them
openbsd-misc
:
Claudio Jeker
Re: Vlan Tag on Vlan Tag (l2tunneling)
Josh Grosse
ssh/sshd challenge-response seems to have stopped working in -current
Pieter Verberne
File collision while using pkg_add
Tomas Bodzar
bsd: uvm_mapent_alloc: out of static map entries
Community First Financial
Teacher A+ Loan
git-commits-head
:
Linux Kernel Mailing List
ath9k: Added get_survey callback in order to get channel noise
Linux Kernel Mailing List
tracing: protect reader of cmdline output
Linux Kernel Mailing List
kconfig: recalc symbol value before showing search results
Linux Kernel Mailing List
KVM: VMX: Clear CR4.VMXE in hardware_disable
Linux Kernel Mailing List
USB: set correct configuration in probe of ti_usb_3410_5052
Colocation donated by:
Syndicate