That's true, but I think your reaction is a little melodramatic... it's
a simple bug to make, with a simple fix, and one unfreed buffer is not
going to bring your mudworld crashing down around you, stock rom has I
believe 4 or 5 unfreed buffers strewn throughout the code... taking 5
paragraphs to point out this minor error and make it sound like it's the
end of the world waiting to happen is, I think, a little over-the-top,
and as was stated, it hadn't been tested... just move the new_buf()
initialization down to just before the for loop starts and problem
solved...

Richard Lindsey.

-----Original Message-----
From: Krayzie K [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, August 18, 2004 2:21 PM
To: Richard Lindsey
Cc: [email protected]
Subject: RE: a problem im having

Excuse me for interrupting, but does not this code below create an error
or
soon will create an error or problem?

The very beginning of the code calls "buffer = new_buf()" which
allocates
memory to that space for a buffer.

Now what if they put in the wrong syntax? It spits out a message to them
about being wrong, but the buffer is never freed.  What if they enter
more
than one name or number value? The buffer is still, never freed.

Then comes to my question, doesn't that create a slight problem? Use the
checkweaps command a few hundred times with the wrong syntax and you
have
just effectively allocated 100 spaces for new memory but never freed
them?

Either way, if I am correct or not, I was just looking through that bit
of
code and it scares me, I was told to ALWAYS make sure the buffer is
freed
before any calls to return out of the function.

I hope this helps.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Richard
Lindsey
Sent: Friday, August 13, 2004 1:41 PM
To: Tristan M; [email protected]
Subject: RE: a problem im having

Try the following, I think part of your problem was that you were using
str_cmp for the name check instead of is_name, meaning that unless you
typed the exact name of the object (generally something like "standard
merc sub issue dagger"), the check wouldn't work right, is_name checks
one word against a name list to find a match on any of those words... I
also made it so you could transpose your name and level arguments (i.e.
you can type "checkweaps 17 dagger" or "checkweaps dagger 17"), or you
can enter either argument without having to enter the word 'null' for a
name, and it only has one loop section, which will cut down on the
number of lines in your file :) I haven't tested any of this, but in
theory it should work :D

Richard Lindsey.

void do_checkweaps(CHAR_DATA *ch, char *argument)
{
    char arg1[MAX_INPUT_LENGTH], arg2[MAX_INPUT_LENGTH],
buf[MAX_INPUT_LENGTH], name[MAX_INPUT_LENGTH];
    BUFFER *buffer;
    OBJ_DATA *obj;
    bool found;
    int level = 0, number = 0;

    found = FALSE;
    number = 0;
    name[0] = '\0';

    buffer = new_buf();

    argument = one_argument(argument, arg1);
    argument = one_argument(argument, arg2);

    if ( arg1[0] == '\0' )
    {
        send_to_char("Syntax: checkweaps <level or name> <level or
name>\n\r", ch);
        return;
    }

    if ( is_number(arg1) )
        level = atoi(arg1);
    else sprintf(name,"%s",arg1);

    if ( arg2[0] != '\0' )
    {
        if ( is_number(arg2) )
        {
            if ( level ) // User entered 2 level values
            {
                send_to_char("Please enter only 1 level value.\n\r",
ch);
                return;
            }
            else level = atoi(arg2);
        }
        else if ( name[0] != '\0' ) // User entered 2 name values
        {
            send_to_char("Please enter only 1 name value.\n\r", ch);
            return;
        }
        else sprintf(name,"%s",arg2);
    }

    // Now just execute 1 loop
    for ( obj = object_list; obj != NULL; obj = obj->next )
    {
        if(obj->wear_loc == WEAR_WIELD
        && (name[0] == '\0' || is_name(name,obj->name))
        && (!level || obj->level == level))
        {
            number++;
            sprintf(buf," %d ) [ AVG DAM: %3d ] [ LEVEL: %3d ]
%s\n\r",number,((1 + obj->value[2]) * obj->value[1] /
2),obj->level,obj->short_descr);
            add_buf(buffer,buf);
        }
    }

    if ( buf_string(buffer)[0] == '\0' )
        send_to_char("No matching weapons found.\n\r", ch);
    else page_to_char(buf_string(buffer),ch);

    free_buf(buffer);
    return;
}

-----Original Message-----
From: Tristan M [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 13, 2004 1:01 PM
To: [email protected]
Subject: a problem im having

i wrote this little function to list all the weapons in the game and
their 
average damage, with two options, you can search for options of  a 
particular level, particular name, particular name and level, or just
list 
all the objects. my problems are:
a) that when it tries to list by name(without level) it only shows
weapons 
that are level 0
b) when it tries to list by name and level it doesnt spit anything out

heres the code, can someone find whats wrong? ive been looking at it and

just cant figure it out.

void do_checkweaps(CHAR_DATA *ch, char *argument)
{
    char buf[MAX_INPUT_LENGTH];
    char name[MAX_INPUT_LENGTH];
    char level[MAX_INPUT_LENGTH];
    BUFFER *buffer;
    OBJ_DATA *obj;
    bool found;
    int number = 0;

    found = FALSE;
    number = 0;

    buffer = new_buf();

    argument = one_argument(argument, name);
    argument = one_argument(argument, level);
    if (name[0] == '\0' || ( !str_cmp( name, "null" ) && level[0] ==
'\0'))
    {
                log_string("1");
            for ( obj = object_list; obj != NULL; obj = obj->next )
            {
                        if(obj->wear_loc == WEAR_WIELD)
                        {
                                number++;
                                sprintf(buf," %d ) [ AVG DAM: %3d ] [
LEVEL: %3d ] %s\n\r",number,((1 + 
obj->value[2]) * obj->value[1] / 2),obj->level,obj->short_descr);
                        add_buf(buffer,buf);
                        }
                }
        page_to_char(buf_string(buffer),ch);
        return;
    }
    if (str_cmp( name, "null" ) && level[0] == '\0')
    {
                log_string("2");
            for ( obj = object_list; obj != NULL; obj = obj->next )
            {
                        if(str_cmp(name,obj->name))
                                continue;
                        if(obj->wear_loc == WEAR_WIELD)
                        {
                                number++;
                                sprintf(buf," %d ) [ AVG DAM: %3d ] [
LEVEL: %3d ] %s\n\r",number,((1 + 
obj->value[2]) * obj->value[1] / 2),obj->level,obj->short_descr);
                        add_buf(buffer,buf);
                        }
                }
        page_to_char(buf_string(buffer),ch);
        return;
    }
    if (!str_cmp( name, "null" ))
    {
                log_string("3");
            for ( obj = object_list; obj != NULL; obj = obj->next )
            {
                        if(obj->level != atoi(level))
                                continue;
                        if(obj->wear_loc == WEAR_WIELD)
                        {
                                number++;
                                sprintf(buf," %d ) [ AVG DAM: %3d ] [
LEVEL: %3d ] %s\n\r",number,((1 + 
obj->value[2]) * obj->value[1] / 2),obj->level,obj->short_descr);
                        add_buf(buffer,buf);
                        }
                }
        page_to_char(buf_string(buffer),ch);
        return;
    }
        log_string("4");
    for ( obj = object_list; obj != NULL; obj = obj->next )
    {
                if(str_cmp(name,obj->name))
                        continue;
                if(obj->level != atoi(level))
                        continue;
                if(obj->wear_loc == WEAR_WIELD)
                {
                        number++;
                        sprintf(buf," %d ) [ AVG DAM: %3d ] [ LEVEL: %3d
] %s\n\r",number,((1 + 
obj->value[2]) * obj->value[1] / 2),obj->level,obj->short_descr);
                add_buf(buffer,buf);
                }
        }
    page_to_char(buf_string(buffer),ch);
    return;
}

_________________________________________________________________
Take charge with a pop-up guard built on patented Microsoft(r)
SmartScreen 
Technology  
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU
=http://hotmail.com/enca&HL=Market_MSNIS_Taglines 
  Start enjoying all the benefits of MSN(r) Premium right now and get
the 
first two months FREE*.


-- 
ROM mailing list
[email protected]
http://www.rom.org/cgi-bin/mailman/listinfo/rom

-- 
ROM mailing list
[email protected]
http://www.rom.org/cgi-bin/mailman/listinfo/rom


-- 
ROM mailing list
[email protected]
http://www.rom.org/cgi-bin/mailman/listinfo/rom

Reply via email to