From 83e369672002d553c9ec5196369c734ef60d4292 Mon Sep 17 00:00:00 2001
From: Philipp Gesang <phg42.2a@gmail.com>
Date: Mon, 4 Aug 2014 22:33:43 +0200
Subject: [PATCH] luainit.w: cast checksum field to unsigned when reading font
 from Lua

Addresses http://tracker.luatex.org/view.php?id=913

If the ``_font_checksum`` field is pulled from the font table using
``lua_numeric_field_by_index()`` it must be cast to unsigned first.
Since ``lua_roundnumber()`` casts directly to integer, relevant
information is lost. The patch fixes this by adding an ad-hoc exemption
for the checksum field but it might make sense to add a dedicated
function for pulling unsigned values instead.
---
 source/texk/web2c/luatexdir/lua/luainit.w | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/source/texk/web2c/luatexdir/lua/luainit.w b/source/texk/web2c/luatexdir/lua/luainit.w
index 98660ca..f732987 100644
--- a/source/texk/web2c/luatexdir/lua/luainit.w
+++ b/source/texk/web2c/luatexdir/lua/luainit.w
@@ -272,7 +272,10 @@ int lua_numeric_field_by_index(lua_State * L, int name_index, int dflt)
     lua_rawgeti(L, LUA_REGISTRYINDEX, name_index);      /* fetch the stringptr */
     lua_rawget(L, -2);
     if (lua_type(L, -1) == LUA_TNUMBER) {
-        i = lua_roundnumber(L, -1);
+        if (name_index == lua_key_index(checksum))
+            i = (unsigned)lua_tonumber(L, -1);
+        else
+            i = lua_roundnumber(L, -1);
     }
     lua_pop(L, 1);
     return i;
-- 
2.0.1

