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
#include

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
#include

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#includechar 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

Downloads

Comments

nnannos
Fri Apr 18 2014, 01:23 PM
venkyrsv
Fri Apr 18 2014, 12:10 PM
Suilied
Fri Apr 18 2014, 10:44 AM
RaviKantSharma
Fri Apr 18 2014, 04:55 AM
sohil99
Fri Apr 18 2014, 03:09 AM
kanakiyajay
Fri Apr 18 2014, 02:00 AM
bradstormer
Thu Apr 17 2014, 05:32 PM
jasmeet_singh
Thu Apr 17 2014, 10:19 AM

Conversation

ExperimenterUK
Thu Apr 17 2014, 01:23 PM
@mba Great .. please do.
Thu Apr 17 2014, 12:27 AM
mba'
like the forum and wish to participate
ExperimenterUK
Wed Apr 16 2014, 04:45 PM
@viniciusheidrun..you should read my comment just before your post
viniciusheidrun
Wed Apr 16 2014, 01:43 PM
I'm doing a drive system with SIM900D modem and microcontroller AT89S52 via sms. I'm having trouble can not generate the. Hex to send to the microcontroller, whenever I compile the error, I'm using MCU 8051 IDE, what should I do so that my system receive sms and perform my task?
ExperimenterUK
Mon Apr 14 2014, 01:00 PM
@Haranadh,bipin chandra etc. Create threads for your questions.
Sun Apr 13 2014, 04:05 AM
Haranadh
we bought HC 06 Bluetooth modem instead of Module ,Can any one help me of using it as bluetooth module since i am doing this project?
Sun Apr 13 2014, 03:58 AM
Haranadh
Hi,Actually we bought Bluetooth modem instead of Bluetooth Module
ajay_bhargav
Sat Apr 12 2014, 02:55 PM
Please use forum if you want to ask a question.
Sat Apr 12 2014, 01:06 PM
Dpk
Hi Ahana,I can Help you on this
Sat Apr 12 2014, 03:51 AM
bipin chandra
can anybody help me. we are making a project to control the position of dc motor. so there we need to interface lcd screen and the 4X3 memberane keypad and a dc motor driver chip. can anybody please give me the complete circuit diagram connection of these components with the 8051.and alse help in the programming. my email id is bipin.chandra666@gmail.com
  Choose Skin