This function initializes StringVal 'dst' with a newly allocated buffer of 'buf_len' bytes and copies the content of StringVal 'src' into it. If allocation fails, 'dst' will be set to a null string.
| 165 | // 'buf_len' bytes and copies the content of StringVal 'src' into it. |
| 166 | // If allocation fails, 'dst' will be set to a null string. |
| 167 | static void CopyStringVal(FunctionContext* ctx, const StringVal& src, StringVal* dst) { |
| 168 | if (src.is_null) { |
| 169 | *dst = StringVal::null(); |
| 170 | } else { |
| 171 | uint8_t* copy = ctx->Allocate(src.len); |
| 172 | if (UNLIKELY(copy == NULL)) { |
| 173 | // Zero-length allocation always returns a hard-coded pointer. |
| 174 | DCHECK(src.len != 0 && !ctx->impl()->state()->GetQueryStatus().ok()); |
| 175 | *dst = StringVal::null(); |
| 176 | } else { |
| 177 | *dst = StringVal(copy, src.len); |
| 178 | memcpy(dst->ptr, src.ptr, src.len); |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | // Converts any UDF Val Type to a string representation |
| 184 | template <typename T> |
no test coverage detected