Make struct telstr members tel_type and tel_length unsigned
They are simpler to use that way.
This commit is contained in:
parent
d2cd46ce20
commit
4c81ca34cb
6 changed files with 23 additions and 26 deletions
|
@ -49,8 +49,8 @@
|
|||
|
||||
struct telstr {
|
||||
natid tel_from; /* sender */
|
||||
signed char tel_type;
|
||||
long tel_length; /* how long */
|
||||
unsigned char tel_type;
|
||||
unsigned tel_length; /* how long */
|
||||
time_t tel_date; /* when sent */
|
||||
};
|
||||
|
||||
|
|
|
@ -114,11 +114,7 @@ rea(void)
|
|||
lasttype = -1;
|
||||
while (fread(&tgm, sizeof(tgm), 1, telfp) == 1) {
|
||||
readit = 1;
|
||||
if (tgm.tel_length < 0) {
|
||||
logerror("bad telegram file header in %s", mbox);
|
||||
break;
|
||||
}
|
||||
if (tgm.tel_type < 0 || tgm.tel_type > TEL_LAST) {
|
||||
if (tgm.tel_type > TEL_LAST) {
|
||||
pr("Bad telegram header. Skipping telegram...\n");
|
||||
readit = 0;
|
||||
goto skip;
|
||||
|
@ -146,7 +142,7 @@ rea(void)
|
|||
pr("\n> ");
|
||||
lastcnum = tgm.tel_from;
|
||||
lasttype = tgm.tel_type;
|
||||
pr("%s ", telnames[(int)tgm.tel_type]);
|
||||
pr("%s ", telnames[tgm.tel_type]);
|
||||
if ((tgm.tel_type == TEL_NORM) ||
|
||||
(tgm.tel_type == TEL_ANNOUNCE) ||
|
||||
(tgm.tel_type == TEL_BULLETIN))
|
||||
|
|
|
@ -52,6 +52,7 @@ turn(void)
|
|||
char buf[1024];
|
||||
char msgbuf[MAXTELSIZE + 1]; /* UTF-8 */
|
||||
char *msgfilepath;
|
||||
int len;
|
||||
|
||||
p = getstarg(player->argp[1], "on, off or motd? ", buf);
|
||||
if (!p)
|
||||
|
@ -76,14 +77,14 @@ turn(void)
|
|||
else
|
||||
pr("Enter a new message of the day.\n");
|
||||
|
||||
time(&tgm.tel_date);
|
||||
tgm.tel_length = getele("The World", msgbuf);
|
||||
if (tgm.tel_length < 0) {
|
||||
len = getele("The World", msgbuf);
|
||||
if (len < 0) {
|
||||
pr("Ignored\n");
|
||||
if (msgfilepath == downfil)
|
||||
pr("NOT disabling logins.\n");
|
||||
return RET_FAIL;
|
||||
} else if (tgm.tel_length == 0) {
|
||||
}
|
||||
if (len == 0) {
|
||||
if (msgfilepath == motdfil) {
|
||||
pr("Removing exsting motd.\n");
|
||||
if ((unlink(msgfilepath) == -1) && (errno != ENOENT)) {
|
||||
|
@ -108,6 +109,8 @@ turn(void)
|
|||
pr("Logins disabled.\n");
|
||||
|
||||
memset(&tgm, 0, sizeof(tgm));
|
||||
time(&tgm.tel_date);
|
||||
tgm.tel_length = len;
|
||||
if ((fwrite(&tgm, sizeof(tgm), 1, fptr) != 1) ||
|
||||
(fwrite(msgbuf, tgm.tel_length, 1, fptr) != 1)) {
|
||||
fclose(fptr);
|
||||
|
|
|
@ -284,14 +284,14 @@ show_first_tel(char *fname)
|
|||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
if (tgm.tel_length >= (long)sizeof(buf)) {
|
||||
logerror("text length (%ld) is too long for login message (%s)",
|
||||
tgm.tel_length, fname);
|
||||
if (tgm.tel_length >= sizeof(buf)) {
|
||||
logerror("text length (%u) is too long for login message (motdfil)",
|
||||
tgm.tel_length);
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
if (fread(buf, tgm.tel_length, 1, fp) != 1) {
|
||||
logerror("bad length %ld on login message", tgm.tel_length);
|
||||
logerror("bad length %u on login message", tgm.tel_length);
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ wu(natid from, natid to, char *format, ...)
|
|||
int
|
||||
typed_wu(natid from, natid to, char *message, int type)
|
||||
{
|
||||
int len;
|
||||
size_t len;
|
||||
struct telstr tel;
|
||||
struct natstr *np;
|
||||
struct iovec iov[2];
|
||||
|
|
|
@ -118,14 +118,13 @@ copy_and_expire(FILE *annfp, FILE *tmpfp, char *tmp_filename,
|
|||
|
||||
while (fread(&tgm, sizeof(tgm), 1, annfp) == 1) {
|
||||
writeit = 1;
|
||||
if (tgm.tel_length < 0 || tgm.tel_length > MAXTELSIZE) {
|
||||
logerror("bad telegram file header (length=%ld)",
|
||||
if (tgm.tel_length > MAXTELSIZE) {
|
||||
logerror("bad telegram file header (length=%d)",
|
||||
tgm.tel_length);
|
||||
return 0;
|
||||
}
|
||||
if (tgm.tel_type < 0 || tgm.tel_type > TEL_LAST) {
|
||||
logerror("bad telegram file header (type=%d)",
|
||||
tgm.tel_type);
|
||||
if (tgm.tel_type > TEL_LAST) {
|
||||
logerror("bad telegram file header (type=%d)", tgm.tel_type);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -146,15 +145,14 @@ copy_and_expire(FILE *annfp, FILE *tmpfp, char *tmp_filename,
|
|||
++saved;
|
||||
} else
|
||||
++deleted;
|
||||
if (fread(message, 1, tgm.tel_length, annfp) !=
|
||||
(size_t)tgm.tel_length) {
|
||||
if (fread(message, 1, tgm.tel_length, annfp) != tgm.tel_length) {
|
||||
logerror("error reading body from telegram file %s",
|
||||
annfil);
|
||||
return 0;
|
||||
}
|
||||
if (writeit) {
|
||||
if (fwrite(message, 1, tgm.tel_length, tmpfp) !=
|
||||
(size_t)tgm.tel_length) {
|
||||
if (fwrite(message, 1, tgm.tel_length, tmpfp)
|
||||
!= tgm.tel_length) {
|
||||
logerror("error writing body to temporary telegram "
|
||||
"file %s", tmp_filename);
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue