mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-10-29 06:27:44 +00:00
Pointer safety, code cleaning
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "volk_gnsssdr/volk_gnsssdr_malloc.h"
|
#include "volk_gnsssdr/volk_gnsssdr_malloc.h"
|
||||||
#include <pthread.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -27,29 +27,6 @@
|
|||||||
* see: http://linux.die.net/man/3/aligned_alloc
|
* 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
|
// Otherwise, test if we are a POSIX or X/Open system
|
||||||
// This only has a restriction that alignment be a power of 2and a
|
// This only has a restriction that alignment be a power of 2and a
|
||||||
// multiple of sizeof(void *).
|
// multiple of sizeof(void *).
|
||||||
@@ -59,11 +36,11 @@ void *volk_gnsssdr_malloc(size_t size, size_t alignment)
|
|||||||
{
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
|
||||||
// quoting posix_memalign() man page:
|
// quoting posix_memalign() man page:
|
||||||
// "alignment must be a power of two and a multiple of sizeof(void *)"
|
// "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)
|
// volk_get_alignment() could return 1 for some machines (e.g. generic_orc)
|
||||||
if (alignment == 1)
|
if (alignment == 1)
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
|
|
||||||
int err = posix_memalign(&ptr, alignment, size);
|
int err = posix_memalign(&ptr, alignment, size);
|
||||||
if(err == 0)
|
if(err == 0)
|
||||||
|
|||||||
@@ -21,19 +21,17 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <volk_gnsssdr/volk_gnsssdr_prefs.h>
|
#include <volk_gnsssdr/volk_gnsssdr_prefs.h>
|
||||||
|
|
||||||
//#if defined(_WIN32)
|
|
||||||
//#include <Windows.h>
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
void volk_gnsssdr_get_config_path(char *path)
|
void volk_gnsssdr_get_config_path(char *path)
|
||||||
{
|
{
|
||||||
|
if (!path) return;
|
||||||
const char *suffix = "/.volk_gnsssdr/volk_gnsssdr_config";
|
const char *suffix = "/.volk_gnsssdr/volk_gnsssdr_config";
|
||||||
char *home = NULL;
|
char *home = NULL;
|
||||||
if (home == NULL) home = getenv("HOME");
|
if (home == NULL) home = getenv("HOME");
|
||||||
if (home == NULL) home = getenv("APPDATA");
|
if (home == NULL) home = getenv("APPDATA");
|
||||||
if (home == NULL)
|
if (home == NULL)
|
||||||
{
|
{
|
||||||
path = NULL;
|
path[0] = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
strcpy(path, home);
|
strcpy(path, home);
|
||||||
@@ -49,7 +47,7 @@ size_t volk_gnsssdr_load_preferences(volk_gnsssdr_arch_pref_t **prefs_res)
|
|||||||
|
|
||||||
//get the config path
|
//get the config path
|
||||||
volk_gnsssdr_get_config_path(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");
|
config_file = fopen(path, "r");
|
||||||
if(!config_file) return n_arch_prefs; //no prefs found
|
if(!config_file) return n_arch_prefs; //no prefs found
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user