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.61 by root, Sat Nov 26 02:10:19 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
192 ? idx > 0xffU 193 return idx <= 23 ? 3
193 ? idx > 0xffffU 194 : idx <= 0xffU ? 4
195 : idx <= 0xffffU ? 5
194 ? idx > 0xffffffffU 196 : idx <= 0xffffffffU ? 7
195 ? 11 197 : 11;
196 : 7
197 : 5
198 : 4
199 : 3;
200} 198}
201 199
202///////////////////////////////////////////////////////////////////////////// 200/////////////////////////////////////////////////////////////////////////////
203// encoder 201// encoder
204 202
217} enc_t; 215} enc_t;
218 216
219ecb_inline void 217ecb_inline void
220need (enc_t *enc, STRLEN len) 218need (enc_t *enc, STRLEN len)
221{ 219{
222 if (ecb_expect_false (enc->cur + len >= enc->end)) 220 if (ecb_expect_false ((uintptr_t)(enc->end - enc->cur) < len))
223 { 221 {
224 STRLEN cur = enc->cur - (char *)SvPVX (enc->sv); 222 STRLEN cur = enc->cur - (char *)SvPVX (enc->sv);
225 SvGROW (enc->sv, cur + (len < (cur >> 2) ? cur >> 2 : len) + 1); 223 SvGROW (enc->sv, cur + (len < (cur >> 2) ? cur >> 2 : len) + 1);
226 enc->cur = SvPVX (enc->sv) + cur; 224 enc->cur = SvPVX (enc->sv) + cur;
227 enc->end = SvPVX (enc->sv) + SvLEN (enc->sv) - 1; 225 enc->end = SvPVX (enc->sv) + SvLEN (enc->sv) - 1;
708 706
709#define ERR_DO(do) SB do; goto fail; SE 707#define ERR_DO(do) SB do; goto fail; SE
710#define ERR(reason) ERR_DO (err_set (dec, reason)) 708#define ERR(reason) ERR_DO (err_set (dec, reason))
711#define ERR_ERRSV ERR_DO (err_errsv (dec)) 709#define ERR_ERRSV ERR_DO (err_errsv (dec))
712 710
713#define WANT(len) if (ecb_expect_false ((UV)(dec->end - dec->cur) < (UV)len)) ERR_DO (err_unexpected_end (dec)) 711#define WANT(len) if (ecb_expect_false ((uintptr_t)(dec->end - dec->cur) < (STRLEN)len)) ERR_DO (err_unexpected_end (dec))
714 712
715#define DEC_INC_DEPTH if (ecb_expect_false (++dec->depth > dec->cbor.max_depth)) ERR (ERR_NESTING_EXCEEDED) 713#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 714#define DEC_DEC_DEPTH --dec->depth
717 715
718static UV 716static UV

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines