MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / xdr_slice

Function xdr_slice

src/remote/protocol.cpp:1801–1896  ·  view source on GitHub ↗

Maybe it's better to take sdl_length into account?

Source from the content-addressed store, hash-verified

1799
1800// Maybe it's better to take sdl_length into account?
1801static bool_t xdr_slice(RemoteXdr* xdrs, lstring* slice, /*USHORT sdl_length,*/ const UCHAR* sdl)
1802{
1803/**************************************
1804 *
1805 * x d r _ s l i c e
1806 *
1807 **************************************
1808 *
1809 * Functional description
1810 * Move a slice of an array under
1811 *
1812 **************************************/
1813 if (!xdr_long(xdrs, reinterpret_cast<SLONG*>(&slice->lstr_length)))
1814 return FALSE;
1815
1816 if ((xdrs->x_op != XDR_FREE) && !sdl)
1817 return FALSE;
1818
1819 // Handle operation specific stuff, particularly memory allocation/deallocation
1820
1821 switch (xdrs->x_op)
1822 {
1823 case XDR_ENCODE:
1824 break;
1825
1826 case XDR_DECODE:
1827 if (!slice->lstr_length)
1828 return TRUE;
1829 if (slice->lstr_length > slice->lstr_allocated && slice->lstr_allocated)
1830 {
1831 delete[] slice->lstr_address;
1832 DEBUG_XDR_FREE(xdrs, slice, slice->lstr_address, slice->lstr_allocated);
1833 slice->lstr_address = NULL;
1834 }
1835 if (!slice->lstr_address)
1836 {
1837 try {
1838 slice->lstr_address = FB_NEW_POOL(*getDefaultMemoryPool()) UCHAR[slice->lstr_length];
1839 }
1840 catch (const BadAlloc&) {
1841 return false;
1842 }
1843
1844 slice->lstr_allocated = slice->lstr_length;
1845 DEBUG_XDR_ALLOC(xdrs, slice, slice->lstr_address, slice->lstr_allocated);
1846 }
1847 break;
1848
1849 case XDR_FREE:
1850 if (slice->lstr_allocated) {
1851 delete[] slice->lstr_address;
1852 DEBUG_XDR_FREE(xdrs, slice, slice->lstr_address, slice->lstr_allocated);
1853 }
1854 slice->lstr_address = NULL;
1855 slice->lstr_allocated = 0;
1856 return TRUE;
1857 }
1858

Callers 1

xdr_protocolFunction · 0.70

Calls 7

xdr_longFunction · 0.85
getDefaultMemoryPoolFunction · 0.85
SDL_infoFunction · 0.85
xdr_opaqueFunction · 0.85
xdr_datumFunction · 0.85
DEBUG_XDR_FREEFunction · 0.70
DEBUG_XDR_ALLOCFunction · 0.70

Tested by

no test coverage detected