ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CBOR-XS/XS.xs
(Generate patch)

Comparing CBOR-XS/XS.xs (file contents):
Revision 1.60 by root, Sat Nov 26 00:47:02 2016 UTC vs.
Revision 1.62 by root, Sat Nov 26 02:11:52 2016 UTC

6#include <string.h> 6#include <string.h>
7#include <stdlib.h> 7#include <stdlib.h>
8#include <stdio.h> 8#include <stdio.h>
9#include <limits.h> 9#include <limits.h>
10#include <float.h> 10#include <float.h>
11#include <inttypes.h>
11 12
12#define ECB_NO_THREADS 1 13#define ECB_NO_THREADS 1
13#include "ecb.h" 14#include "ecb.h"
14 15
15// compatibility with perl <5.18 16// compatibility with perl <5.18
186 187
187// minimum length of a string to be registered for stringref 188// minimum length of a string to be registered for stringref
188ecb_inline int 189ecb_inline int
189minimum_string_length (UV idx) 190minimum_string_length (UV idx)
190{ 191{
191 return idx > 23 192 return idx <= 23 ? 3
192 ? idx > 0xffU 193 : idx <= 0xffU ? 4
193 ? idx > 0xffffU 194 : idx <= 0xffffU ? 5
194 ? idx > 0xffffffffU 195 : idx <= 0xffffffffU ? 7
195 ? 11 196 : 11;
196 : 7
197 : 5
198 : 4
199 : 3;
200} 197}
201 198
202///////////////////////////////////////////////////////////////////////////// 199/////////////////////////////////////////////////////////////////////////////
203// encoder 200// encoder
204 201
217} enc_t; 214} enc_t;
218 215
219ecb_inline void 216ecb_inline void
220need (enc_t *enc, STRLEN len) 217need (enc_t *enc, STRLEN len)
221{ 218{
222 if (ecb_expect_false (enc->cur + len >= enc->end)) 219 if (ecb_expect_false ((uintptr_t)(enc->end - enc->cur) < len))
223 { 220 {
224 STRLEN cur = enc->cur - (char *)SvPVX (enc->sv); 221 STRLEN cur = enc->cur - (char *)SvPVX (enc->sv);
225 SvGROW (enc->sv, cur + (len < (cur >> 2) ? cur >> 2 : len) + 1); 222 SvGROW (enc->sv, cur + (len < (cur >> 2) ? cur >> 2 : len) + 1);
226 enc->cur = SvPVX (enc->sv) + cur; 223 enc->cur = SvPVX (enc->sv) + cur;
227 enc->end = SvPVX (enc->sv) + SvLEN (enc->sv) - 1; 224 enc->end = SvPVX (enc->sv) + SvLEN (enc->sv) - 1;
708 705
709#define ERR_DO(do) SB do; goto fail; SE 706#define ERR_DO(do) SB do; goto fail; SE
710#define ERR(reason) ERR_DO (err_set (dec, reason)) 707#define ERR(reason) ERR_DO (err_set (dec, reason))
711#define ERR_ERRSV ERR_DO (err_errsv (dec)) 708#define ERR_ERRSV ERR_DO (err_errsv (dec))
712 709
713#define WANT(len) if (ecb_expect_false ((UV)(dec->end - dec->cur) < (UV)len)) ERR_DO (err_unexpected_end (dec)) 710#define WANT(len) if (ecb_expect_false ((uintptr_t)(dec->end - dec->cur) < (STRLEN)len)) ERR_DO (err_unexpected_end (dec))
714 711
715#define DEC_INC_DEPTH if (ecb_expect_false (++dec->depth > dec->cbor.max_depth)) ERR (ERR_NESTING_EXCEEDED) 712#define DEC_INC_DEPTH if (ecb_expect_false (++dec->depth > dec->cbor.max_depth)) ERR (ERR_NESTING_EXCEEDED)
716#define DEC_DEC_DEPTH --dec->depth 713#define DEC_DEC_DEPTH --dec->depth
717 714
718static UV 715static UV

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines