Discussion in "Software" started by    bhagirath    Jul 5, 2011.
Tue Jul 05 2011, 12: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, 02: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, 11:28 AM ]
Wed Jul 06 2011, 03: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, 04: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, 05: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, 06: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, 07: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, 08:26 AM
#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, 09:34 AM
#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, 11:51 AM
#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

ExperimenterUK
Sat Sep 13 2014, 12:34 PM
jaimin1212,Pimpalkhare Create a thread for your question
jaimin1212
Sat Sep 13 2014, 02: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, 09:00 AM
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, 02:21 AM
hariom panday
plz hlp me in my project
iec.naga
Tue Sep 09 2014, 01:19 AM
spi
Mon Sep 08 2014, 08:14 AM
fameem
water changing in fish tank automatically using microcontoller with timer. send idea to me
dexter_a
Sat Sep 06 2014, 11:09 AM
hello guys
Sat Sep 06 2014, 10:10 AM
munaxa
plx guide me
Sat Sep 06 2014, 10:09 AM
munaxa
hi i want to buy plx guie me
ajay_bhargav
Sat Sep 06 2014, 03:10 AM
@Ben, Its hard to undrstand the context like this. If you can post in forum with some example code we might answer you better.

Downloads

Comments

piku_123
Tue Sep 16 2014, 11:29 AM
qudor
Tue Sep 16 2014, 11:06 AM
sara_seecs
Tue Sep 16 2014, 10:53 AM
akshar
Fri Sep 12 2014, 12:45 PM
iec.naga
Tue Sep 09 2014, 01:09 AM
ELTenin
Sun Sep 07 2014, 09:51 AM
dexter_a
Sat Sep 06 2014, 08:46 AM
pedrocardoso
Thu Sep 04 2014, 07:04 PM

Online

Guests: 56, Members: 0 ...

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

Members: 37514
Newest member: piku_123
Forum Activity
ajay_bhargav Avatar
Posted By ajay_bhargav
Wed Sep 17 2014, 12:59 AM
I think its important to list out the features of ...
ajay_bhargav Avatar
Posted By ajay_bhargav
Wed Sep 17 2014, 12:45 AM
you need to put a wait condition in ISR till the s...
akshar Avatar
Posted By akshar
Mon Sep 15 2014, 04:41 AM
sir,i used microcontroller 89v51rd2 in circuit. No...
bobparihar Avatar
Posted By bobparihar
Mon Sep 15 2014, 02:24 AM
i am programming interrupt 0 using 8051my task is....
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Sep 13 2014, 12:23 PM
There may not be an exact equivalent .You will hav...
akshar Avatar
Posted By akshar
Sat Sep 13 2014, 03:18 AM
Sir, Good Morning,Thank you for making me a member...
ajay_bhargav Avatar
Posted By ajay_bhargav
Thu Sep 11 2014, 12:52 AM
which compiler are you using? I suggest XC8 with M...
ajay_bhargav Avatar
Posted By ajay_bhargav
Thu Sep 11 2014, 12:49 AM
I always prefer Olimex Dev boards when it comes to...
ajay_bhargav Avatar
Posted By ajay_bhargav
Thu Sep 11 2014, 12:44 AM
master will always lower down the Chip select... s...
ajay_bhargav Avatar
Posted By ajay_bhargav
Thu Sep 11 2014, 12:38 AM
Well HitechC is the compiler used inside XC8. So i...