[retro-gtk/wip/aplazas/gl-errors] pass bytes size as it may not be null-terminated



commit b946c532b898ae40b31193fc0c2e523fcc1ec897
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu Nov 16 13:29:19 2017 +0100

    pass bytes size as it may not be null-terminated

 retro-gtk/retro-glsl-filter.c |   21 +++++----------------
 1 files changed, 5 insertions(+), 16 deletions(-)
---
diff --git a/retro-gtk/retro-glsl-filter.c b/retro-gtk/retro-glsl-filter.c
index 7c534c7..820bfd9 100644
--- a/retro-gtk/retro-glsl-filter.c
+++ b/retro-gtk/retro-glsl-filter.c
@@ -131,7 +131,6 @@ retro_glsl_filter_new (const char  *uri,
   GKeyFile *key_file;
   GFile *file;
   GFile *parent;
-  GFileInputStream *stream;
   GBytes *bytes;
   const gchar *value;
   GError *inner_error = NULL;
@@ -139,25 +138,13 @@ retro_glsl_filter_new (const char  *uri,
   g_return_val_if_fail (uri != NULL, NULL);
 
   file = g_file_new_for_uri (uri);
-  stream = g_file_read (file, NULL, &inner_error);
-  if (G_UNLIKELY (inner_error != NULL)) {
-    g_propagate_error (error, inner_error);
-    g_object_unref (file);
-
-    return NULL;
-  }
-
-  bytes = g_input_stream_read_bytes (G_INPUT_STREAM (stream), 4096, NULL, error);
-  if (G_UNLIKELY (inner_error != NULL)) {
-    g_propagate_error (error, inner_error);
+  bytes = g_file_try_read_bytes (file);
+  if (G_UNLIKELY (bytes == NULL)) {
     g_object_unref (file);
-    g_object_unref (stream);
 
     return NULL;
   }
 
-  g_object_unref (stream);
-
   key_file = g_key_file_new ();
   g_key_file_load_from_bytes (key_file, bytes, G_KEY_FILE_NONE, &inner_error);
   if (G_UNLIKELY (inner_error != NULL)) {
@@ -259,14 +246,16 @@ create_shader (GBytes  *source_bytes,
                GError **error)
 {
   const gchar *source;
+  gint size;
   GLuint shader;
   gint status;
   gint log_length;
   gchar *buffer;
 
   source = g_bytes_get_data (source_bytes, NULL);
+  size = g_bytes_get_size (source_bytes);
   shader = glCreateShader (shader_type);
-  glShaderSource (shader, 1, &source, NULL);
+  glShaderSource (shader, 1, &source, &size);
   glCompileShader (shader);
 
   status = 0;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]