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

Function safe_interpret

src/yvalve/gds.cpp:829–1033  ·  view source on GitHub ↗

safe_interpret @brief Translate a status code with arguments to a string. Return the length of the string while updating the vector address. If the message is null (end of messages) or invalid, return 0; @param s the output buffer where a human readable version of the error is put @param bufsize the size of the output buffer @param vector the input, the address of const pointer to the st

Source from the content-addressed store, hash-verified

827
828**/
829static SLONG safe_interpret(char* const s, const FB_SIZE_T bufsize,
830 const ISC_STATUS** const vector, bool legacy)
831{
832 // CVC: It doesn't make sense to provide a buffer smaller than 50 bytes.
833 // Return error otherwise.
834 if (bufsize < 50)
835 return 0;
836
837 // Skip the SQLSTATE
838 if ((*vector)[0] == isc_arg_sql_state)
839 *vector += 2;
840
841 // If the first element of the vector doesn't signal an error, return.
842 if (!**vector)
843 return 0;
844
845 const ISC_STATUS* v;
846 ISC_STATUS code;
847 // Handle a case: "no errors, some warning(s)"
848 if ((*vector)[1] == 0 && (*vector)[2] == isc_arg_warning)
849 {
850 v = *vector + 4;
851 code = (*vector)[3];
852 }
853 else
854 {
855 v = *vector + 2;
856 code = (*vector)[1];
857 }
858
859 const TEXT* args[10];
860 const TEXT** arg = args;
861 const char* const* const argend = arg + FB_NELEM(args);
862
863 MsgFormat::SafeArg safe;
864
865 // Parse and collect any arguments that may be present
866
867 TEXT* p = 0;
868 const TEXT* q;
869 int temp_len = BUFFER_SMALL;
870 TEXT* temp = NULL;
871
872 for (;;)
873 {
874 // CVC: Close overflow in "args".
875 if (arg >= argend)
876 break;
877
878 int len;
879 const UCHAR x = (UCHAR) *v++;
880 switch (x)
881 {
882 case isc_arg_string:
883 *arg++ = (TEXT*) *v;
884 safe << (TEXT*) *v;
885 ++v;
886 continue;

Callers 3

API_ROUTINE fb_interpretFunction · 0.85

Calls 4

fb_msg_formatFunction · 0.85
MsgPrintFunction · 0.85
safe_strncpyFunction · 0.85
copy_terminateFunction · 0.50

Tested by

no test coverage detected