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