From 51ac2809e5c20a5f657c3c56877f75b2f789289d Mon Sep 17 00:00:00 2001 From: zixun Date: Tue, 14 Oct 2014 17:44:36 +0800 Subject: [PATCH] fix write_ff bug. --- sproto.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/sproto.c b/sproto.c index 0f519d1..50bc052 100644 --- a/sproto.c +++ b/sproto.c @@ -1076,9 +1076,14 @@ pack_seg(const uint8_t *src, uint8_t * buffer, int sz, int n) { static inline void write_ff(const uint8_t * src, uint8_t * des, int n) { + int align8_n = (n+7)&(~7); + des[0] = 0xff; - des[1] = n-1; - memcpy(des+2, src, n * 8); + des[1] = align8_n/8 - 1; + memcpy(des+2, src, n); + for(int i=0; i< align8_n-n; i++){ + des[n+2+i] = 0; + } } int @@ -1112,14 +1117,14 @@ sproto_pack(const void * srcv, int srcsz, void * bufferv, int bufsz) { ++ff_n; if (ff_n == 256) { if (bufsz >= 0) { - write_ff(ff_srcstart, ff_desstart, 256); + write_ff(ff_srcstart, ff_desstart, 256*8); } ff_n = 0; } } else { if (ff_n > 0) { if (bufsz >= 0) { - write_ff(ff_srcstart, ff_desstart, ff_n); + write_ff(ff_srcstart, ff_desstart, ff_n*8); } ff_n = 0; } @@ -1128,8 +1133,11 @@ sproto_pack(const void * srcv, int srcsz, void * bufferv, int bufsz) { buffer += n; size += n; } - if (ff_n > 0 && bufsz >= 0) { - write_ff(ff_srcstart, ff_desstart, ff_n); + if(bufsz >= 0){ + if(ff_n == 1) + write_ff(ff_srcstart, ff_desstart, 8); + else if (ff_n > 1) + write_ff(ff_srcstart, ff_desstart, srcsz - (intptr_t)(ff_srcstart - (const uint8_t*)srcv)); } return size; }