Helper to add a string attribute
| 11167 | |
| 11168 | // Helper to add a string attribute |
| 11169 | static int AddStringAttribute(EXRHeader *exr_header, const char *name, const char *value) { |
| 11170 | if (!exr_header || !name || !value) return TINYEXR_ERROR_INVALID_ARGUMENT; |
| 11171 | |
| 11172 | int new_count = exr_header->num_custom_attributes + 1; |
| 11173 | if (new_count > TINYEXR_MAX_CUSTOM_ATTRIBUTES) { |
| 11174 | return TINYEXR_ERROR_DATA_TOO_LARGE; |
| 11175 | } |
| 11176 | |
| 11177 | // Reallocate attributes array |
| 11178 | EXRAttribute *new_attrs = static_cast<EXRAttribute*>( |
| 11179 | realloc(exr_header->custom_attributes, |
| 11180 | sizeof(EXRAttribute) * static_cast<size_t>(new_count))); |
| 11181 | if (!new_attrs) { |
| 11182 | return TINYEXR_ERROR_INVALID_DATA; |
| 11183 | } |
| 11184 | |
| 11185 | exr_header->custom_attributes = new_attrs; |
| 11186 | EXRAttribute *attr = &exr_header->custom_attributes[exr_header->num_custom_attributes]; |
| 11187 | |
| 11188 | // Initialize the new attribute |
| 11189 | memset(attr, 0, sizeof(EXRAttribute)); |
| 11190 | |
| 11191 | #ifdef _MSC_VER |
| 11192 | strncpy_s(attr->name, sizeof(attr->name), name, 255); |
| 11193 | strncpy_s(attr->type, sizeof(attr->type), "string", 255); |
| 11194 | #else |
| 11195 | strncpy(attr->name, name, 255); |
| 11196 | attr->name[255] = '\0'; |
| 11197 | strncpy(attr->type, "string", 255); |
| 11198 | attr->type[255] = '\0'; |
| 11199 | #endif |
| 11200 | |
| 11201 | size_t value_len = strlen(value) + 1; // Include null terminator |
| 11202 | attr->value = static_cast<unsigned char*>(malloc(value_len)); |
| 11203 | if (!attr->value) { |
| 11204 | return TINYEXR_ERROR_INVALID_DATA; |
| 11205 | } |
| 11206 | memcpy(attr->value, value, value_len); |
| 11207 | attr->size = static_cast<int>(value_len); |
| 11208 | |
| 11209 | exr_header->num_custom_attributes = new_count; |
| 11210 | |
| 11211 | return TINYEXR_SUCCESS; |
| 11212 | } |
| 11213 | |
| 11214 | // Helper to add an int attribute |
| 11215 | static int AddIntAttribute(EXRHeader *exr_header, const char *name, int value) { |
no outgoing calls
no test coverage detected