Jump to content
Eternal Lands Official Forums
Sign in to follow this  
v0id

Error in elbot.c

Recommended Posts

I'm not sure if this is the correct place to post this, and it may be frowned upon, but for those of you that have created a bot with redknight...

 

I've ran into this problem while compiling in DEV-C++ 4.9.9.2

 

in elbot.c

 

elbot.c: In function `process_text_message':

elbot.c:250: error: assignment of read-only location

 

Line250

data = tolower(data);

 

ERROR : assignment of read-only location

 

data is declared like this:

 

Line240

void process_text_message(const char *data, int PM) {

 

---------------

 

If anyone could shed some light, I would appreciate it -- otherwise, I'm sure I'll figure it out in a few. But a quickfix from someone that has done it before would be great!!

 

Thanks in advance!

Share this post


Link to post
Share on other sites

You can't change a variable that's declared with the "const" keyword. Either remove it or create a pointer to data like so:

 

char *p = data;

 

then...

 

p[i] = tolower(p[i])

 

would not cause an error.

Share this post


Link to post
Share on other sites

You can't change a variable that's declared with the "const" keyword. Either remove it or create a pointer to data like so:

 

char *p = data;

 

then...

 

p[i] = tolower(p[i])

 

would not cause an error.

 

 

Yep! that worked. :lurker: ...among fixing other things... lol. well, at least this gives me a template to work from. now the real fun begins. Thanks for the pointer (no pun intended)! :D

Edited by v0id

Share this post


Link to post
Share on other sites

I'm not sure if this is the correct place to post this, and it may be frowned upon, but for those of you that have created a bot with redknight...

 

I wouldn't recommend it, unless you need a guard bot. The source is a bit of a mess, though I'm slowly tacking on some proper architecture, and deadheading the worst of it (ie. I have, though not yet committed, the code to move from the weird old hacked lists architecture to a proper hash list format.) Still, in the interim... storebot may be the better choice. (Which, I believe, is based almost entirely off of Bongo's work.).

Edited by crusadingknight

Share this post


Link to post
Share on other sites

Which, I believe, is based almost entirely off of Bongo's work.

 

No need to give me credit for that monstrosity :-). I abandoned that project shortly after starting it. If you're looking for a decent store bot, look no further than somewhere else.

Share this post


Link to post
Share on other sites
You can't change a variable that's declared with the "const" keyword. Either remove it or create a pointer to data like so:

char *p = data;

then...

p[i] = tolower(p[i])

would not cause an error.

 

However it may cause a SEGV later.

 

You don't know where 'data' came from, and cannot make presumptions. It may point to read-only memory, such as a string literal. eg:

const char *data = "Hello World";

These are now placed in read-only memory, and attempting to change them will result in a runtime error/crash/SEGV.

 

You cannot cast away your problems, you are just hiding the bug for later.

Options are:

  1. Change the function declaration. This is bad because it requires all users to re-evaluate their use of it, but is necessary if the side-effect of calling this function is to lower-case the contents of 'data'.
  2. Or take a local mutable copy of the data and use that instead. In which case the case changes will not be passed out of the function.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×