Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Invalid read of size 1

Posted on 2008-10-15
16
Medium Priority
?
1,021 Views
Last Modified: 2012-05-05
i am getting error : invalid read of size 1...

what does this mean...
0
Comment
Question by:zizi21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 3
16 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 1200 total points
ID: 22723484
You are reading one byte from memory that you have not allocated
0
 

Author Comment

by:zizi21
ID: 22723505
is there a way to check which memory i have not allocated ? i am using valgrind
0
 

Author Comment

by:zizi21
ID: 22723509
with this options:valgrind --tool=memcheck --leak-check=yes --show-reachable=yes
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 800 total points
ID: 22723520
You should have a backtrace that goes with the error. That shows you the exact location of the problem.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 22723527
It should be giving you a stack trace
0
 

Author Comment

by:zizi21
ID: 22723537
it says at 0x804A936:funct1(....)

it does not say the exact location..is there any option that i should use...
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 22723563
There should be more .. something like

==9814==  Invalid write of size 1
==9814==    at 0x804841E: main (example2.c:6)
==9814==  Address 0x1BA3607A is 0 bytes after a block of size 10 alloc'd
==9814==    at 0x1B900DD0: malloc (vg_replace_malloc.c:131)
==9814==    by 0x804840F: main (example2.c:5)

The values in the bracket are file name and line number
Can you copy paste the exact output.
0
 

Author Comment

by:zizi21
ID: 22723568
=11411== Invalid read of size 1
==11411==    at 0x804A936: computeA (in /test/main)
==11411==    by 0x804B0E1: scan(in /test/main)
==11411==    by 0x8048EFF: main (main.c:262)
==11411==  Address 0x1EC1C029 is 0 bytes after a block of size 52428801 alloc'd
==11411==    at 0x1B904984: malloc (vg_replace_malloc.c:131)
==11411==    by 0x8048AC3: main (main.c:162)
0
 

Author Comment

by:zizi21
ID: 22723582
i went to the computeA function but i can't say which line it is happening...
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 22723707
This is odd ... it would print line numbers for only part of the trace. As far as I can tell your command line looks okay. Did you really allocate 52428801 bytes of memory? Wondering if the tool got clobbered ;-) Or were there some memory errors preceding this one?
0
 

Author Comment

by:zizi21
ID: 22723810
it is the first error and i have more similar errors after this...

i checked and i did allocate memory for 52428801
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22723880
>> i went to the computeA function but i can't say which line it is happening...

Can you show the computeA function ?
0
 

Author Comment

by:zizi21
ID: 22724047
actually, the code is very very long and i am not allowed to post any code as i would be penalised...i am a student...

i am grateful of all of you helping ...sorry for that...
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22724335
>> the code is very very long

It is a good idea to split up your code into manageable functions (no longer than 10-15 lines is a good rule). Longer functions are more difficult to maintain, and it's easier to make mistakes.


You can look for the problem yourself, by checking all the locations where memory is read, and checking whether the reads are done within allocated memory blocks.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 22728025
You can probably zip the code and upload to another site such as rapidshare or even ee-stuff.com and post a link here. Once we have found the problem, you can delete the file from the server.
0
 

Author Comment

by:zizi21
ID: 22765199
just saw this...the thing is solved ..thanks a million
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question