Skip to content

Commit 4242000

Browse files
committed
Verify the empty slice for tex_image_2d() call.
We will have a crash when we pass an empty slice to tex_image_2d(). Turn to pass a null() to tex_image_2d() if we have an empty slice.
1 parent f747107 commit 4242000

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

src/gl_fns.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -353,19 +353,13 @@ impl Gl for GlFns {
353353
format: GLenum,
354354
ty: GLenum,
355355
opt_data: Option<&[u8]>) {
356-
match opt_data {
357-
Some(data) => {
358-
unsafe {
359-
self.ffi_gl_.TexImage2D(target, level, internal_format, width, height, border, format, ty,
360-
data.as_ptr() as *const GLvoid);
361-
}
362-
}
363-
None => {
364-
unsafe {
365-
self.ffi_gl_.TexImage2D(target, level, internal_format, width, height, border, format, ty,
366-
ptr::null());
367-
}
368-
}
356+
let ptr = match opt_data {
357+
Some(data) if !data.is_empty() => data.as_ptr(),
358+
_ => ptr::null(),
359+
};
360+
unsafe {
361+
self.ffi_gl_.TexImage2D(target, level, internal_format, width, height, border, format, ty,
362+
ptr as *const GLvoid);
369363
}
370364
}
371365

src/gles_fns.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -331,19 +331,13 @@ impl Gl for GlesFns {
331331
format: GLenum,
332332
ty: GLenum,
333333
opt_data: Option<&[u8]>) {
334-
match opt_data {
335-
Some(data) => {
336-
unsafe {
337-
self.ffi_gl_.TexImage2D(target, level, internal_format, width, height, border, format, ty,
338-
data.as_ptr() as *const GLvoid);
339-
}
340-
}
341-
None => {
342-
unsafe {
343-
self.ffi_gl_.TexImage2D(target, level, internal_format, width, height, border, format, ty,
344-
ptr::null());
345-
}
346-
}
334+
let ptr = match opt_data {
335+
Some(data) if !data.is_empty() => data.as_ptr(),
336+
_ => ptr::null(),
337+
};
338+
unsafe {
339+
self.ffi_gl_.TexImage2D(target, level, internal_format, width, height, border, format, ty,
340+
ptr as *const GLvoid);
347341
}
348342
}
349343

0 commit comments

Comments
 (0)