Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ Compiling the server
➜ Suggested improvement to SmaugFUSS
Suggested improvement to SmaugFUSS
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1
2
3
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #30 on Sun 09 Jul 2006 06:46 AM (UTC) Amended on Sun 09 Jul 2006 07:07 AM (UTC) by Nick Gammon
|
Message
| The following are the problem areas I have detected:
comm.c function display_prompt
There is an snprintf like this in that function:
snprintf( pbuf, MAX_STRING_LENGTH, ...
However pbuf is declared like this:
char buf[MAX_STRING_LENGTH];
char *pbuf = buf;
The pointer pbuf is gradually incremented through buf, so the code should probably read:
snprintf( pbuf, sizeof (buf) - strlen (buf), ...
mud_prog.c function mprog_do_ifcheck
A similar thing is happening here with rval, it initially is set to:
char *rval = "";
Later it appears to be incrementing through buf, so I think simply using sizeof (rval) will be definitely wrong, and also MAX_STRING_LENGTH isn't too great either. A bit of reworking is required here.
act_comm.c function talk_channel
As mentioned in an earlier post, lbuf is MAX_INPUT_LENGTH + 4 bytes long, but the snprintf is for MAX_STRING_LENGTH, which is much longer.
build.c function edit_buffer
char buf[MAX_INPUT_LENGTH];
...
lineln = snprintf( buf, MAX_STRING_LENGTH, "%s%s", word2, wptr + wordln );
This is just plain wrong, the snprintf is using the wrong size.
player.c function do_statreport
char buf[MAX_INPUT_LENGTH];
...
snprintf( buf, MAX_STRING_LENGTH, "$n reports: %d/%d hp %d/%d blood %d/%d mv %d xp.",
Again, wrong, this is the wrong length.
The last 2 examples in particular show why it is a good idea to get in the habit of using sizeof, and avoiding typos, rather than copying and pasting numeric lengths (or even defined lengths). |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #31 on Sun 09 Jul 2006 09:20 PM (UTC) |
Message
| Another way of looking at this is, if you fix the 5 places mentioned above, then wholesale change isn't really necessary, the other places are correct anyway.
However it is "more technically correct" (to change everything) in that you don't have to look at the 900 other instances later on and wonder if the buffer is really the correct size. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
83,985 views.
This is page 3, subject is 3 pages long:
1
2
3
It is now over 60 days since the last post. This thread is closed.
Refresh page
top