aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wslua/wslua_tvb.c
diff options
context:
space:
mode:
authorBalint Reczey <balint.reczey@ericsson.com>2008-09-16 14:00:48 +0000
committerBalint Reczey <balint.reczey@ericsson.com>2008-09-16 14:00:48 +0000
commitd3c1fca78d04510fd95772ffa7ee62c53b18c862 (patch)
treef4f444438416dbd686f9805e0b5658804e3ee0fc /epan/wslua/wslua_tvb.c
parentcb477a2a4a1e4e91d2badd6b4622bde72becf048 (diff)
Fix for bug 1965:
Fix ByteArray append() and set_size() svn path=/trunk/; revision=26215
Diffstat (limited to 'epan/wslua/wslua_tvb.c')
-rw-r--r--epan/wslua/wslua_tvb.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/epan/wslua/wslua_tvb.c b/epan/wslua/wslua_tvb.c
index d7d992daab..5835bd9a67 100644
--- a/epan/wslua/wslua_tvb.c
+++ b/epan/wslua/wslua_tvb.c
@@ -126,9 +126,9 @@ WSLUA_METHOD ByteArray_append(lua_State* L) {
ByteArray ba2 = checkByteArray(L,2);
if (! (ba && ba2) )
- WSLUA_ERROR(ByteArray_prepend,"both arguments must be ByteArrays");
+ WSLUA_ERROR(ByteArray_append,"both arguments must be ByteArrays");
- g_byte_array_prepend(ba,ba2->data,ba2->len);
+ g_byte_array_append(ba,ba2->data,ba2->len);
pushByteArray(L,ba);
return 1;
@@ -140,10 +140,21 @@ WSLUA_METHOD ByteArray_set_size(lua_State* L) {
ByteArray ba = checkByteArray(L,1);
int siz = luaL_checkint(L,2);
+ guint8* padding;
if (!ba) return 0;
+ if (siz < 0) {
+ WSLUA_ERROR(ByteArray_set_size,"ByteArray size must be non-negative");
+ return 0;
+ }
- g_byte_array_set_size(ba,siz);
+ if (ba->len >= (uint)siz) { /* truncate */
+ g_byte_array_set_size(ba,siz);
+ } else { /* fill */
+ padding = g_malloc0(sizeof(guint8)*(siz - ba->len));
+ g_byte_array_append(ba,padding,siz - ba->len);
+ g_free(padding);
+ }
return 0;
}