mirror of
				https://github.com/libsdl-org/SDL.git
				synced 2025-11-04 01:34:38 +00:00 
			
		
		
		
	Fixed calling SDL_utf8strlcpy() with dst_bytes of 0
This commit is contained in:
		@@ -860,11 +860,14 @@ size_t SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxl
 | 
			
		||||
 | 
			
		||||
size_t SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
 | 
			
		||||
{
 | 
			
		||||
    size_t bytes = 0;
 | 
			
		||||
 | 
			
		||||
	if (dst_bytes > 0) {
 | 
			
		||||
		size_t src_bytes = SDL_strlen(src);
 | 
			
		||||
    size_t bytes = SDL_min(src_bytes, dst_bytes - 1);
 | 
			
		||||
		size_t i = 0;
 | 
			
		||||
		size_t trailing_bytes = 0;
 | 
			
		||||
 | 
			
		||||
		bytes = SDL_min(src_bytes, dst_bytes - 1);
 | 
			
		||||
		if (bytes) {
 | 
			
		||||
			unsigned char c = (unsigned char)src[bytes - 1];
 | 
			
		||||
			if (UTF8_IsLeadByte(c)) {
 | 
			
		||||
@@ -885,6 +888,7 @@ size_t SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size
 | 
			
		||||
			SDL_memcpy(dst, src, bytes);
 | 
			
		||||
		}
 | 
			
		||||
		dst[bytes] = '\0';
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    return bytes;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user