From ca9174e1d8812e09e756efce4b1f718b85c9912f Mon Sep 17 00:00:00 2001 From: janwas Date: Sat, 7 Aug 2004 13:45:03 +0000 Subject: [PATCH] update vfs_load; now returns handle with the correct file size (i.e. leaving out padding) This was SVN commit r934. --- source/lib/res/vfs.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/lib/res/vfs.cpp b/source/lib/res/vfs.cpp index 49f82886cf..f0638b0158 100755 --- a/source/lib/res/vfs.cpp +++ b/source/lib/res/vfs.cpp @@ -1368,7 +1368,24 @@ debug_out("vfs_load fn=%s\n", fn); ssize_t nread = vfs_io(hf, size, &p); if(nread > 0) { + // one case where we need the handle return value is Tex.hm; + // we can't have the pointer freed behind our back there. + // if someone calls mem_get_ptr or mem_size, it must return the + // real memory range (p+size), disregarding padding added by File. + // hence, mem_assign finds the actual allocation to which p belongs + // (not necessarily starting at p); we mem_assign_user a subrange. hm = mem_assign(p, size); + assert(hm > 0); + if(mem_assign_user(hm, p, size) < 0) + debug_warn("vfs_load: mem_assign_user failed"); + + // sanity check: handle returns correct info +#ifndef NDEBUG + size_t test_size; + void* test_p = mem_get_ptr(hm, &test_size); + assert(test_p == p && test_size == size); +#endif + if(flags & FILE_CACHE) { vf->hm = hm;