Comparison

util-src/pposix.c @ 10410:659b577f280c 0.11

util.pposix: Avoid overflow of malloc info at 2GB (fixes #1445 until 4GB)
author Kim Alvefur <zash@zash.se>
date Sat, 16 Nov 2019 16:45:33 +0100
parent 9282:778d2dbfc784
child 10411:db2a06b9ff98
comparison
equal deleted inserted replaced
10400:4c2d789a106b 10410:659b577f280c
719 #ifdef WITH_MALLINFO 719 #ifdef WITH_MALLINFO
720 int lc_meminfo(lua_State *L) { 720 int lc_meminfo(lua_State *L) {
721 struct mallinfo info = mallinfo(); 721 struct mallinfo info = mallinfo();
722 lua_createtable(L, 0, 5); 722 lua_createtable(L, 0, 5);
723 /* This is the total size of memory allocated with sbrk by malloc, in bytes. */ 723 /* This is the total size of memory allocated with sbrk by malloc, in bytes. */
724 lua_pushinteger(L, info.arena); 724 lua_pushinteger(L, (unsigned)info.arena);
725 lua_setfield(L, -2, "allocated"); 725 lua_setfield(L, -2, "allocated");
726 /* This is the total size of memory allocated with mmap, in bytes. */ 726 /* This is the total size of memory allocated with mmap, in bytes. */
727 lua_pushinteger(L, info.hblkhd); 727 lua_pushinteger(L, (unsigned)info.hblkhd);
728 lua_setfield(L, -2, "allocated_mmap"); 728 lua_setfield(L, -2, "allocated_mmap");
729 /* This is the total size of memory occupied by chunks handed out by malloc. */ 729 /* This is the total size of memory occupied by chunks handed out by malloc. */
730 lua_pushinteger(L, info.uordblks); 730 lua_pushinteger(L, (unsigned)info.uordblks);
731 lua_setfield(L, -2, "used"); 731 lua_setfield(L, -2, "used");
732 /* This is the total size of memory occupied by free (not in use) chunks. */ 732 /* This is the total size of memory occupied by free (not in use) chunks. */
733 lua_pushinteger(L, info.fordblks); 733 lua_pushinteger(L, (unsigned)info.fordblks);
734 lua_setfield(L, -2, "unused"); 734 lua_setfield(L, -2, "unused");
735 /* This is the size of the top-most releasable chunk that normally borders the 735 /* This is the size of the top-most releasable chunk that normally borders the
736 end of the heap (i.e., the high end of the virtual address space's data segment). */ 736 end of the heap (i.e., the high end of the virtual address space's data segment). */
737 lua_pushinteger(L, info.keepcost); 737 lua_pushinteger(L, (unsigned)info.keepcost);
738 lua_setfield(L, -2, "returnable"); 738 lua_setfield(L, -2, "returnable");
739 return 1; 739 return 1;
740 } 740 }
741 #endif 741 #endif
742 742