mirror of https://github.com/encounter/SDL.git
Add null termination to Wayland_data_source_get_data() if requested
Fixes https://github.com/libsdl-org/SDL/issues/6083
This commit is contained in:
parent
948dbe7d3f
commit
6e007c36e7
|
@ -305,12 +305,20 @@ Wayland_data_source_get_data(SDL_WaylandDataSource *source,
|
||||||
} else {
|
} else {
|
||||||
mime_data = mime_data_list_find(&source->mimes, mime_type);
|
mime_data = mime_data_list_find(&source->mimes, mime_type);
|
||||||
if (mime_data != NULL && mime_data->length > 0) {
|
if (mime_data != NULL && mime_data->length > 0) {
|
||||||
buffer = SDL_malloc(mime_data->length);
|
size_t buffer_length = mime_data->length;
|
||||||
|
|
||||||
|
if (null_terminate == SDL_TRUE) {
|
||||||
|
++buffer_length;
|
||||||
|
}
|
||||||
|
buffer = SDL_malloc(buffer_length);
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
*length = SDL_OutOfMemory();
|
*length = SDL_OutOfMemory();
|
||||||
} else {
|
} else {
|
||||||
*length = mime_data->length;
|
*length = mime_data->length;
|
||||||
SDL_memcpy(buffer, mime_data->data, mime_data->length);
|
SDL_memcpy(buffer, mime_data->data, mime_data->length);
|
||||||
|
if (null_terminate) {
|
||||||
|
*((Uint8 *)buffer + mime_data->length) = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue