Commit e85cfe54 authored by Raúl Marín's avatar Raúl Marín

Address compiler warnings and add -Wextra to travis

Closes #4091
Closes https://github.com/postgis/postgis/pull/246


git-svn-id: http://svn.osgeo.org/postgis/trunk@16581 b70326c6-7e19-0410-871a-916f4a2858ee
parent 274dd419
Pipeline #22385963 passed with stage
in 30 minutes and 16 seconds
......@@ -2,7 +2,7 @@ env:
matrix:
- CFLAGS="-g -Og" MATRIX_EVAL="touch check-no-trailing-blanks"
- CFLAGS="-g -O2 -fstack-protector -Wformat -Werror=format-security" LDFLAGS="-Wl,-Bsymbolic-functions -Wl,-z,relro"
- CFLAGS="-g -O3 -mtune=generic -fno-omit-frame-pointer -Werror -Wall"
- CFLAGS="-g -O3 -mtune=generic -fno-omit-frame-pointer -Werror -Wall -Wextra -Wno-unused-parameter"
- CFLAGS="-g -O0 --coverage -fprofile-arcs -ftest-coverage" LDFLAGS="--coverage -fprofile-arcs -ftest-coverage" CONFIGURE_FLAGS="--enable-debug"
addons:
......@@ -47,7 +47,7 @@ compiler: gcc
dist: trusty
cache:
cache:
ccache: true
directories:
- /home/travis/deb
......
......@@ -690,7 +690,7 @@ static int load_lex(LEXICON *lex, char *tab)
int ntuples;
int total_tuples = 0;
lex_columns_t lex_columns = {seq: -1, word: -1, stdword: -1, token: -1};
lex_columns_t lex_columns = {.seq = -1, .word = -1, .stdword = -1, .token = -1};
int seq;
char *word;
......@@ -816,7 +816,7 @@ static int load_rules(RULES *rules, char *tab)
int ntuples;
int total_tuples = 0;
rules_columns_t rules_columns = {rule: -1};
rules_columns_t rules_columns = {.rule = -1};
char *rule;
......
......@@ -21,7 +21,7 @@ extern LWGEOM* lwgeom_sfcgal_noop( const LWGEOM* geom_in );
static void test_sfcgal_noop(void)
{
int i;
size_t i;
char *ewkt[] =
{
......
......@@ -35,7 +35,7 @@ static POINTARRAY * ptarray_chaikin(POINTARRAY *inpts, int preserve_endpoint, in
POINTARRAY *opts;
double *dlist;
double deltaval, quarter_delta, val1, val2;
int ndims = 2 + ptarray_has_z(inpts) + ptarray_has_m(inpts);
uint32_t ndims = 2 + ptarray_has_z(inpts) + ptarray_has_m(inpts);
int new_npoints = inpts->npoints * 2;
opts = ptarray_construct_empty(FLAGS_GET_Z(inpts->flags), FLAGS_GET_M(inpts->flags), new_npoints);
......@@ -125,7 +125,8 @@ static LWLINE* lwline_chaikin(const LWLINE *iline, int n_iterations)
static LWPOLY* lwpoly_chaikin(const LWPOLY *ipoly, int n_iterations, int preserve_endpoint)
{
uint32_t i, j;
uint32_t i;
int j;
POINTARRAY *pa, *pa_new;
LWPOLY *opoly = lwpoly_construct_empty(ipoly->srid, FLAGS_GET_Z(ipoly->flags), FLAGS_GET_M(ipoly->flags));
......
......@@ -360,7 +360,7 @@ uint8_t MULTITYPE[NUMTYPES] =
uint8_t lwtype_multitype(uint8_t type)
{
if (type > 15 || type < 0) return 0;
if (type > 15) return 0;
return MULTITYPE[type];
}
......
......@@ -56,7 +56,7 @@ static POINTARRAY* ptarray_filterm(POINTARRAY *pa,double min, double max, int re
//M-value will always be the last dimension
int m_pos = ndims-1;
int i, counter=0;
uint32_t i, counter=0;
for(i=0;i<pa->npoints;i++)
{
m_val = *((double*)pa->serialized_pointlist + i*ndims + m_pos);
......
......@@ -117,6 +117,8 @@ rect_leaf_node_intersects(RECT_NODE_LEAF *n1, RECT_NODE_LEAF *n2)
lwerror("%s: unsupported segment type", __func__);
break;
}
break;
}
case RECT_NODE_SEG_LINEAR:
......@@ -147,6 +149,8 @@ rect_leaf_node_intersects(RECT_NODE_LEAF *n1, RECT_NODE_LEAF *n2)
lwerror("%s: unsupported segment type", __func__);
break;
}
break;
}
case RECT_NODE_SEG_CIRCULAR:
{
......@@ -178,6 +182,8 @@ rect_leaf_node_intersects(RECT_NODE_LEAF *n1, RECT_NODE_LEAF *n2)
lwerror("%s: unsupported segment type", __func__);
break;
}
break;
}
default:
return LW_FALSE;
......@@ -587,7 +593,7 @@ rect_node_internal_new(const RECT_NODE *seed)
* spatially coherent structure.
*/
static RECT_NODE *
rect_nodes_merge(RECT_NODE ** nodes, int num_nodes)
rect_nodes_merge(RECT_NODE ** nodes, uint32_t num_nodes)
{
if (num_nodes < 1)
{
......@@ -596,7 +602,7 @@ rect_nodes_merge(RECT_NODE ** nodes, int num_nodes)
while (num_nodes > 1)
{
int i, k = 0;
uint32_t i, k = 0;
RECT_NODE *node = NULL;
for (i = 0; i < num_nodes; i++)
{
......@@ -740,7 +746,7 @@ rect_tree_from_lwpoly(const LWGEOM *lwgeom)
{
RECT_NODE **nodes;
RECT_NODE *tree;
int i, j = 0;
uint32_t i, j = 0;
const LWPOLY *lwpoly = (const LWPOLY*)lwgeom;
if (lwpoly->nrings < 1)
......@@ -767,7 +773,7 @@ rect_tree_from_lwcurvepoly(const LWGEOM *lwgeom)
{
RECT_NODE **nodes;
RECT_NODE *tree;
int i, j = 0;
uint32_t i, j = 0;
const LWCURVEPOLY *lwcol = (const LWCURVEPOLY*)lwgeom;
if (lwcol->nrings < 1)
......@@ -813,7 +819,7 @@ rect_tree_from_lwcollection(const LWGEOM *lwgeom)
{
RECT_NODE **nodes;
RECT_NODE *tree;
int i, j = 0;
uint32_t i, j = 0;
const LWCOLLECTION *lwcol = (const LWCOLLECTION*)lwgeom;
if (lwcol->ngeoms < 1)
......
......@@ -1126,6 +1126,7 @@ ShpLoaderOpenShape(SHPLOADERSTATE *state)
}
strncpy(name, utf8str, MAXFIELDNAMELEN);
name[MAXFIELDNAMELEN-1] = '\0';
free(utf8str);
}
......@@ -1161,7 +1162,12 @@ ShpLoaderOpenShape(SHPLOADERSTATE *state)
! strcmp(name, "primary") ||
! strcmp(name, "oid") || ! strcmp(name, "ctid"))
{
strncpy(name2 + 2, name, MAXFIELDNAMELEN - 2);
size_t len = strlen(name);
if (len > (MAXFIELDNAMELEN - 2))
len = MAXFIELDNAMELEN - 2;
strncpy(name2 + 2, name, len);
name2[MAXFIELDNAMELEN-1] = '\0';
name2[len + 2] = '\0';
name2[0] = '_';
name2[1] = '_';
strcpy(name, name2);
......@@ -1651,6 +1657,7 @@ ShpLoaderGenerateSQLRowStatement(SHPLOADERSTATE *state, int item, char **strreco
return SHPLOADERERR;
}
strncpy(val, utf8str, MAXVALUELEN);
val[MAXVALUELEN-1] = '\0';
free(utf8str);
}
......
......@@ -1532,7 +1532,7 @@ Datum isvalid(PG_FUNCTION_ARGS)
{
GSERIALIZED *geom1;
LWGEOM *lwgeom;
bool result;
char result;
GEOSGeom g1;
geom1 = PG_GETARG_GSERIALIZED_P(0);
......@@ -1715,7 +1715,7 @@ Datum overlaps(PG_FUNCTION_ARGS)
GSERIALIZED *geom1;
GSERIALIZED *geom2;
GEOSGeometry *g1, *g2;
bool result;
char result;
GBOX box1, box2;
geom1 = PG_GETARG_GSERIALIZED_P(0);
......@@ -1916,7 +1916,7 @@ Datum containsproperly(PG_FUNCTION_ARGS)
{
GSERIALIZED * geom1;
GSERIALIZED * geom2;
bool result;
char result;
GBOX box1, box2;
PrepGeomCache * prep_cache;
......@@ -2450,7 +2450,7 @@ Datum touches(PG_FUNCTION_ARGS)
GSERIALIZED *geom1;
GSERIALIZED *geom2;
GEOSGeometry *g1, *g2;
bool result;
char result;
GBOX box1, box2;
geom1 = PG_GETARG_GSERIALIZED_P(0);
......@@ -2510,7 +2510,7 @@ Datum disjoint(PG_FUNCTION_ARGS)
GSERIALIZED *geom1;
GSERIALIZED *geom2;
GEOSGeometry *g1, *g2;
bool result;
char result;
GBOX box1, box2;
geom1 = PG_GETARG_GSERIALIZED_P(0);
......@@ -2570,7 +2570,7 @@ Datum relate_pattern(PG_FUNCTION_ARGS)
GSERIALIZED *geom1;
GSERIALIZED *geom2;
char *patt;
bool result;
char result;
GEOSGeometry *g1, *g2;
size_t i;
......@@ -2688,7 +2688,7 @@ Datum ST_Equals(PG_FUNCTION_ARGS)
GSERIALIZED *geom1;
GSERIALIZED *geom2;
GEOSGeometry *g1, *g2;
bool result;
char result;
GBOX box1, box2;
geom1 = PG_GETARG_GSERIALIZED_P(0);
......
......@@ -119,7 +119,7 @@ Datum ST_ClusterDBSCAN(PG_FUNCTION_ARGS)
uf = UF_create(ngeoms);
for (i = 0; i < ngeoms; i++)
{
geoms[i] = read_lwgeom_from_partition(win_obj, i, &(context->cluster_assignments[i].is_null));
geoms[i] = read_lwgeom_from_partition(win_obj, i, (bool*)&(context->cluster_assignments[i].is_null));
if (!geoms[i]) {
/* TODO release memory ? */
......
......@@ -263,6 +263,7 @@ trim(const char *input) {
char *rtn;
char *ptr;
uint32_t offset = 0;
size_t len = 0;
if (!input)
return NULL;
......@@ -278,13 +279,13 @@ trim(const char *input) {
while (isspace(*--ptr))
offset++;
rtn = rtalloc(sizeof(char) * (strlen(input) - offset + 1));
len = strlen(input) - offset + 1;
rtn = rtalloc(sizeof(char) * len);
if (NULL == rtn) {
rterror(_("trim: Not enough memory"));
return NULL;
}
strncpy(rtn, input, strlen(input) - offset);
rtn[strlen(input) - offset] = '\0';
strncpy(rtn, input, len);
return rtn;
}
......@@ -294,6 +295,7 @@ chartrim(const char *input, char *remove) {
char *rtn = NULL;
char *ptr = NULL;
uint32_t offset = 0;
size_t len = 0;
if (!input)
return NULL;
......@@ -309,12 +311,13 @@ chartrim(const char *input, char *remove) {
while (strchr(remove, *--ptr) != NULL)
offset++;
rtn = rtalloc(sizeof(char) * (strlen(input) - offset + 1));
len = strlen(input) - offset + 1;
rtn = rtalloc(sizeof(char) * len);
if (NULL == rtn) {
rterror(_("chartrim: Not enough memory"));
return NULL;
}
strncpy(rtn, input, strlen(input) - offset);
strncpy(rtn, input, len);
rtn[strlen(input) - offset] = '\0';
return rtn;
......@@ -2475,13 +2478,14 @@ main(int argc, char **argv) {
}
/* raster column name */
else if (CSEQUAL(argv[argit], "-f") && argit < argc - 1) {
config->raster_column = rtalloc(sizeof(char) * (strlen(argv[++argit]) + 1));
const size_t len = (strlen(argv[++argit]) + 1);
config->raster_column = rtalloc(sizeof(char) * len);
if (config->raster_column == NULL) {
rterror(_("Could not allocate memory for storing raster column name"));
rtdealloc_config(config);
exit(1);
}
strncpy(config->raster_column, argv[argit], strlen(argv[argit]) + 1);
strncpy(config->raster_column, argv[argit], len);
}
/* filename column */
else if (CSEQUAL(argv[argit], "-F")) {
......@@ -2489,13 +2493,14 @@ main(int argc, char **argv) {
}
/* filename column name */
else if (CSEQUAL(argv[argit], "-n") && argit < argc - 1) {
config->file_column_name = rtalloc(sizeof(char) * (strlen(argv[++argit]) + 1));
const size_t len = (strlen(argv[++argit]) + 1);
config->file_column_name = rtalloc(sizeof(char) * len);
if (config->file_column_name == NULL) {
rterror(_("Could not allocate memory for storing filename column name"));
rtdealloc_config(config);
exit(1);
}
strncpy(config->file_column_name, argv[argit], strlen(argv[argit]) + 1);
strncpy(config->file_column_name, argv[argit], len);
config->file_column = 1;
}
/* overview factors */
......@@ -2558,23 +2563,25 @@ main(int argc, char **argv) {
}
/* tablespace of new table */
else if (CSEQUAL(argv[argit], "-T") && argit < argc - 1) {
config->tablespace = rtalloc(sizeof(char) * (strlen(argv[++argit]) + 1));
const size_t len = (strlen(argv[++argit]) + 1);
config->tablespace = rtalloc(len);
if (config->tablespace == NULL) {
rterror(_("Could not allocate memory for storing tablespace of new table"));
rtdealloc_config(config);
exit(1);
}
strncpy(config->tablespace, argv[argit], strlen(argv[argit]) + 1);
strncpy(config->tablespace, argv[argit], len);
}
/* tablespace of new index */
else if (CSEQUAL(argv[argit], "-X") && argit < argc - 1) {
config->idx_tablespace = rtalloc(sizeof(char) * (strlen(argv[++argit]) + 1));
const size_t len = (strlen(argv[++argit]) + 1);
config->idx_tablespace = rtalloc(len);
if (config->idx_tablespace == NULL) {
rterror(_("Could not allocate memory for storing tablespace of new indices"));
rtdealloc_config(config);
exit(1);
}
strncpy(config->idx_tablespace, argv[argit], strlen(argv[argit]) + 1);
strncpy(config->idx_tablespace, argv[argit], len);
}
/* nodata value */
else if (CSEQUAL(argv[argit], "-N") && argit < argc - 1) {
......@@ -2632,6 +2639,7 @@ main(int argc, char **argv) {
exit(0);
}
else {
size_t len;
config->rt_file_count++;
config->rt_file = (char **) rtrealloc(config->rt_file, sizeof(char *) * config->rt_file_count);
if (config->rt_file == NULL) {
......@@ -2640,13 +2648,14 @@ main(int argc, char **argv) {
exit(1);
}
config->rt_file[config->rt_file_count - 1] = rtalloc(sizeof(char) * (strlen(argv[argit]) + 1));
len = strlen(argv[argit]) + 1;
config->rt_file[config->rt_file_count - 1] = rtalloc(sizeof(char) * len);
if (config->rt_file[config->rt_file_count - 1] == NULL) {
rterror(_("Could not allocate memory for storing raster filename"));
rtdealloc_config(config);
exit(1);
}
strncpy(config->rt_file[config->rt_file_count - 1], argv[argit], strlen(argv[argit]) + 1);
strncpy(config->rt_file[config->rt_file_count - 1], argv[argit], len);
}
}
......@@ -2699,13 +2708,14 @@ main(int argc, char **argv) {
}
/* table */
else {
config->table = rtalloc(sizeof(char) * strlen(config->rt_file[config->rt_file_count - 1]) + 1);
const size_t len = strlen(config->rt_file[config->rt_file_count - 1]) + 1;
config->table = rtalloc(sizeof(char) * len);
if (config->table == NULL) {
rterror(_("Could not allocate memory for storing table name"));
rtdealloc_config(config);
exit(1);
}
strncpy(config->table, config->rt_file[config->rt_file_count - 1], strlen(config->rt_file[config->rt_file_count - 1]) + 1);
strncpy(config->table, config->rt_file[config->rt_file_count - 1], len);
}
rtdealloc(config->rt_file[--(config->rt_file_count)]);
......
......@@ -1062,6 +1062,7 @@ rt_raster_iterator(
*/
case ET_FIRST:
i = 0;
/* FALLTHROUGH */
case ET_SECOND:
if (i < 0) {
if (itrcount < 2)
......@@ -1069,6 +1070,7 @@ rt_raster_iterator(
else
i = 1;
}
/* FALLTHROUGH */
case ET_LAST:
if (i < 0) i = itrcount - 1;
......@@ -1102,6 +1104,7 @@ rt_raster_iterator(
*rtnraster = rtnrast;
return ES_NONE;
}
/* FALLTHROUGH */
/* copy the custom extent raster */
case ET_CUSTOM:
rtnrast = rtalloc(sizeof(struct rt_raster_t));
......
......@@ -3522,6 +3522,7 @@ rt_raster_from_two_rasters(
i = 0;
_offset[0][0] = 0.;
_offset[0][1] = 0.;
/* FALLTHROUGH */
case ET_LAST:
case ET_SECOND:
if (i < 0) {
......
......@@ -285,8 +285,10 @@ rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode) {
const char* pszAuthorityCode = OSRGetAuthorityCode(hSRS, NULL);
if (pszAuthorityName != NULL && pszAuthorityCode != NULL) {
*authname = rtalloc(sizeof(char) * (strlen(pszAuthorityName) + 1));
*authcode = rtalloc(sizeof(char) * (strlen(pszAuthorityCode) + 1));
size_t authorityName_len = strlen(pszAuthorityName) +1;
size_t authorityCode_len = strlen(pszAuthorityCode) + 1;
*authname = rtalloc(sizeof(char) * authorityName_len);
*authcode = rtalloc(sizeof(char) * authorityCode_len);
if (*authname == NULL || *authcode == NULL) {
rterror("rt_util_gdal_sr_auth_info: Could not allocate memory for auth name and code");
......@@ -296,8 +298,8 @@ rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode) {
return ES_ERROR;
}
strncpy(*authname, pszAuthorityName, strlen(pszAuthorityName) + 1);
strncpy(*authcode, pszAuthorityCode, strlen(pszAuthorityCode) + 1);
strncpy(*authname, pszAuthorityName, authorityName_len);
strncpy(*authcode, pszAuthorityCode, authorityCode_len);
}
}
......
......@@ -46,7 +46,7 @@
#include "rtpostgis.h"
extern char enable_outdb_rasters;
extern bool enable_outdb_rasters;
/* Get all the properties of a raster band */
Datum RASTER_getBandPixelType(PG_FUNCTION_ARGS);
......
......@@ -756,14 +756,14 @@ Datum RASTER_asRaster(PG_FUNCTION_ARGS)
char *pixeltype = NULL;
rt_pixtype pixtype = PT_END;
rt_pixtype *pixtypes = NULL;
int pixtypes_len = 0;
uint32_t pixtypes_len = 0;
double *values = NULL;
int values_len = 0;
uint32_t values_len = 0;
uint8_t *hasnodatas = NULL;
double *nodatavals = NULL;
int nodatavals_len = 0;
uint32_t nodatavals_len = 0;
double ulw[2] = {0};
double *ul_xw = NULL;
......
......@@ -1137,7 +1137,7 @@ static int rtpg_nmapalgebraexpr_callback(
/* run prepared plan */
if (plan != NULL) {
Datum values[12];
bool nulls[12];
char nulls[12];
int err = 0;
TupleDesc tupdesc;
......@@ -1150,7 +1150,7 @@ static int rtpg_nmapalgebraexpr_callback(
/* init values and nulls */
memset(values, (Datum) NULL, sizeof(Datum) * callback->kw.count);
memset(nulls, FALSE, sizeof(bool) * callback->kw.count);
memset(nulls, FALSE, sizeof(char) * callback->kw.count);
if (callback->expr[id].spi_argcount) {
int idx = 0;
......@@ -6122,7 +6122,7 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS)
uint8_t argpos[3][8] = {{0}};
char *argkw[] = {"[rast1.x]", "[rast1.y]", "[rast1.val]", "[rast1]", "[rast2.x]", "[rast2.y]", "[rast2.val]", "[rast2]"};
Datum values[argkwcount];
bool nulls[argkwcount];
char nulls[argkwcount];
TupleDesc tupdesc;
SPITupleTable *tuptable = NULL;
HeapTuple tuple;
......@@ -7009,7 +7009,7 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS)
/* reset values to (Datum) NULL */
memset(values, (Datum) NULL, sizeof(Datum) * argkwcount);
/* reset nulls to FALSE */
memset(nulls, FALSE, sizeof(bool) * argkwcount);
memset(nulls, FALSE, sizeof(char) * argkwcount);
/* set values and nulls */
for (j = 0; j < argkwcount; j++) {
......
......@@ -246,7 +246,7 @@ rt_pg_debug(const char *fmt, va_list ap)
static char *gdal_datapath = NULL;
extern char *gdal_enabled_drivers;
extern char enable_outdb_rasters;
extern bool enable_outdb_rasters;
/* ---------------------------------------------------------------- */
/* Useful variables */
......
......@@ -292,8 +292,8 @@ static void test_band_get_pixel_of_value() {
rt_band band;
uint32_t x, y;
int rtn;
const int maxX = 10;
const int maxY = 10;
uint32_t maxX = 10;
uint32_t maxY = 10;
rt_pixel pixels = NULL;
double search0[1] = {0};
......
......@@ -513,8 +513,8 @@ static void test_gdal_to_raster() {
CU_ASSERT(gddrv != NULL);
CU_ASSERT_EQUAL(destroy, 0);
CU_ASSERT(gdds != NULL);
CU_ASSERT_EQUAL(GDALGetRasterXSize(gdds), width);
CU_ASSERT_EQUAL(GDALGetRasterYSize(gdds), height);
CU_ASSERT_EQUAL((uint32_t)GDALGetRasterXSize(gdds), width);
CU_ASSERT_EQUAL((uint32_t)GDALGetRasterYSize(gdds), height);
rast = rt_raster_from_gdal_dataset(gdds);
CU_ASSERT(rast != NULL);
......@@ -559,8 +559,8 @@ static void test_gdal_to_raster() {
CU_ASSERT(gddrv != NULL);
CU_ASSERT_EQUAL(destroy, 0);
CU_ASSERT(gdds != NULL);
CU_ASSERT_EQUAL(GDALGetRasterXSize(gdds), width);
CU_ASSERT_EQUAL(GDALGetRasterYSize(gdds), height);
CU_ASSERT_EQUAL((uint32_t)GDALGetRasterXSize(gdds), width);
CU_ASSERT_EQUAL((uint32_t)GDALGetRasterYSize(gdds), height);
rast = rt_raster_from_gdal_dataset(gdds);
CU_ASSERT(rast != NULL);
......
......@@ -526,8 +526,8 @@ static void test_raster_pixel_as_polygon() {
rt_raster rast;
rt_band band;
uint32_t x, y;
const int maxX = 10;
const int maxY = 10;
const uint32_t maxX = 10;
const uint32_t maxY = 10;
LWPOLY *poly = NULL;
rast = rt_raster_new(maxX, maxY);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment