Jason Stortz wrote: > <snip> > Okay, Scenario 1: I load an object using load obj 300 lets say. And it's a > sword, great. Now, I type in: > > restring obj sword short a HUGE sword. > > Okay, I check my inventory and sure enough, instead of seeing "a sword" > like I saw originally, I see "a HUGE sword." Perfect eh? =( Not so... > > Scenario 2: I create another sword after restringing the first. Instead of > the message "you create a sword" like I am expecting, I get "you create a > HUGE sword." <snip all the irrelevent code from objsave.c> > All the restring function uses is this basically, where arg1, arg2, and > info are passed in. Arg1 is the name of the object, arg2 is the field to > edit, and info is the new stuff to place into the field. > if((obj=get_obj_vis(ch,arg1))!=NULL){ > if(!str_cmp(arg2,"short")){ > strcpy(obj->short_description,info); > }else if(!str_cmp(arg2,"long")){ > strcpy(obj->description,info); > }else if(!str_cmp(arg2,"name")){ > strcpy(obj->name,info); > } > }else{ > send_to_char("No such object around.\r\n",ch); > } Okay, here's how it works... Each instance of a given proto uses the same memory to store it's description, shor description, etc. This is to save memory by not creating a duplicate string for each one. What you are doing above is changing the string used for the object's prototype (and for each instance of the object). What you really need to do is allocate new memory and copy the new string to it as follows... if(!str_cmp(arg2,"short")){ /* The following line prevents a memory leak */ if (obj->short_description != obj_proto[obj->item_number].short_description) free(obj->short_description) /* * Allocate memory, copy the new string to it, and set * the short_description pointer to the new memory. */ obj->short_description = str_dup(info); }else if(!str_cmp(arg2,"long")){ /* same basic thing for "long" and "name" */ That should hopefully fix your problem. Regards, Peter +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 04/10/01 PDT