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

Function xdr_string

src/common/xdr.cpp:694–754  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

692
693
694bool_t xdr_string(xdr_t* xdrs, SCHAR** sp, unsigned maxlength)
695{
696/**************************************
697 *
698 * x d r _ s t r i n g
699 *
700 **************************************
701 *
702 * Functional description
703 * Encode, decode, or free a string.
704 *
705 **************************************/
706 SCHAR trash[4];
707 static const SCHAR filler[4] = { 0, 0, 0, 0 };
708 ULONG length;
709
710 switch (xdrs->x_op)
711 {
712 case XDR_ENCODE:
713 length = static_cast<ULONG>(strlen(*sp));
714 if (length > maxlength ||
715 !PUTLONG(xdrs, reinterpret_cast<SLONG*>(&length)) ||
716 !PUTBYTES(*sp, length))
717 {
718 return FALSE;
719 }
720 if ((length = (4 - length) & 3) != 0)
721 return PUTBYTES(filler, length);
722 return TRUE;
723
724 case XDR_DECODE:
725 if (!*sp)
726 {
727 *sp = (SCHAR*) XDR_ALLOC((ULONG) (maxlength + 1));
728 // FREE: via XDR_FREE call to this procedure
729 if (!*sp) // NOMEM: return error
730 return FALSE;
731 DEBUG_XDR_ALLOC(xdrs, sp, *sp, (maxlength + 1));
732 }
733 if (!GETLONG(xdrs, reinterpret_cast<SLONG*>(&length)) ||
734 length > maxlength || !GETBYTES(*sp, length))
735 {
736 return FALSE;
737 }
738 (*sp)[length] = 0;
739 if ((length = (4 - length) & 3) != 0)
740 return GETBYTES(trash, length);
741 return TRUE;
742
743 case XDR_FREE:
744 if (*sp)
745 {
746 XDR_FREEA(*sp);
747 DEBUG_XDR_FREE(xdrs, sp, *sp, (maxlength + 1));
748 *sp = NULL;
749 }
750 return TRUE;
751 }

Callers 1

xdr_wrapstringFunction · 0.85

Calls 6

PUTLONGFunction · 0.85
XDR_ALLOCFunction · 0.85
GETLONGFunction · 0.85
XDR_FREEAFunction · 0.85
DEBUG_XDR_ALLOCFunction · 0.70
DEBUG_XDR_FREEFunction · 0.70

Tested by

no test coverage detected