| 38 | namespace Firebird { |
| 39 | |
| 40 | unsigned makeDynamicStrings(unsigned length, ISC_STATUS* const dst, const ISC_STATUS* const src) |
| 41 | { |
| 42 | const ISC_STATUS* end = &src[length]; |
| 43 | |
| 44 | // allocate space for strings |
| 45 | size_t len = 0; |
| 46 | for (const ISC_STATUS* from = src; from < end; ++from) |
| 47 | { |
| 48 | const ISC_STATUS type = *from++; |
| 49 | if (from == end || type == isc_arg_end) |
| 50 | { |
| 51 | end = from - 1; |
| 52 | break; |
| 53 | } |
| 54 | |
| 55 | switch (type) |
| 56 | { |
| 57 | case isc_arg_cstring: |
| 58 | if (from + 1 >= end) |
| 59 | { |
| 60 | end = from - 1; |
| 61 | break; |
| 62 | } |
| 63 | len += *from++; |
| 64 | len++; |
| 65 | break; |
| 66 | |
| 67 | case isc_arg_string: |
| 68 | case isc_arg_interpreted: |
| 69 | case isc_arg_sql_state: |
| 70 | len += strlen(reinterpret_cast<const char*>(*from)); |
| 71 | len++; |
| 72 | break; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | char* string = len ? FB_NEW_POOL(*getDefaultMemoryPool()) char[len] : NULL; |
| 77 | ISC_STATUS* to = dst; |
| 78 | |
| 79 | // copy status vector saving strings in local buffer |
| 80 | for (const ISC_STATUS* from = src; from < end; ++from) |
| 81 | { |
| 82 | const ISC_STATUS type = *from++; |
| 83 | *to++ = type == isc_arg_cstring ? isc_arg_string : type; |
| 84 | |
| 85 | switch (type) |
| 86 | { |
| 87 | case isc_arg_cstring: |
| 88 | fb_assert(string); |
| 89 | *to++ = (ISC_STATUS)(IPTR) string; |
| 90 | memcpy(string, reinterpret_cast<const char*>(from[1]), from[0]); |
| 91 | string += *from++; |
| 92 | *string++ = '\0'; |
| 93 | break; |
| 94 | |
| 95 | case isc_arg_string: |
| 96 | case isc_arg_interpreted: |
| 97 | case isc_arg_sql_state: |
no test coverage detected