@@ -74,13 +74,16 @@ extern "C" {
7474 FILE* file = fopen (filename, " rb" );
7575 fseek (file, 0 , SEEK_END);
7676 long file_length = ftell (file);
77+ if (file_length < 0 ) {
78+ return NULL ;
79+ }
7780 fseek (file, 0 , SEEK_SET);
7881 unsigned char * data = static_cast <unsigned char *>(malloc (file_length));
7982 inkAssert (data, " Malloc of size %u failed" , file_length);
80- unsigned length = fread (data, sizeof (unsigned char ), file_length, file);
83+ size_t length = fread (data, sizeof (unsigned char ), file_length, file);
8184 inkAssert (
82- file_length == length, " Expected to read file of size %u, but only read %u " , file_length ,
83- length
85+ static_cast < size_t >( file_length) == length,
86+ " Expected to read file of size %u, but only read %u " , file_length, length
8487 );
8588 fclose (file);
8689 return reinterpret_cast <HInkStory*>(story::from_binary (data, file_length));
@@ -91,13 +94,16 @@ extern "C" {
9194 FILE* file = fopen (filename, " rb" );
9295 fseek (file, 0 , SEEK_END);
9396 long file_length = ftell (file);
97+ if (file_length < 0 ) {
98+ return NULL ;
99+ }
94100 fseek (file, 0 , SEEK_SET);
95101 unsigned char * data = static_cast <unsigned char *>(malloc (file_length));
96102 inkAssert (data, " Malloc of size %u failed" , file_length);
97- unsigned length = fread (data, sizeof (unsigned char ), file_length, file);
103+ size_t length = fread (data, sizeof (unsigned char ), file_length, file);
98104 inkAssert (
99- file_length == length, " Expected to read file of size %u, but only read %u " , file_length ,
100- length
105+ static_cast < size_t >( file_length) == length,
106+ " Expected to read file of size %u, but only read %u " , file_length, length
101107 );
102108 fclose (file);
103109 return reinterpret_cast <HInkSnapshot*>(snapshot::from_binary (data, file_length));
@@ -107,7 +113,7 @@ extern "C" {
107113 {
108114 FILE* file = fopen (filename, " wb" );
109115 const snapshot& snap = *reinterpret_cast <const snapshot*>(self);
110- unsigned length = fwrite (snap.get_data (), sizeof (unsigned char ), snap.get_data_len (), file);
116+ size_t length = fwrite (snap.get_data (), sizeof (unsigned char ), snap.get_data_len (), file);
111117 inkAssert (
112118 length == snap.get_data_len (),
113119 " Snapshot write failed, snapshot of size %u, but only %u bytes where written." ,
@@ -119,13 +125,17 @@ extern "C" {
119125
120126 HInkStory* ink_story_from_binary (const unsigned char * data, size_t length, bool freeOnDestroy)
121127 {
122- return reinterpret_cast <HInkStory*>(story::from_binary (data, length, freeOnDestroy));
128+ return reinterpret_cast <HInkStory*>(
129+ story::from_binary (data, static_cast <ink::size_t >(length), freeOnDestroy)
130+ );
123131 }
124132
125133 HInkSnapshot*
126134 ink_snapshot_from_binary (const unsigned char * data, size_t length, bool freeOnDestroy)
127135 {
128- return reinterpret_cast <HInkSnapshot*>(snapshot::from_binary (data, length, freeOnDestroy));
136+ return reinterpret_cast <HInkSnapshot*>(
137+ snapshot::from_binary (data, static_cast <ink::size_t >(length), freeOnDestroy)
138+ );
129139 }
130140
131141 void ink_snapshot_get_binary (
@@ -291,7 +301,7 @@ extern "C" {
291301 function_name,
292302 [callback](size_t len, const value* vals) {
293303 InkValue* c_vals = reinterpret_cast <InkValue*>(const_cast <value*>(vals));
294- int c_len = len;
304+ int c_len = static_cast < int >( len) ;
295305 for (int i = 0 ; i < c_len; ++i) {
296306 c_vals[i] = inkvar_to_c (const_cast <value&>(vals[i]));
297307 }
@@ -310,7 +320,7 @@ extern "C" {
310320 function_name,
311321 [callback](size_t len, const value* vals) -> value {
312322 InkValue* c_vals = reinterpret_cast <InkValue*>(const_cast <value*>(vals));
313- int c_len = len;
323+ int c_len = static_cast < int >( len) ;
314324 for (int i = 0 ; i < c_len; ++i) {
315325 c_vals[i] = inkvar_to_c (const_cast <value&>(vals[i]));
316326 }
0 commit comments