forked from github/server
re-undo splint warning fizes
This commit is contained in:
parent
6f61ca87a7
commit
6f771ace3e
5 changed files with 49 additions and 59 deletions
|
@ -67,7 +67,7 @@ void new_potiontype(item_type * itype, int level)
|
||||||
potion_type *ptype;
|
potion_type *ptype;
|
||||||
|
|
||||||
ptype = (potion_type *)calloc(1, sizeof(potion_type));
|
ptype = (potion_type *)calloc(1, sizeof(potion_type));
|
||||||
assert(ptype != NULL);
|
assert(ptype);
|
||||||
itype->flags |= ITF_POTION;
|
itype->flags |= ITF_POTION;
|
||||||
ptype->itype = itype;
|
ptype->itype = itype;
|
||||||
ptype->level = level;
|
ptype->level = level;
|
||||||
|
@ -120,7 +120,7 @@ void herbsearch(unit * u, int max_take)
|
||||||
|
|
||||||
if (herbsfound) {
|
if (herbsfound) {
|
||||||
produceexp(u, SK_HERBALISM, u->number);
|
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",
|
ADDMSG(&u->faction->msgs, msg_message("herbfound",
|
||||||
"unit region amount herb", u, r, herbsfound, whichherb->rtype));
|
"unit region amount herb", u, r, herbsfound, whichherb->rtype));
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <spells/regioncurse.h>
|
#include <spells/regioncurse.h>
|
||||||
|
|
||||||
/* kernel includes */
|
/* kernel includes */
|
||||||
|
|
||||||
#include "curse.h"
|
#include "curse.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
|
@ -96,7 +95,7 @@ static int bt_changes = 1;
|
||||||
|
|
||||||
bool bt_changed(int *cache)
|
bool bt_changed(int *cache)
|
||||||
{
|
{
|
||||||
assert(cache != NULL);
|
assert(cache);
|
||||||
if (*cache != bt_changes) {
|
if (*cache != bt_changes) {
|
||||||
*cache = bt_changes;
|
*cache = bt_changes;
|
||||||
return true;
|
return true;
|
||||||
|
@ -109,7 +108,7 @@ static void bt_register(building_type * btype)
|
||||||
size_t len;
|
size_t len;
|
||||||
char data[64];
|
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);
|
len = cb_new_kv(btype->_name, strlen(btype->_name), &btype, sizeof(btype), data);
|
||||||
assert(len <= sizeof(data));
|
assert(len <= sizeof(data));
|
||||||
cb_insert(&cb_bldgtypes, data, len);
|
cb_insert(&cb_bldgtypes, data, len);
|
||||||
|
@ -130,8 +129,13 @@ static void free_buildingtype(void *ptr) {
|
||||||
free(btype);
|
free(btype);
|
||||||
}
|
}
|
||||||
|
|
||||||
static building_type *bt_create(const char *name) {
|
building_type *bt_get_or_create(const char *name)
|
||||||
building_type *btype = (building_type *)calloc(1, sizeof(building_type));
|
{
|
||||||
|
assert(name && name[0]);
|
||||||
|
if (name != NULL) {
|
||||||
|
building_type *btype = bt_find_i(name);
|
||||||
|
if (btype == NULL) {
|
||||||
|
btype = (building_type *)calloc(1, sizeof(building_type));
|
||||||
if (!btype) abort();
|
if (!btype) abort();
|
||||||
btype->_name = str_strdup(name);
|
btype->_name = str_strdup(name);
|
||||||
btype->flags = BTF_DEFAULT;
|
btype->flags = BTF_DEFAULT;
|
||||||
|
@ -139,16 +143,6 @@ static building_type *bt_create(const char *name) {
|
||||||
btype->maxsize = -1;
|
btype->maxsize = -1;
|
||||||
btype->capacity = 1;
|
btype->capacity = 1;
|
||||||
btype->maxcapacity = -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);
|
|
||||||
bt_register(btype);
|
bt_register(btype);
|
||||||
}
|
}
|
||||||
return 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 */
|
/* TECH DEBT: simplest thing that works for E3 dwarf/halfling faction rules */
|
||||||
static int adjust_size(const building *b, int bsize) {
|
static int adjust_size(const building *b, int bsize) {
|
||||||
assert(b != NULL);
|
assert(b);
|
||||||
if (config_get_int("rules.dwarf_castles", 0)
|
if (config_get_int("rules.dwarf_castles", 0)
|
||||||
&& strcmp(b->type->_name, "castle") == 0) {
|
&& strcmp(b->type->_name, "castle") == 0) {
|
||||||
unit *u = building_owner(b);
|
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)
|
const char *buildingtype(const building_type * btype, const building * b, int bsize)
|
||||||
{
|
{
|
||||||
assert(btype != NULL);
|
assert(btype);
|
||||||
|
|
||||||
if (b && b->attribs) {
|
if (b && b->attribs) {
|
||||||
if (is_building_type(btype, "generic")) {
|
if (is_building_type(btype, "generic")) {
|
||||||
|
@ -417,7 +411,7 @@ building *new_building(const struct building_type * btype, region * r,
|
||||||
bname = parameters[P_GEBAEUDE];
|
bname = parameters[P_GEBAEUDE];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(bname != NULL);
|
assert(bname);
|
||||||
snprintf(buffer, sizeof(buffer), "%s %s", bname, itoa36(b->no));
|
snprintf(buffer, sizeof(buffer), "%s %s", bname, itoa36(b->no));
|
||||||
b->name = str_strdup(bname);
|
b->name = str_strdup(bname);
|
||||||
return b;
|
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 const struct building_type *bt_caravan, *bt_dam, *bt_tunnel;
|
||||||
static int btypes;
|
static int btypes;
|
||||||
|
|
||||||
assert(bfindhash(b->no) != NULL);
|
assert(bfindhash(b->no));
|
||||||
|
|
||||||
if (bt_changed(&btypes)) {
|
if (bt_changed(&btypes)) {
|
||||||
bt_caravan = bt_find("caravan");
|
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) {
|
bool is_building_type(const struct building_type *btype, const char *name) {
|
||||||
assert(btype != NULL);
|
assert(btype);
|
||||||
return name && strcmp(btype->_name, name)==0;
|
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) {
|
int building_taxes(const building *b) {
|
||||||
assert(b != NULL);
|
assert(b);
|
||||||
return b->type->taxes;
|
return b->type->taxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifndef _GAMEDATA_H
|
#ifndef _GAMEDATA_H
|
||||||
#define _GAMEDATA_H
|
#define _GAMEDATA_H
|
||||||
|
|
|
@ -55,7 +55,7 @@ extern "C" {
|
||||||
struct mlist ** merge_messages(message_list *ml, message_list *append);
|
struct mlist ** merge_messages(message_list *ml, message_list *append);
|
||||||
void split_messages(message_list *ml, struct mlist **split);
|
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 syntax_error(const struct unit *u, struct order *ord);
|
||||||
void cmistake(const struct unit *u, struct order *ord, int mno, int mtype);
|
void cmistake(const struct unit *u, struct order *ord, int mno, int mtype);
|
||||||
|
|
|
@ -64,8 +64,8 @@ size_t str_strlcpy(char *dst, const char *src, size_t len)
|
||||||
register const char *s = src;
|
register const char *s = src;
|
||||||
register size_t n = len;
|
register size_t n = len;
|
||||||
|
|
||||||
assert(src != NULL);
|
assert(src);
|
||||||
assert(dst != NULL);
|
assert(dst);
|
||||||
/* Copy as many bytes as will fit */
|
/* Copy as many bytes as will fit */
|
||||||
if (n != 0 && --n != 0) {
|
if (n != 0 && --n != 0) {
|
||||||
do {
|
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 (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
|
#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 */
|
/* Find the end of dst and adjust bytes left but don't go past end */
|
||||||
while (*d != '\0' && n-- != 0)
|
while (*d != '\0' && n-- != 0)
|
||||||
d++;
|
d++;
|
||||||
dlen = (size_t)(d - dst);
|
dlen = d - dst;
|
||||||
n = len - dlen;
|
n = len - dlen;
|
||||||
|
|
||||||
if (n == 0)
|
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);
|
char *p = strstr(tmpl, var);
|
||||||
size_t len;
|
size_t len;
|
||||||
if (p) {
|
if (p) {
|
||||||
len = (size_t)(p - tmpl);
|
len = p - tmpl;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
len = strlen(tmpl);
|
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 str_hash(const char *s)
|
||||||
{
|
{
|
||||||
int key = 0;
|
int key = 0;
|
||||||
assert(s != NULL);
|
assert(s);
|
||||||
while (*s) {
|
while (*s) {
|
||||||
key = key * 37 + *s++;
|
key = key * 37 + *s++;
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ unsigned int wang_hash(unsigned int a)
|
||||||
}
|
}
|
||||||
|
|
||||||
char *str_strdup(const char *s) {
|
char *str_strdup(const char *s) {
|
||||||
if (s != NULL) {
|
if (s == NULL) return NULL;
|
||||||
#ifdef HAVE_STRDUP
|
#ifdef HAVE_STRDUP
|
||||||
return strdup(s);
|
return strdup(s);
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
|
@ -211,8 +211,6 @@ char *str_strdup(const char *s) {
|
||||||
memcpy(dup, s, len+1);
|
memcpy(dup, s, len+1);
|
||||||
return dup;
|
return dup;
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sbs_printf(struct sbstring *sbs, const char *format, ...)
|
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);
|
size_t size = sbs->size - (sbs->end - sbs->begin);
|
||||||
|
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
int bytes;
|
|
||||||
va_list argp;
|
va_list argp;
|
||||||
va_start(argp, format);
|
va_start(argp, format);
|
||||||
bytes = vsnprintf(sbs->end, size, format, argp);
|
int bytes = vsnprintf(sbs->end, size, format, argp);
|
||||||
if (bytes > 0) {
|
if (bytes > 0) {
|
||||||
size_t len = (size_t)bytes;
|
if ((size_t)bytes >= size) {
|
||||||
if (len >= size) {
|
bytes = size - 1;
|
||||||
len = size - 1;
|
|
||||||
/* terminate truncated output */
|
/* terminate truncated output */
|
||||||
sbs->end[len] = '\0';
|
sbs->end[bytes] = '\0';
|
||||||
}
|
}
|
||||||
sbs->end += len;
|
sbs->end += bytes;
|
||||||
}
|
}
|
||||||
va_end(argp);
|
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)
|
void sbs_init(struct sbstring *sbs, char *buffer, size_t size)
|
||||||
{
|
{
|
||||||
assert(sbs != NULL);
|
assert(sbs);
|
||||||
assert(size > 0);
|
assert(size > 0);
|
||||||
sbs->begin = buffer;
|
sbs->begin = buffer;
|
||||||
sbs->size = size;
|
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)
|
void sbs_adopt(struct sbstring *sbs, char *buffer, size_t size)
|
||||||
{
|
{
|
||||||
size_t len = strlen(buffer);
|
size_t len = strlen(buffer);
|
||||||
assert(sbs != NULL);
|
assert(sbs);
|
||||||
assert(size > len);
|
assert(size > len);
|
||||||
sbs->begin = buffer;
|
sbs->begin = buffer;
|
||||||
sbs->size = size;
|
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)
|
void sbs_strncat(struct sbstring *sbs, const char *str, size_t size)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
assert(sbs != NULL);
|
assert(sbs);
|
||||||
len = sbs->size - (sbs->end - sbs->begin) - 1;
|
len = sbs->size - (sbs->end - sbs->begin) - 1;
|
||||||
if (len < size) {
|
if (len < size) {
|
||||||
size = len;
|
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)
|
void sbs_strcat(struct sbstring *sbs, const char *str)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
assert(sbs != NULL);
|
assert(sbs);
|
||||||
len = sbs->size - (sbs->end - sbs->begin);
|
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);
|
sbs->end += strlen(sbs->end);
|
||||||
assert(sbs->begin + sbs->size >= sbs->end);
|
assert(sbs->begin + sbs->size >= sbs->end);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sbs_substr(sbstring *sbs, ptrdiff_t pos, size_t len)
|
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 */
|
/* starting past end of string, do nothing */
|
||||||
sbs->end = sbs->begin;
|
sbs->end = sbs->begin;
|
||||||
}
|
}
|
||||||
if (pos >= 0) {
|
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 > sz) len = sz;
|
||||||
if (len - pos > 0) {
|
if (len - pos > 0) {
|
||||||
memmove(sbs->begin, sbs->begin + pos, len);
|
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)
|
size_t sbs_length(const struct sbstring *sbs)
|
||||||
{
|
{
|
||||||
assert(sbs->begin + sbs->size >= sbs->end);
|
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 *str_unescape(char *str) {
|
||||||
char *read = str, *write = str;
|
char *read = str, *write = str;
|
||||||
while (*read) {
|
while (*read) {
|
||||||
char * pos = strchr(read, '\\');
|
char * pos = strchr(read, '\\');
|
||||||
if (pos > read) {
|
if (pos >= read) {
|
||||||
size_t len = (size_t)(pos - read);
|
size_t len = (size_t)(pos - read);
|
||||||
memmove(write, read, len);
|
memmove(write, read, len);
|
||||||
write += 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) {
|
while (slen > 0 && size > 1 && *read) {
|
||||||
const char *pos = strpbrk(read, chars);
|
const char *pos = strpbrk(read, chars);
|
||||||
size_t len = size;
|
size_t len = size;
|
||||||
if (pos > read) {
|
if (pos >= read) {
|
||||||
len = (size_t)(pos - read);
|
len = pos - read;
|
||||||
}
|
}
|
||||||
if (len < size) {
|
if (len < size) {
|
||||||
unsigned char ch = *(const unsigned char *)pos;
|
unsigned char ch = *(const unsigned char *)pos;
|
||||||
|
|
Loading…
Reference in a new issue