1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-09-27 22:58:24 +00:00

Pointer safety, code cleaning

This commit is contained in:
Carles Fernandez 2015-04-27 00:36:45 +02:00
parent 64b069f50d
commit 9b4435ac67
2 changed files with 9 additions and 34 deletions

View File

@ -18,7 +18,7 @@
*/
#include "volk_gnsssdr/volk_gnsssdr_malloc.h"
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -27,29 +27,6 @@
* see: http://linux.die.net/man/3/aligned_alloc
*/
// Disabling use of aligned_alloc. This function requires that size be
// a multiple of alignment, which is too restrictive for many uses of
// VOLK.
//// If we are using C11 standard, use the aligned_alloc
//#ifdef _ISOC11_SOURCE
//
//void *volk_gnsssdr_malloc(size_t size, size_t alignment)
//{
// void *ptr = aligned_alloc(alignment, size);
// if(ptr == NULL) {
// fprintf(stderr, "VOLK: Error allocating memory (aligned_alloc)\n");
// }
// return ptr;
//}
//
//void volk_gnsssdr_free(void *ptr)
//{
// free(ptr);
//}
//
//#else // _ISOC11_SOURCE
// Otherwise, test if we are a POSIX or X/Open system
// This only has a restriction that alignment be a power of 2and a
// multiple of sizeof(void *).
@ -59,11 +36,11 @@ void *volk_gnsssdr_malloc(size_t size, size_t alignment)
{
void *ptr;
// quoting posix_memalign() man page:
// "alignment must be a power of two and a multiple of sizeof(void *)"
// volk_get_alignment() could return 1 for some machines (e.g. generic_orc)
if (alignment == 1)
return malloc(size);
// quoting posix_memalign() man page:
// "alignment must be a power of two and a multiple of sizeof(void *)"
// volk_get_alignment() could return 1 for some machines (e.g. generic_orc)
if (alignment == 1)
return malloc(size);
int err = posix_memalign(&ptr, alignment, size);
if(err == 0)

View File

@ -21,19 +21,17 @@
#include <string.h>
#include <volk_gnsssdr/volk_gnsssdr_prefs.h>
//#if defined(_WIN32)
//#include <Windows.h>
//#endif
void volk_gnsssdr_get_config_path(char *path)
{
if (!path) return;
const char *suffix = "/.volk_gnsssdr/volk_gnsssdr_config";
char *home = NULL;
if (home == NULL) home = getenv("HOME");
if (home == NULL) home = getenv("APPDATA");
if (home == NULL)
{
path = NULL;
path[0] = 0;
return;
}
strcpy(path, home);
@ -49,7 +47,7 @@ size_t volk_gnsssdr_load_preferences(volk_gnsssdr_arch_pref_t **prefs_res)
//get the config path
volk_gnsssdr_get_config_path(path);
if (path == NULL) return n_arch_prefs; //no prefs found
if (!path[0]) return n_arch_prefs; //no prefs found
config_file = fopen(path, "r");
if(!config_file) return n_arch_prefs; //no prefs found