Discussion in "Software" started by    bhagirath    Jul 5, 2011.
Tue Jul 05 2011, 04:19 AM
#1
Hi all,

I am a newbie to Keil. I was just working in one demo project and stuck in between due to some access violation error. I tried googleing to various forums but didn't work, also tried applying map command but no success may be anyone could provide proper steps to do so. So could can one please help me in this regards? My code is as follows

//start
#include<reg51.h>

#include<string.h>


char var1[1];
char var2[1];
char var3[1];
char var4[5];
char var5[5];
char var6[1];
char var7[1];

void main()
{
    while(1)
    {
        char str[]= "123456789123456";
        int idx1 = 0;
        int index2 = 1;
        strncpy (var1,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var2,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var3,str+idx1,index2);
        idx1+=5;
        index2+=5;
        strncpy (var4,str+idx1,index2);
        idx1+=1;
        index2+=5;
        strncpy (var5,str+idx1,index2);
        idx1+=5;
        index2+=1;
        strncpy (var6,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var7,str+idx1,index2);
    }
}
//end


The error comes while debugging the code, here any where in between it stops debugging and throws error 65 access violation error.
If possible please reply me with steps to resolve this. Let me know if you want further information.

Thanks in advance

Info: Keil version 3.0 eval, hardware : AT89S52
Tue Jul 05 2011, 06:22 PM
#2
For a start,to find an error remove all the code you can until the error disappears.
In this case everything in your while loop.
Then put back a bit at a time until the error comes back .
This tells you where to look.

Your error(s) come from the use of strncpy.
Most of your target buffers are only one byte long and yet you are often trying to copy
more than one byte into them.
This means you are "violating" memory space you "don't own"



[ Edited Wed Jul 06 2011, 03:28 PM ]
Wed Jul 06 2011, 07:52 AM
#3
Hi ExperimenterUK,

Thank you very much for reply,

As per your advice I have removed all the multiple characters trimming, now I am doing only on single character, but then also I am getting the same error. I had googled on this error and some where it was mentioned to keep the code in single loop thats why i have kept it under while(1).

#include<reg51.h>

#include<string.h>


char var1[1];
char var2[1];
char var3[1];
char var4[1];
char var5[1];
char var6[1];
char var7[1];

void main()
{
    while(1)
    {
        char str[]= "123456789123456";
        unsigned char idx1 = 0;
        unsigned char index2 = 1;
        strncpy (var1,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var2,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var3,str+idx1,index2);
		idx1+=1;
        index2+=1;
        strncpy (var4,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var5,str+idx1,index2);// here the location of error..
        idx1+=1;
        index2+=1;
        strncpy (var6,str+idx1,index2);
        idx1+=1;
        index2+=1;
       	strncpy (var7,str+idx1,index2);
		break;
    }
}


I will be really grateful to you if you could try this in your environment.

According to my requirement I need to perform substring function on one string, thats why i have kept strncpy().

Thanks once again.
Wed Jul 06 2011, 08:31 AM
#4
I tried your code on My keil, it didnt showed any error,
Check your keil with other programs(simple one)
Wed Jul 06 2011, 09:16 AM
#5
Hi kirangowle,

I am getting error on debugging the code line by line. The code compiles fine with keil. the only issue
is while debugging it throws error for access violation.

Could you please try debugging the code?

Thanks
Bhagirath
Wed Jul 06 2011, 10:22 AM
#6
Hi,
I debugged your code, it was getting halt at strncpy(var3,)

In array declaration i increased the array length to 5(var[5]) and keep the local variable declaration outside of the while(1).
Wed Jul 06 2011, 11:31 AM
#7
Hi Kirangowle,

Thanks for reply,

I have changed the code as you have suggested, for performance and testing issue i have changed the capacity for each var to 1 byte. But no success, in debugging it stops at var5, after which i have noticed that all variables are cleared which were holding their values before error. here is my changed code

char var1[1];
char var2[1];
///...
char var7[1];
char str[]= "123456789123456";
char idx1 = 0;
char index2 = 1;

void main()
{

    while(1)
    {
        strncpy (var1,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var2,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var3,str+idx1,index2);
		idx1+=1;
        index2+=1;
        strncpy (var4,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var5,str+idx1,index2);
        idx1+=1;
        index2+=1;
        strncpy (var6,str+idx1,index2);
        idx1+=1;
        index2+=1;
       	strncpy (var7,str+idx1,index2);
		
    }
}


Wed Jul 06 2011, 12:26 PM
#8
You didnt change the array length from var[1] to var[5].
i am not understanding what basically u are try to achieve .
Wed Jul 06 2011, 01:34 PM
#9
Hi,

Let me describe my workflow here, I want to substring the "str" in different segments. Let say that segments would be like
var1 = first character
var2 = 2nd - 4th
var3 = 5th - 8th
like wise, it is my custom requirement.

In given example i have created var1[1] - var7[1] just to check, because it was some times showing error in array with bigger ranges. Actually it will be as describe above.e.g.
var1[1], var2[3], var2[4], var4[1]....

Hope this clears it..

And in doing so keil is throwing the error of either access violation or it stops debugging.
Wed Jul 06 2011, 03:51 PM
#10


Hi ExperimenterUK,
As per your advice I have removed all the multiple characters trimming, now I am doing only on single character,

bhagirath


Actually I meant remove all the statements,then put back one statement at a time.


I had googled on this error and some where it was mentioned to keep the code in single
loop thats why i have kept it under while(1).

bhagirath


Whatever you Googled is not relevent here,remove the while() loop, or at least move it to the end

Remove this line for now " index2+=1; " it makes you copy more bytes each time


Try this
#include<reg51.h>
#include<string.h>
char var1[1];
char var2[1];
char var3[1];

void main()
{

    
        char str[]= "123456789123456";
        unsigned char idx1 = 0;
        unsigned char index2 = 1;
        strncpy (var1,str+idx1,index2);  //this should work
        idx1+=1;
 //;  index2+=1; don't do this as it copies 2 bytes next time

        strncpy (var2,str+idx1,index2);   //this should work
        idx1+=1;
        index2+=1;
        strncpy (var3,str+idx1,index2);   //this should not  work
//;		break;  // ??? not needed
    while(1);

}


Get Social

Information

Powered by e107 Forum System

Conversation

ajay_bhargav
Mon Oct 20 2014, 11:22 AM
@skrishna, please post in forum so we can help you better.
Tue Oct 14 2014, 01:45 PM
skrishna
how do i write an ALP equivalent 7segment display interfacing embedded c program (both 8051 microcontroller)
Sat Oct 11 2014, 06:41 PM
vaidehi
want details of seven segment LED display common cathode ( IC CD 4026)
Fri Oct 03 2014, 12:52 PM
Narsim
Rickey you inspired me a lot ... I am also planing like you ...
ExperimenterUK
Wed Oct 01 2014, 09:33 PM
We're back.. we had a bug, but posting is back to normal
ExperimenterUK
Sat Sep 13 2014, 04:34 PM
jaimin1212,Pimpalkhare Create a thread for your question
jaimin1212
Sat Sep 13 2014, 06:35 AM
i want to make self balancing robot using MPU6050 using atmega8.. please help to get data of gyro and accelerometer from this sensor through atmega8.
Thu Sep 11 2014, 01:00 PM
Sunil Pimpalkhare
Hello sir, I am trying to make Wearfin project https://www.youtube.com/watch?v=iZ6PVBvQf-g so can u help me in teaching how to built the program???
Thu Sep 11 2014, 06:21 AM
hariom panday
plz hlp me in my project
iec.naga
Tue Sep 09 2014, 05:19 AM
spi

Downloads

Comments

pddung93
Sun Oct 19 2014, 01:56 PM
msideal
Thu Oct 16 2014, 08:48 AM
robotgirl
Tue Oct 14 2014, 06:23 PM
BRV64
Mon Oct 13 2014, 05:48 AM
menadjelia
Mon Oct 13 2014, 02:47 AM
kulbhushan
Sun Oct 12 2014, 12:20 PM
HarrySid
Fri Oct 10 2014, 05:15 AM
pphamtuan
Thu Oct 09 2014, 03:58 AM

Online

Guests: 40, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37531
Newest member: pddung93
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Oct 22 2014, 03:22 AM
Okay, it seems to be a simple serial connection.Th...
jona Avatar
Posted By jona
Tue Oct 21 2014, 10:29 PM
I found this slightly different data sheet on a pu...
majoka Avatar
Posted By majoka
Tue Oct 21 2014, 06:35 PM
after this Accept-language:en-us\r\n...
majoka Avatar
Posted By majoka
Tue Oct 21 2014, 06:33 PM
@ aksharAT89C51AC3 can bebut the final decision wi...
majoka Avatar
Posted By majoka
Tue Oct 21 2014, 06:29 PM
@ Okechukwubefore starting this project you should...
majoka Avatar
Posted By majoka
Tue Oct 21 2014, 06:18 PM
@ kirangowleyou have to set the microphone level a...
majoka Avatar
Posted By majoka
Tue Oct 21 2014, 06:08 PM
i didnt understand the error where is error is th...
majoka Avatar
Posted By majoka
Tue Oct 21 2014, 06:04 PM
@ msidealMicrochip MCP23008 I2C 8-bit I/O expander...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Oct 21 2014, 05:21 PM
I found this slightly different data sheet on a pu...
msideal Avatar
Posted By msideal
Tue Oct 21 2014, 04:56 PM
Coding on Assembly Language is attached hereCODE:....