Fix const correctness warnings

This commit is contained in:
Martijn Otto 2018-02-20 18:18:43 +01:00
parent 0d78599a57
commit 021c54308a
7 changed files with 28 additions and 27 deletions

View file

@ -74,7 +74,7 @@ typedef struct st_r3_buffer_prototype_t r3_buffer_prototype_t;
* buffer structure compatible with iovec
*/
typedef struct st_r3_iovec_t {
char *base;
const char *base;
unsigned int len;
} r3_iovec_t;

View file

@ -13,11 +13,11 @@ extern "C" {
char * r3_slug_compile(const char * str, unsigned int len);
char * r3_slug_find_pattern(const char *s1, unsigned int str_len, unsigned int *len);
const char * r3_slug_find_pattern(const char *s1, unsigned int str_len, unsigned int *len);
char * r3_slug_find_name(const char *s1, unsigned int str_len, unsigned int *len);
const char * r3_slug_find_name(const char *s1, unsigned int str_len, unsigned int *len);
char * r3_slug_find_placeholder(const char *s1, unsigned int str_len, unsigned int *len);
const char * r3_slug_find_placeholder(const char *s1, unsigned int str_len, unsigned int *len);
int r3_slug_count(const char * needle, int len, char **errstr);

View file

@ -26,7 +26,7 @@ bool str_array_slugs_full(const str_array * l);
// bool str_array_append_slug(str_array * l, char * slug);
bool str_array_append(str_array * l, char * token, unsigned int len);
bool str_array_append(str_array * l, const char * token, unsigned int len);
void str_array_free(str_array *l);

View file

@ -64,7 +64,7 @@ R3Node * r3_edge_branch(R3Edge *e, int dl) {
R3Edge * new_edge;
// the rest string
char * s1 = e->pattern.base + dl;
const char * s1 = e->pattern.base + dl;
int s1_len = e->pattern.len - dl;
// the suffix edge of the leaf

View file

@ -28,8 +28,8 @@
// String value as the index http://judy.sourceforge.net/doc/JudySL_3x.htm
static int strndiff(char * d1, char * d2, unsigned int n) {
char * o = d1;
static int strndiff(const char * d1, const char * d2, unsigned int n) {
const char * o = d1;
while ( *d1 == *d2 && n-- > 0 ) {
d1++;
d2++;
@ -505,7 +505,7 @@ void r3_route_free(R3Route * route) {
// return route->slugs != NULL;
// }
static r3_iovec_t* router_append_slug(R3Route * route, char * slug, unsigned int len) {
static r3_iovec_t* router_append_slug(R3Route * route, const char * slug, unsigned int len) {
r3_iovec_t *temp;
r3_vector_reserve(NULL, &route->slugs, route->slugs.size + 1);
temp = route->slugs.entries + route->slugs.size++;
@ -515,10 +515,10 @@ static r3_iovec_t* router_append_slug(R3Route * route, char * slug, unsigned int
}
static void get_slugs(R3Route * route, const char * path, int path_len) {
char *plh = (char*)path;
const char *plh = path;
unsigned int l, namel;
l = 0;
char *name;
const char *name;
while (plh < (path + path_len)) {
plh = r3_slug_find_placeholder(plh+l, path_len, &l);
if (!plh) break;
@ -681,7 +681,7 @@ R3Node * r3_tree_insert_pathl_ex(R3Node *tree, const char *path, unsigned int pa
info("slug_cnt: %d\n",slug_cnt);
if ( slug_cnt > 1 ) {
unsigned int slug_len;
char *p = r3_slug_find_placeholder(path, path_len, &slug_len);
const char *p = r3_slug_find_placeholder(path, path_len, &slug_len);
#ifdef DEBUG
assert(p);
@ -707,9 +707,9 @@ R3Node * r3_tree_insert_pathl_ex(R3Node *tree, const char *path, unsigned int pa
if (slug_cnt == 1) {
// there is one slug, let's see if it's optimiz-able by opcode
unsigned int slug_len = 0;
char *slug_p = r3_slug_find_placeholder(path, path_len, &slug_len);
const char *slug_p = r3_slug_find_placeholder(path, path_len, &slug_len);
unsigned int slug_pattern_len = 0;
char *slug_pattern = r3_slug_find_pattern(slug_p, slug_len, &slug_pattern_len);
const char *slug_pattern = r3_slug_find_pattern(slug_p, slug_len, &slug_pattern_len);
int opcode = 0;
// if there is a pattern defined.

View file

@ -15,7 +15,7 @@
#include "slug.h"
#include "zmalloc.h"
static char * strnchr(const char* str, unsigned int len, int ch) {
static const char * strnchr(const char* str, unsigned int len, int ch) {
for (unsigned int i = 0; i < len; i++) {
if (str[i] == ch) return str + i;
}
@ -86,9 +86,9 @@ char * r3_inside_slug(const char * needle, int needle_len, char *offset, char **
return NULL;
}
char * r3_slug_find_placeholder(const char *s1, unsigned int str_len, unsigned int *len) {
char *c;
char *s2;
const char * r3_slug_find_placeholder(const char *s1, unsigned int str_len, unsigned int *len) {
const char *c;
const char *s2;
int cnt = 0;
if (c = strnchr(s1, str_len, '{')) {
// find closing '}'
@ -119,9 +119,9 @@ char * r3_slug_find_placeholder(const char *s1, unsigned int str_len, unsigned i
/**
* given a slug string, duplicate the pattern string of the slug
*/
char * r3_slug_find_pattern(const char *s1, unsigned int str_len, unsigned int *len) {
char *c;
char *s2;
const char * r3_slug_find_pattern(const char *s1, unsigned int str_len, unsigned int *len) {
const char *c;
const char *s2;
unsigned int cnt = 1;
if ( (c = strnchr(s1, str_len, ':')) ) {
c++;
@ -152,9 +152,9 @@ char * r3_slug_find_pattern(const char *s1, unsigned int str_len, unsigned int *
/**
* given a slug string, duplicate the parameter name string of the slug
*/
char * r3_slug_find_name(const char *s1, unsigned int str_len, unsigned int *len) {
char * c;
char * s2;
const char * r3_slug_find_name(const char *s1, unsigned int str_len, unsigned int *len) {
const char * c;
const char * s2;
int cnt = 0;
unsigned int plholder;
if (c = r3_slug_find_placeholder(s1, str_len, &plholder)) {
@ -177,8 +177,9 @@ char * r3_slug_find_name(const char *s1, unsigned int str_len, unsigned int *len
*/
char * r3_slug_compile(const char * str, unsigned int len)
{
char *s1 = NULL, *o = NULL;
char *pat = NULL;
const char *s1 = NULL;
char *o = NULL;
const char *pat = NULL;
char sep = '/';

View file

@ -20,7 +20,7 @@ void str_array_free(str_array *l) {
free(l->tokens.entries);
}
bool str_array_append(str_array * l, char * token, unsigned int len) {
bool str_array_append(str_array * l, const char * token, unsigned int len) {
R3_VECTOR(r3_iovec_t) *tks = &l->tokens;
r3_vector_reserve(NULL, tks, tks->size + 1);
r3_iovec_t *temp = tks->entries + tks->size++;