From cd956a2afff71c4c5b3cc313f421fce723b7c6a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sun, 3 Oct 2010 04:17:52 +0200 Subject: [PATCH] lib/nbl: When the pointer array is empty, don't output 0x800 0s. --- lib/nbl.erl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/nbl.erl b/lib/nbl.erl index b62afed..0f76b36 100644 --- a/lib/nbl.erl +++ b/lib/nbl.erl @@ -45,10 +45,16 @@ pack_files([], {AccH, AccD, AccP, _FilePos, _PtrIndex}) -> BinD = iolist_to_binary(lists:reverse(AccD)), PaddingD = 8 * (16#800 - (byte_size(BinD) rem 16#800)), BinP = iolist_to_binary(lists:reverse(AccP)), - PaddingP = 8 * (16#800 - (byte_size(BinP) rem 16#800)), + PtrSize = byte_size(BinP), + PtrArray = case PtrSize of + 0 -> << >>; + _ -> + PaddingP = 8 * (16#800 - (byte_size(BinP) rem 16#800)), + << BinP/binary, 0:PaddingP >> + end, {<< BinH/binary, 0:PaddingH2 >>, << BinD/binary, 0:PaddingD >>, byte_size(BinD), - << BinP/binary, 0:PaddingP >>, byte_size(BinP)}; + PtrArray, PtrSize}; pack_files([{data, Filename, Data, PtrList}|Tail], {AccH, AccD, AccP, FilePos, PtrIndex}) -> ID = case filename:extension(Filename) of ".bin" -> << $S, $T, $D, 0 >>;