Skip to content

Commit

Permalink
Change TclpLoadMemoryGetBuffer/TclpLoadMemory signature using size_t/…
Browse files Browse the repository at this point in the history
…Tcl_Size
  • Loading branch information
jan.nijtmans committed Nov 21, 2024
1 parent 81aee50 commit 43e17d2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
9 changes: 5 additions & 4 deletions generic/tclIOUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -3237,7 +3237,8 @@ Tcl_LoadFile(
*/

{
int ret, size;
Tcl_Size ret;
size_t size;
void *buffer;
Tcl_StatBuf statBuf;
Tcl_Channel data;
Expand All @@ -3246,13 +3247,13 @@ Tcl_LoadFile(
if (ret < 0) {
goto mustCopyToTempAnyway;
}
size = (int) statBuf.st_size;
size = statBuf.st_size;

/*
* Tcl_Read takes an int: Determine whether the file size is wide.
* Tcl_Read takes an int: Determine whether the file size <= INT_MAX
*/

if (size != (Tcl_WideInt) statBuf.st_size) {
if (size > INT_MAX) {
goto mustCopyToTempAnyway;
}
data = Tcl_FSOpenFileChannel(interp, pathPtr, "rb", 0666);
Expand Down
4 changes: 2 additions & 2 deletions generic/tclInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -3478,9 +3478,9 @@ MODULE_SCOPE int TclpDlopen(Tcl_Interp *interp, Tcl_Obj *pathPtr,
Tcl_FSUnloadFileProc **unloadProcPtr, int flags);
MODULE_SCOPE int TclpUtime(Tcl_Obj *pathPtr, struct utimbuf *tval);
#ifdef TCL_LOAD_FROM_MEMORY
MODULE_SCOPE void * TclpLoadMemoryGetBuffer(Tcl_Interp *interp, int size);
MODULE_SCOPE void * TclpLoadMemoryGetBuffer(Tcl_Interp *interp, size_t size);
MODULE_SCOPE int TclpLoadMemory(Tcl_Interp *interp, void *buffer,
int size, int codeSize, Tcl_LoadHandle *loadHandle,
size_t size, Tcl_Size codeSize, Tcl_LoadHandle *loadHandle,
Tcl_FSUnloadFileProc **unloadProcPtr, int flags);
#endif
MODULE_SCOPE void TclInitThreadStorage(void);
Expand Down
6 changes: 3 additions & 3 deletions generic/tclLoadNone.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ TclpDlopen(
MODULE_SCOPE void *
TclpLoadMemoryGetBuffer(
TCL_UNUSED(Tcl_Interp *),
TCL_UNUSED(int))
TCL_UNUSED(size_t))
{
return NULL;
}
Expand All @@ -73,8 +73,8 @@ MODULE_SCOPE int
TclpLoadMemory(
Tcl_Interp *interp, /* Used for error reporting. */
TCL_UNUSED(void *),
TCL_UNUSED(int),
TCL_UNUSED(int),
TCL_UNUSED(size_t),
TCL_UNUSED(Tcl_Size),
TCL_UNUSED(Tcl_LoadHandle *),
TCL_UNUSED(Tcl_FSUnloadFileProc **),
TCL_UNUSED(int))
Expand Down
10 changes: 5 additions & 5 deletions unix/tclLoadDyld.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ UnloadFile(
MODULE_SCOPE void *
TclpLoadMemoryGetBuffer(
TCL_UNUSED(Tcl_Interp *),
int size) /* Size of desired buffer. */
size_t size) /* Size of desired buffer. */
{
void *buffer = NULL;

Expand Down Expand Up @@ -536,8 +536,8 @@ TclpLoadMemory(
Tcl_Interp *interp, /* Used for error reporting. */
void *buffer, /* Buffer containing the desired code
* (allocated with TclpLoadMemoryGetBuffer). */
int size, /* Allocation size of buffer. */
int codeSize, /* Size of code data read into buffer or -1 if
size_t size, /* Allocation size of buffer. */
Tcl_Size codeSize, /* Size of code data read into buffer or -1 if
* an error occurred and the buffer should
* just be freed. */
Tcl_LoadHandle *loadHandle, /* Filled with token for dynamically loaded
Expand Down Expand Up @@ -577,15 +577,15 @@ TclpLoadMemory(
# define arch_abi CPU_ARCH_ABI64
#endif /* __LP64__ */

if ((size_t) codeSize >= sizeof(struct fat_header)
if ((size_t)codeSize >= sizeof(struct fat_header)
&& fh->magic == OSSwapHostToBigInt32(FAT_MAGIC)) {
uint32_t fh_nfat_arch = OSSwapBigToHostInt32(fh->nfat_arch);

/*
* Fat binary, try to find mach_header for our architecture
*/

if ((size_t) codeSize >= sizeof(struct fat_header) +
if ((size_t)codeSize >= sizeof(struct fat_header) +
fh_nfat_arch * sizeof(struct fat_arch)) {
void *fatarchs = (char*)buffer + sizeof(struct fat_header);
const NXArchInfo *arch = NXGetLocalArchInfo();
Expand Down

0 comments on commit 43e17d2

Please sign in to comment.