1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-01-29 21:21:08 +00:00

Correct integer type warnings (#405)

* Correct warning: cast to smaller integer type -- X_init/lispbitmap

* Fixes to INTRSAFE, INTRSAFE0 and ensure TIMEOUT, TIMEOUT0 used appropriately

INTRSAFE and INTRSAFE0 must clear errno before executing the library or system
call because not all library calls set errno on success.
Avoid casting pointers or larger integer values down to smaller ints before
comparing to 0 or -1, and use NULL (a pointer) rather than 0.

Fix cases where the result of the library call is a pointer rather than an int
to use TIMEOUT0 instead of TIMEOUT, testing for NULL rather than -1
on timeout (errno == EINTR)

* Remove useless validity check of LASTVMEMFILEPAGE_word pointer

* Convert pointer arithmetic type in drawline from int to ptrdiff_t

* Add NOTE warning about a 32-bit vs 64-bit issue affecting currently unused GET_NATIVE_ADDR_FROM_LISP_PTR
This commit is contained in:
Nick Briggs
2021-11-04 09:08:55 -07:00
committed by GitHub
parent 6c241f1eaa
commit de5ea2110f
11 changed files with 26 additions and 31 deletions

View File

@@ -691,7 +691,7 @@ static int enum_dsk_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
nextp->prop->wdate = (unsigned)ToLispTime(sbuf.st_mtime);
nextp->prop->rdate = (unsigned)ToLispTime(sbuf.st_atime);
nextp->prop->protect = (unsigned)sbuf.st_mode;
TIMEOUT(pwd = getpwuid(sbuf.st_uid));
TIMEOUT0(pwd = getpwuid(sbuf.st_uid));
if (pwd == (struct passwd *)NULL) {
nextp->prop->au_len = 0;
} else {
@@ -1080,7 +1080,7 @@ static int enum_ufs_prop(char *dir, char *name, char *ver, FINFO **finfo_buf)
char namebuf[MAXPATHLEN];
errno = 0;
TIMEOUT(dirp = opendir(dir));
TIMEOUT0(dirp = opendir(dir));
if (dirp == NULL) {
*Lisp_errno = errno;
return (-1);
@@ -1263,7 +1263,7 @@ static int enum_ufs(char *dir, char *name, char *ver, FINFO **finfo_buf)
char namebuf[MAXPATHLEN];
errno = 0;
TIMEOUT(dirp = opendir(dir));
TIMEOUT0(dirp = opendir(dir));
if (dirp == NULL) {
*Lisp_errno = errno;
return (-1);

View File

@@ -17,10 +17,10 @@
#include "version.h"
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include "lispemul.h"
#include "lspglob.h"
#include "lispmap.h"
@@ -268,21 +268,21 @@ int N_OP_drawline(LispPTR ptr, int curbit, int xsize, int width, int ysize, int
#endif /* COLOR */
{
DLword *start_addr, *temp_s, *temp_e;
DLword *start_addr;
start_addr = (DLword *)Addr68k_from_LADDR(ptr);
if (((int)(temp_s = (DLword *)(start_addr - DisplayRegion68k)) >= 0) &&
(start_addr < DisplayRegion68k_end_addr) &&
((int)(temp_e = (DLword *)(dataptr - DisplayRegion68k)) >= 0) &&
((DLword *)dataptr < DisplayRegion68k_end_addr)) {
if (in_display_segment(start_addr) && in_display_segment(dataptr)) {
int start_x, start_y, end_x, end_y, w, h;
ptrdiff_t temp_s, temp_e;
start_y = (int)temp_s / DisplayRasterWidth;
start_x = ((int)temp_s % DisplayRasterWidth) * BITSPER_DLWORD;
temp_s = start_addr - DisplayRegion68k;
temp_e = dataptr - DisplayRegion68k;
end_y = (int)temp_e / DisplayRasterWidth;
end_x = ((int)temp_e % DisplayRasterWidth) * BITSPER_DLWORD + (BITSPER_DLWORD - 1);
start_y = temp_s / DisplayRasterWidth;
start_x = (temp_s % DisplayRasterWidth) * BITSPER_DLWORD;
end_y = temp_e / DisplayRasterWidth;
end_x = (temp_e % DisplayRasterWidth) * BITSPER_DLWORD + (BITSPER_DLWORD - 1);
w = abs(start_x - end_x) + 1;
h = abs(start_y - end_y) + 1;
@@ -290,10 +290,8 @@ int N_OP_drawline(LispPTR ptr, int curbit, int xsize, int width, int ysize, int
if (start_x > end_x) start_x = end_x;
if (start_y > end_y) start_y = end_y;
#if defined(XWINDOW) || defined(BYTESWAP)
flush_display_region(start_x, start_y, w, h);
#endif /* XWINDOW */
}
}

View File

@@ -1702,7 +1702,7 @@ LispPTR COM_getfileinfo(register LispPTR *args)
case AUTHOR: {
size_t rval;
#ifndef DOS
TIMEOUT(pwd = getpwuid(sbuf.st_uid));
TIMEOUT0(pwd = getpwuid(sbuf.st_uid));
if (pwd == (struct passwd *)NULL) {
/*
* Returns Lisp 0. Lisp code handles this case as author
@@ -1748,7 +1748,7 @@ LispPTR COM_getfileinfo(register LispPTR *args)
bufp = (unsigned *)(Addr68k_from_LADDR(laddr));
*bufp = sbuf.st_mode;
#ifndef DOS
TIMEOUT(pwd = getpwuid(sbuf.st_uid));
TIMEOUT0(pwd = getpwuid(sbuf.st_uid));
if (pwd == (struct passwd *)NULL) { return (GetSmallp(0)); }
laddr = cdr(car(cdr(cdr(cdr(cdr(args[2]))))));
STRING_BASE(laddr, base);

View File

@@ -27,9 +27,6 @@ DspInterface currentdsp = &curdsp;
#ifdef XWINDOW
extern int LispDisplayRequestedWidth;
extern int LispDisplayRequestedHeight;
extern DspInterface X_init(DspInterface dsp, char *lispbitmap, int width_hint, int height_hint,
int depth_hint);
#endif /* XWINDOW */
#ifdef DOS

View File

@@ -139,8 +139,7 @@ void init_ifpage(int sysout_size) {
#ifdef BIGVM
/* For BIGVM system, save the value in \LASTVMEMFILEPAGE for lisp's use */
if ((LispPTR)LASTVMEMFILEPAGE_word != 0xFFFFFFFF)
*LASTVMEMFILEPAGE_word = InterfacePage->dllastvmempage;
*LASTVMEMFILEPAGE_word = InterfacePage->dllastvmempage;
#endif /* BIGVM */
/* unfortunately, Lisp only looks at a 16 bit serial number */

View File

@@ -659,7 +659,7 @@ int makepathname(char *src, char *dst)
#ifdef DOS
pwd = 0;
#else
TIMEOUT(pwd = getpwuid(getuid()));
TIMEOUT0(pwd = getpwuid(getuid()));
#endif /* DOS */
if (pwd == NULL) {
*Lisp_errno = errno;
@@ -678,7 +678,7 @@ int makepathname(char *src, char *dst)
strncpy(name, base + 1, len);
name[len] = '\0';
#ifndef DOS
TIMEOUT(pwd = getpwnam(name));
TIMEOUT0(pwd = getpwnam(name));
#endif /* DOS */
if (pwd == NULL) {
*Lisp_errno = errno;

View File

@@ -484,6 +484,7 @@ void OP_subrcall(int subr_no, int argnum) {
case sb_GET_NATIVE_ADDR_FROM_LISP_PTR:
POP_SUBR_ARGS;
/* XXX: this WILL NOT WORK if Lisp memory is allocated outside the low 4GB */
ARITH_SWITCH(Addr68k_from_LADDR(args[0]), TopOfStack);
break;

View File

@@ -566,7 +566,7 @@ int unixpathname(char *src, char *dst, int versionp, int genp)
case '~':
if (*(cp + 1) == '>' || *(cp + 1) == '\0') {
/* "~>" or "~" means the user's home directory. */
TIMEOUT(pwd = getpwuid(getuid()));
TIMEOUT0(pwd = getpwuid(getuid()));
if (pwd == NULL) return (0);
strcpy(dst, pwd->pw_dir);
@@ -590,7 +590,7 @@ int unixpathname(char *src, char *dst, int versionp, int genp)
*/
for (++cp, np = name; *cp != '\0' && *cp != '>';) *np++ = *cp++;
*np = '\0';
TIMEOUT(pwd = getpwnam(name));
TIMEOUT0(pwd = getpwnam(name));
if (pwd == NULL) return (0);
strcpy(dst, pwd->pw_dir);

View File

@@ -222,7 +222,7 @@ void Open_Display(DspInterface dsp)
/* */
/*********************************************************************/
DspInterface X_init(DspInterface dsp, char *lispbitmap, int width_hint, int height_hint,
DspInterface X_init(DspInterface dsp, LispPTR lispbitmap, int width_hint, int height_hint,
int depth_hint)
{
Screen *Xscreen;