diff options
Diffstat (limited to 'redist')
-rw-r--r-- | redist/json_helpers.c | 28 | ||||
-rw-r--r-- | redist/linmath.c | 12 | ||||
-rw-r--r-- | redist/os_generic.c | 17 |
3 files changed, 29 insertions, 28 deletions
diff --git a/redist/json_helpers.c b/redist/json_helpers.c index 29d48bd..c52301d 100644 --- a/redist/json_helpers.c +++ b/redist/json_helpers.c @@ -50,44 +50,46 @@ void json_write_float_array(FILE* f, const char* tag, float* v, uint8_t count) { uint8_t i = 0; char * str1 = NULL; char * str2 = NULL; - asprintf(&str1,"\"%s\":[", tag); + if( asprintf(&str1,"\"%s\":[", tag) < 0 ) goto giveup; for (i=0;i<count;++i) { if ( (i+1) < count) { - asprintf(&str2, "%s\"%f\"", str1,v[i]); + if( asprintf(&str2, "%s\"%f\"", str1,v[i]) < 0 ) goto giveup; } else { - asprintf(&str2, "%s\"%f\",", str1,v[i]); + if( asprintf(&str2, "%s\"%f\",", str1,v[i]) < 0 ) goto giveup; } free(str1); str1=str2; str2=NULL; } - asprintf(&str2, "%s]", str1); + if( asprintf(&str2, "%s]", str1) < 0 ) goto giveup; fputs(str2,f); - free(str1); - free(str2); +giveup: + if( str1 ) free(str1); + if( str2 ) free(str2); } void json_write_double_array(FILE* f, const char* tag, double* v, uint8_t count) { uint8_t i = 0; char * str1 = NULL; char * str2 = NULL; - asprintf(&str1,"\"%s\":[", tag); + if( asprintf(&str1,"\"%s\":[", tag) < 0 ) goto giveup; for (i=0;i<count;++i) { if (i<(count-1)) { - asprintf(&str2, "%s\"%f\",", str1,v[i]); + if( asprintf(&str2, "%s\"%f\",", str1,v[i]) < 0 ) goto giveup; } else { - asprintf(&str2, "%s\"%f\"", str1,v[i]); + if( asprintf(&str2, "%s\"%f\"", str1,v[i]) < 0 ) goto giveup; } free(str1); str1=str2; str2=NULL; } - asprintf(&str2, "%s]", str1); + if( asprintf(&str2, "%s]", str1) < 0 ) goto giveup; fputs(str2,f); - free(str1); - free(str2); +giveup: + if( str1 ) free(str1); + if( str2 ) free(str2); } void json_write_uint32(FILE* f, const char* tag, uint32_t v) { @@ -119,7 +121,7 @@ char* load_file_to_mem(const char* path) { fseek( f, 0, SEEK_SET ); char * JSON_STRING = malloc( len + 1); memset(JSON_STRING,0,len+1); - fread( JSON_STRING, len, 1, f ); + int i = fread( JSON_STRING, len, 1, f ); i = i; //Ignore return value. fclose( f ); return JSON_STRING; } diff --git a/redist/linmath.c b/redist/linmath.c index caff1de..5fefe1e 100644 --- a/redist/linmath.c +++ b/redist/linmath.c @@ -520,17 +520,15 @@ void quatfrom2vectors(FLT *q, const FLT *src, const FLT *dest) FLT invs = 1 / s; FLT c[3]; - //cross3d(c, v0, v1); - cross3d(c, v1, v0); + cross3d(c, v0, v1); - q[0] = c[0] * invs; - q[1] = c[1] * invs; - q[2] = c[2] * invs; - q[3] = s * 0.5f; + q[0] = s * 0.5f; + q[1] = c[0] * invs; + q[2] = c[1] * invs; + q[3] = c[2] * invs; quatnormalize(q, q); } - } void matrix44copy(FLT * mout, const FLT * minm ) diff --git a/redist/os_generic.c b/redist/os_generic.c index 1ab4863..3191357 100644 --- a/redist/os_generic.c +++ b/redist/os_generic.c @@ -151,8 +151,9 @@ void OGDeleteSema( og_sema_t os ) #else -#define _GNU_SOURCE - +#ifndef _GNU_SOURCE +# define _GNU_SOURCE +#endif #include <sys/stat.h> #include <stdlib.h> @@ -198,7 +199,7 @@ double OGGetFileTime( const char * file ) og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter ) { - pthread_t * ret = malloc( sizeof( pthread_t ) ); + pthread_t * ret = (pthread_t *)malloc( sizeof( pthread_t ) ); int r = pthread_create( ret, 0, routine, parameter ); if( r ) { @@ -277,7 +278,7 @@ void OGDeleteMutex( og_mutex_t om ) og_sema_t OGCreateSema() { - sem_t * sem = malloc( sizeof( sem_t ) ); + sem_t * sem = (sem_t *)malloc( sizeof( sem_t ) ); sem_init( sem, 0, 0 ); return (og_sema_t)sem; } @@ -285,24 +286,24 @@ og_sema_t OGCreateSema() int OGGetSema( og_sema_t os ) { int valp; - sem_getvalue( os, &valp ); + sem_getvalue( (sem_t *)os, &valp ); return valp; } void OGLockSema( og_sema_t os ) { - sem_wait( os ); + sem_wait( (sem_t *)os ); } void OGUnlockSema( og_sema_t os ) { - sem_post( os ); + sem_post( (sem_t *)os ); } void OGDeleteSema( og_sema_t os ) { - sem_destroy( os ); + sem_destroy( (sem_t *)os ); free(os); } |