diff options
| author | ruki <[email protected]> | 2024-11-15 22:33:50 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-11-15 22:33:50 +0800 |
| commit | ad8324471f281a348a01fd982d483bb9cf0e56cf (patch) | |
| tree | 85c20f05b364b564ad54e025d19a9f619f344696 | |
| parent | 2a8211ad79a8aaa7a053272eb4aa8c9ec9bb6ed9 (diff) | |
improve xxhash
| -rw-r--r-- | core/src/xmake/hash/xxhash.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/core/src/xmake/hash/xxhash.c b/core/src/xmake/hash/xxhash.c index 12dd3ba10..2d6f44d44 100644 --- a/core/src/xmake/hash/xxhash.c +++ b/core/src/xmake/hash/xxhash.c @@ -47,7 +47,7 @@ tb_int_t xm_hash_xxhash(lua_State* lua) if (mode != 64 && mode != 128) { lua_pushnil(lua); - lua_pushfstring(lua, "invalid mode(%d))!", (tb_int_t)mode); + lua_pushfstring(lua, "invalid mode(%d)!", (tb_int_t)mode); return 2; } @@ -65,7 +65,7 @@ tb_int_t xm_hash_xxhash(lua_State* lua) tb_assert_static(sizeof(lua_Integer) >= sizeof(tb_pointer_t)); // compuate hash - tb_byte_t const* buffer; + tb_byte_t const* buffer = tb_null; XXH64_hash_t value64; XXH128_hash_t value128; if (mode == 64) @@ -78,6 +78,12 @@ tb_int_t xm_hash_xxhash(lua_State* lua) value128 = XM_XXH3_128bits(data, size); buffer = (tb_byte_t const*)&value128; } + if (!buffer) + { + lua_pushnil(lua); + lua_pushfstring(lua, "empty buffer!"); + return 2; + } // make xxhash string tb_size_t i = 0; |
