Merge pull request #865 from ennorehling/develop

new coverity issues
This commit is contained in:
Enno Rehling 2019-08-10 05:59:30 +02:00 committed by GitHub
commit 8bd7a0a157
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 9 deletions

View File

@ -2025,10 +2025,10 @@ int entertain_cmd(unit * u, struct order *ord, econ_request **io_req)
return 0; return 0;
} }
wants = u->number * (entertainbase + effskill(u, SK_ENTERTAINMENT, NULL) * entertainperlevel); wants = getuint();
max_e = getuint(); max_e = u->number * (entertainbase + effskill(u, SK_ENTERTAINMENT, NULL) * entertainperlevel);
if (max_e != 0 && wants > max_e) { if (wants > 0 && wants < max_e) {
wants = max_e; max_e = wants;
} }
if (max_e > 0) { if (max_e > 0) {
add_request(req++, ECON_ENTERTAIN, u, ord, max_e); add_request(req++, ECON_ENTERTAIN, u, ord, max_e);

View File

@ -565,7 +565,7 @@ int autoseed(newfaction ** players, int nsize, int max_agediff)
nfp = &nextf->next; nfp = &nextf->next;
while (*nfp) { while (*nfp) {
newfaction *nf = *nfp; newfaction *nf = *nfp;
if (strcmp(nextf->email, nf->email) == 0) { if (nf->email && nextf->email && strcmp(nextf->email, nf->email) == 0) {
log_warning("Duplicate email %s\n", nf->email ? nf->email : ""); log_warning("Duplicate email %s\n", nf->email ? nf->email : "");
*nfp = nf->next; *nfp = nf->next;
free_newfaction(nf); free_newfaction(nf);

View File

@ -125,6 +125,7 @@ void free_recruitments(recruitment * recruits)
recruitment *rec = recruits; recruitment *rec = recruits;
recruits = rec->next; recruits = rec->next;
free_requests(rec->requests); free_requests(rec->requests);
free(rec);
} }
} }

View File

@ -13,6 +13,7 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <stdbool.h>
#include <string.h> #include <string.h>
#include <wctype.h> #include <wctype.h>
#include <ctype.h> #include <ctype.h>
@ -33,6 +34,14 @@
#define B00000011 0x03 #define B00000011 0x03
#define B00000001 0x01 #define B00000001 0x01
static bool char_trimmed(wint_t wc) {
if (wc >= 0x2000 && wc <= 0x200f) {
/* only weird stuff here */
return true;
}
return iswspace(wc) || iswcntrl(wc);
}
size_t unicode_utf8_trim(char *buf) size_t unicode_utf8_trim(char *buf)
{ {
int result = 0, ts = 0; int result = 0, ts = 0;
@ -56,15 +65,15 @@ size_t unicode_utf8_trim(char *buf)
++result; ++result;
} }
} }
if (op == buf && (iswspace(wc) || !iswprint(wc))) { if (op == buf && char_trimmed(wc)) {
result += size; result += size;
} }
else if (wc>255 || !iscntrl(wc)) { else if (wc>255 || !iswcntrl(wc)) {
if (op != ip) { if (op != ip) {
memmove(op, ip, size); memmove(op, ip, size);
} }
op += size; op += size;
if (iswspace(wc) || !iswprint(wc)) { if (char_trimmed(wc)) {
ts += size; ts += size;
} }
else { else {

View File

@ -173,12 +173,23 @@ static void test_unicode_trim_ltrm(CuTest *tc) {
CuAssertStrEquals(tc, expect, name); CuAssertStrEquals(tc, expect, name);
} }
static void test_unicode_trim_emoji(CuTest *tc) {
const char clock[] = { 0xE2, 0x8F, 0xB0, 0x00 };
char name[64];
char expect[64];
snprintf(name, sizeof(name), "%s Alarm%sClock %s", clock, clock, clock);
strcpy(expect, name);
CuAssertIntEquals(tc, 0, unicode_utf8_trim(name));
CuAssertStrEquals(tc, expect, name);
}
CuSuite *get_unicode_suite(void) CuSuite *get_unicode_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_unicode_trim); SUITE_ADD_TEST(suite, test_unicode_trim);
SUITE_ADD_TEST(suite, test_unicode_trim_zwnj); SUITE_ADD_TEST(suite, test_unicode_trim_zwnj);
SUITE_ADD_TEST(suite, test_unicode_trim_ltrm); SUITE_ADD_TEST(suite, test_unicode_trim_ltrm);
SUITE_ADD_TEST(suite, test_unicode_trim_emoji);
SUITE_ADD_TEST(suite, test_unicode_utf8_to_other); SUITE_ADD_TEST(suite, test_unicode_utf8_to_other);
SUITE_ADD_TEST(suite, test_unicode_utf8_to_ucs); SUITE_ADD_TEST(suite, test_unicode_utf8_to_ucs);
SUITE_ADD_TEST(suite, test_unicode_compare); SUITE_ADD_TEST(suite, test_unicode_compare);