re-undo splint warning fizes

This commit is contained in:
Enno Rehling 2019-01-24 14:24:18 +01:00
parent 6f61ca87a7
commit 6f771ace3e
5 changed files with 49 additions and 59 deletions

View File

@ -67,7 +67,7 @@ void new_potiontype(item_type * itype, int level)
potion_type *ptype;
ptype = (potion_type *)calloc(1, sizeof(potion_type));
assert(ptype != NULL);
assert(ptype);
itype->flags |= ITF_POTION;
ptype->itype = itype;
ptype->level = level;
@ -120,7 +120,7 @@ void herbsearch(unit * u, int max_take)
if (herbsfound) {
produceexp(u, SK_HERBALISM, u->number);
(void)i_change(&u->items, whichherb, herbsfound);
i_change(&u->items, whichherb, herbsfound);
ADDMSG(&u->faction->msgs, msg_message("herbfound",
"unit region amount herb", u, r, herbsfound, whichherb->rtype));
}

View File

@ -27,7 +27,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <spells/regioncurse.h>
/* kernel includes */
#include "curse.h"
#include "item.h"
#include "unit.h"
@ -96,7 +95,7 @@ static int bt_changes = 1;
bool bt_changed(int *cache)
{
assert(cache != NULL);
assert(cache);
if (*cache != bt_changes) {
*cache = bt_changes;
return true;
@ -109,7 +108,7 @@ static void bt_register(building_type * btype)
size_t len;
char data[64];
(void)selist_push(&buildingtypes, (void *)btype);
selist_push(&buildingtypes, (void *)btype);
len = cb_new_kv(btype->_name, strlen(btype->_name), &btype, sizeof(btype), data);
assert(len <= sizeof(data));
cb_insert(&cb_bldgtypes, data, len);
@ -130,25 +129,20 @@ static void free_buildingtype(void *ptr) {
free(btype);
}
static building_type *bt_create(const char *name) {
building_type *btype = (building_type *)calloc(1, sizeof(building_type));
if (!btype) abort();
btype->_name = str_strdup(name);
btype->flags = BTF_DEFAULT;
btype->auraregen = 1.0;
btype->maxsize = -1;
btype->capacity = 1;
btype->maxcapacity = -1;
return btype;
}
building_type *bt_get_or_create(const char *name)
{
assert(name && name[0]);
if (name != NULL) {
building_type *btype = bt_find_i(name);
if (btype == NULL) {
btype = bt_create(name);
btype = (building_type *)calloc(1, sizeof(building_type));
if (!btype) abort();
btype->_name = str_strdup(name);
btype->flags = BTF_DEFAULT;
btype->auraregen = 1.0;
btype->maxsize = -1;
btype->capacity = 1;
btype->maxcapacity = -1;
bt_register(btype);
}
return btype;
@ -180,7 +174,7 @@ attrib_type at_building_generic_type = {
/* TECH DEBT: simplest thing that works for E3 dwarf/halfling faction rules */
static int adjust_size(const building *b, int bsize) {
assert(b != NULL);
assert(b);
if (config_get_int("rules.dwarf_castles", 0)
&& strcmp(b->type->_name, "castle") == 0) {
unit *u = building_owner(b);
@ -196,7 +190,7 @@ static int adjust_size(const building *b, int bsize) {
*/
const char *buildingtype(const building_type * btype, const building * b, int bsize)
{
assert(btype != NULL);
assert(btype);
if (b && b->attribs) {
if (is_building_type(btype, "generic")) {
@ -417,7 +411,7 @@ building *new_building(const struct building_type * btype, region * r,
bname = parameters[P_GEBAEUDE];
}
}
assert(bname != NULL);
assert(bname);
snprintf(buffer, sizeof(buffer), "%s %s", bname, itoa36(b->no));
b->name = str_strdup(bname);
return b;
@ -435,7 +429,7 @@ void remove_building(building ** blist, building * b)
static const struct building_type *bt_caravan, *bt_dam, *bt_tunnel;
static int btypes;
assert(bfindhash(b->no) != NULL);
assert(bfindhash(b->no));
if (bt_changed(&btypes)) {
bt_caravan = bt_find("caravan");
@ -696,7 +690,7 @@ bool in_safe_building(unit *u1, unit *u2) {
}
bool is_building_type(const struct building_type *btype, const char *name) {
assert(btype != NULL);
assert(btype);
return name && strcmp(btype->_name, name)==0;
}
@ -832,7 +826,7 @@ int cmp_wage(const struct building *b, const building * a)
}
int building_taxes(const building *b) {
assert(b != NULL);
assert(b);
return b->type->taxes;
}

View File

@ -1,4 +1,4 @@
#pragma once
#pragma once
#ifndef _GAMEDATA_H
#define _GAMEDATA_H

View File

@ -55,7 +55,7 @@ extern "C" {
struct mlist ** merge_messages(message_list *ml, message_list *append);
void split_messages(message_list *ml, struct mlist **split);
#define ADDMSG(msgs, mcreate) { message * mx = mcreate; if (mx) { (void)add_message(msgs, mx); msg_release(mx); } }
#define ADDMSG(msgs, mcreate) { message * mx = mcreate; if (mx) { add_message(msgs, mx); msg_release(mx); } }
void syntax_error(const struct unit *u, struct order *ord);
void cmistake(const struct unit *u, struct order *ord, int mno, int mtype);

View File

@ -64,8 +64,8 @@ size_t str_strlcpy(char *dst, const char *src, size_t len)
register const char *s = src;
register size_t n = len;
assert(src != NULL);
assert(dst != NULL);
assert(src);
assert(dst);
/* Copy as many bytes as will fit */
if (n != 0 && --n != 0) {
do {
@ -82,7 +82,7 @@ size_t str_strlcpy(char *dst, const char *src, size_t len)
return (s - src) + strlen(s); /* count does not include NUL */
}
return (size_t)(s - src - 1); /* count does not include NUL */
return (s - src - 1); /* count does not include NUL */
#endif
}
@ -99,7 +99,7 @@ size_t str_strlcat(char *dst, const char *src, size_t len)
/* Find the end of dst and adjust bytes left but don't go past end */
while (*d != '\0' && n-- != 0)
d++;
dlen = (size_t)(d - dst);
dlen = d - dst;
n = len - dlen;
if (n == 0)
@ -143,7 +143,7 @@ void str_replace(char *buffer, size_t size, const char *tmpl, const char *var,
char *p = strstr(tmpl, var);
size_t len;
if (p) {
len = (size_t)(p - tmpl);
len = p - tmpl;
}
else {
len = strlen(tmpl);
@ -170,7 +170,7 @@ void str_replace(char *buffer, size_t size, const char *tmpl, const char *var,
int str_hash(const char *s)
{
int key = 0;
assert(s != NULL);
assert(s);
while (*s) {
key = key * 37 + *s++;
}
@ -200,19 +200,17 @@ unsigned int wang_hash(unsigned int a)
}
char *str_strdup(const char *s) {
if (s != NULL) {
if (s == NULL) return NULL;
#ifdef HAVE_STRDUP
return strdup(s);
return strdup(s);
#elif defined(_MSC_VER)
return _strdup(s);
return _strdup(s);
#else
size_t len = strlen(s);
char *dup = malloc(len+1);
memcpy(dup, s, len+1);
return dup;
size_t len = strlen(s);
char *dup = malloc(len+1);
memcpy(dup, s, len+1);
return dup;
#endif
}
return NULL;
}
void sbs_printf(struct sbstring *sbs, const char *format, ...)
@ -220,18 +218,16 @@ void sbs_printf(struct sbstring *sbs, const char *format, ...)
size_t size = sbs->size - (sbs->end - sbs->begin);
if (size > 0) {
int bytes;
va_list argp;
va_start(argp, format);
bytes = vsnprintf(sbs->end, size, format, argp);
int bytes = vsnprintf(sbs->end, size, format, argp);
if (bytes > 0) {
size_t len = (size_t)bytes;
if (len >= size) {
len = size - 1;
if ((size_t)bytes >= size) {
bytes = size - 1;
/* terminate truncated output */
sbs->end[len] = '\0';
sbs->end[bytes] = '\0';
}
sbs->end += len;
sbs->end += bytes;
}
va_end(argp);
}
@ -239,7 +235,7 @@ void sbs_printf(struct sbstring *sbs, const char *format, ...)
void sbs_init(struct sbstring *sbs, char *buffer, size_t size)
{
assert(sbs != NULL);
assert(sbs);
assert(size > 0);
sbs->begin = buffer;
sbs->size = size;
@ -250,7 +246,7 @@ void sbs_init(struct sbstring *sbs, char *buffer, size_t size)
void sbs_adopt(struct sbstring *sbs, char *buffer, size_t size)
{
size_t len = strlen(buffer);
assert(sbs != NULL);
assert(sbs);
assert(size > len);
sbs->begin = buffer;
sbs->size = size;
@ -260,7 +256,7 @@ void sbs_adopt(struct sbstring *sbs, char *buffer, size_t size)
void sbs_strncat(struct sbstring *sbs, const char *str, size_t size)
{
size_t len;
assert(sbs != NULL);
assert(sbs);
len = sbs->size - (sbs->end - sbs->begin) - 1;
if (len < size) {
size = len;
@ -273,21 +269,21 @@ void sbs_strncat(struct sbstring *sbs, const char *str, size_t size)
void sbs_strcat(struct sbstring *sbs, const char *str)
{
size_t len;
assert(sbs != NULL);
assert(sbs);
len = sbs->size - (sbs->end - sbs->begin);
(void)str_strlcpy(sbs->end, str, len);
str_strlcpy(sbs->end, str, len);
sbs->end += strlen(sbs->end);
assert(sbs->begin + sbs->size >= sbs->end);
}
void sbs_substr(sbstring *sbs, ptrdiff_t pos, size_t len)
{
if (sbs->begin + pos > sbs->end) {
if (pos > sbs->end - sbs->begin) {
/* starting past end of string, do nothing */
sbs->end = sbs->begin;
}
if (pos >= 0) {
size_t sz = sbs->end - sbs->begin - pos;
size_t sz = sbs->end - (sbs->begin + pos);
if (len > sz) len = sz;
if (len - pos > 0) {
memmove(sbs->begin, sbs->begin + pos, len);
@ -303,14 +299,14 @@ void sbs_substr(sbstring *sbs, ptrdiff_t pos, size_t len)
size_t sbs_length(const struct sbstring *sbs)
{
assert(sbs->begin + sbs->size >= sbs->end);
return (size_t)(sbs->end - sbs->begin);
return sbs->end - sbs->begin;
}
char *str_unescape(char *str) {
char *read = str, *write = str;
while (*read) {
char * pos = strchr(read, '\\');
if (pos > read) {
if (pos >= read) {
size_t len = (size_t)(pos - read);
memmove(write, read, len);
write += len;
@ -352,8 +348,8 @@ const char *str_escape_ex(const char *str, char *buffer, size_t size, const char
while (slen > 0 && size > 1 && *read) {
const char *pos = strpbrk(read, chars);
size_t len = size;
if (pos > read) {
len = (size_t)(pos - read);
if (pos >= read) {
len = pos - read;
}
if (len < size) {
unsigned char ch = *(const unsigned char *)pos;