Skip to content

Commit

Permalink
fixup r12729 and also check return value from realloc
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@12730 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jun 3, 2016
1 parent 4622cd1 commit 070f886
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/rencode/rencode/rencode.pyx
Expand Up @@ -29,7 +29,7 @@ if py3:
unicode = str

from cpython cimport bool
from libc.stdlib cimport realloc, malloc, free
from libc.stdlib cimport realloc, free
from libc.string cimport memcpy

__version__ = ("Cython", 1, 0, 3)
Expand Down Expand Up @@ -151,11 +151,15 @@ cdef swap_byte_order_double(char *c):

cdef write_buffer_char(char **buf, int *pos, char c):
buf[0] = <char*>realloc(buf[0], pos[0] + 1)
if buf[0]==NULL:
raise Exception("memory allocation failure for output buffer: %i bytes needed" % (pos[0] + 1))
memcpy(&buf[0][pos[0]], &c, 1)
pos[0] += 1

cdef write_buffer(char **buf, int *pos, void* data, int size):
buf[0] = <char*>realloc(buf[0], pos[0] + size)
if buf[0]==NULL:
raise Exception("memory allocation failure for output buffer: %i bytes needed" % (pos[0] + 1))
memcpy(&buf[0][pos[0]], data, size)
pos[0] += size

Expand Down Expand Up @@ -375,7 +379,7 @@ cdef decode_big_number(char *data, int *pos):
cdef int x = 18
while (data[pos[0]+x] != CHR_TERM):
x += 1
s = data[pos[0]:x+1]
s = data[pos[0]:pos[0]+x]
pos[0] += x + 1
big_number = int(s)
return big_number
Expand Down

0 comments on commit 070f886

Please sign in to comment.