| 898 | |
| 899 | PG_FUNCTION_INFO_V1(subfloatvector); |
| 900 | Datum subfloatvector(PG_FUNCTION_ARGS) |
| 901 | { |
| 902 | FloatVector *a = PG_GETARG_FLOATVECTOR_P(0); |
| 903 | int32 start = PG_GETARG_INT32(1); |
| 904 | int32 count = PG_GETARG_INT32(2); |
| 905 | |
| 906 | if (count < 1) { |
| 907 | ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION), |
| 908 | errmsg("vector must have at least 1 dimension"))); |
| 909 | } |
| 910 | |
| 911 | /* |
| 912 | * Check if (start + count > a->dim), avoiding integer overflow. a->dim |
| 913 | * and count are both positive, so a->dim - count won't overflow. |
| 914 | */ |
| 915 | int32 end = start > a->dim - count ? |
| 916 | a->dim + 1 : |
| 917 | start + count; |
| 918 | |
| 919 | /* Indexing starts at 1, like substring */ |
| 920 | if (start < 1) { |
| 921 | start = 1; |
| 922 | } else if (start > a->dim) { |
| 923 | ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION), |
| 924 | errmsg("vector must have at least 1 dimension"))); |
| 925 | } |
| 926 | |
| 927 | int dim = end - start; |
| 928 | CheckDim(dim); |
| 929 | FloatVector *result = InitFloatVector(dim); |
| 930 | memcpy(result->x, a->x + start - 1, dim * sizeof(float)); |
| 931 | PG_FREE_IF_COPY(a, 0); |
| 932 | PG_RETURN_POINTER(result); |
| 933 | } |
| 934 | |
| 935 | FloatVectorArray FloatVectorArrayInit(int maxlen, int dimensions) |
| 936 | { |
nothing calls this directly
no test coverage detected