Fix some off by one issues with arraycount ..thanks coypu.

This commit is contained in:
roy 2017-01-11 20:53:52 +00:00
parent c77e1d014f
commit 53035e70de
2 changed files with 11 additions and 11 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh
# $NetBSD: genhash,v 1.8 2011/11/02 12:09:25 roy Exp $
# $NetBSD: genhash,v 1.9 2017/01/11 20:53:52 roy Exp $
# Copyright (c) 2009, 2011 The NetBSD Foundation, Inc.
#
@ -65,7 +65,7 @@ const char *
_ti_${name}id(ssize_t idx)
{
if ((size_t)idx > __arraycount(_ti_${name}ids))
if ((size_t)idx >= __arraycount(_ti_${name}ids))
return NULL;
return _ti_${name}ids[idx];
}
@ -76,7 +76,7 @@ _ti_${name}index(const char *key)
uint32_t idx;
idx = _ti_${name}hash((const unsigned char *)key, strlen(key));
if (idx > __arraycount(_ti_${name}ids) ||
if (idx >= __arraycount(_ti_${name}ids) ||
strcmp(key, _ti_${name}ids[idx]) != 0)
return -1;
return idx;

View File

@ -1,4 +1,4 @@
/* $NetBSD: termcap.c,v 1.19 2016/04/01 19:59:08 christos Exp $ */
/* $NetBSD: termcap.c,v 1.20 2017/01/11 20:53:52 roy Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: termcap.c,v 1.19 2016/04/01 19:59:08 christos Exp $");
__RCSID("$NetBSD: termcap.c,v 1.20 2017/01/11 20:53:52 roy Exp $");
#include <assert.h>
#include <ctype.h>
@ -88,7 +88,7 @@ tgetflag(const char *id2)
return 0;
ind = _t_flaghash((const unsigned char *)id, strlen(id));
if (ind <= __arraycount(_ti_cap_flagids)) {
if (ind < __arraycount(_ti_cap_flagids)) {
if (strcmp(id, _ti_cap_flagids[ind].id) == 0)
return cur_term->flags[_ti_cap_flagids[ind].ti];
}
@ -113,7 +113,7 @@ tgetnum(const char *id2)
return -1;
ind = _t_numhash((const unsigned char *)id, strlen(id));
if (ind <= __arraycount(_ti_cap_numids)) {
if (ind < __arraycount(_ti_cap_numids)) {
te = &_ti_cap_numids[ind];
if (strcmp(id, te->id) == 0) {
if (!VALID_NUMERIC(cur_term->nums[te->ti]))
@ -146,7 +146,7 @@ tgetstr(const char *id2, char **area)
str = NULL;
ind = _t_strhash((const unsigned char *)id, strlen(id));
if (ind <= __arraycount(_ti_cap_strids)) {
if (ind < __arraycount(_ti_cap_strids)) {
if (strcmp(id, _ti_cap_strids[ind].id) == 0) {
str = cur_term->strs[_ti_cap_strids[ind].ti];
if (str == NULL)
@ -188,7 +188,7 @@ flagname(const char *key)
uint32_t idx;
idx = _t_flaghash((const unsigned char *)key, strlen(key));
if (idx <= __arraycount(_ti_cap_flagids) &&
if (idx < __arraycount(_ti_cap_flagids) &&
strcmp(key, _ti_cap_flagids[idx].id) == 0)
return _ti_flagid(_ti_cap_flagids[idx].ti);
return key;
@ -200,7 +200,7 @@ numname(const char *key)
uint32_t idx;
idx = _t_numhash((const unsigned char *)key, strlen(key));
if (idx <= __arraycount(_ti_cap_numids) &&
if (idx < __arraycount(_ti_cap_numids) &&
strcmp(key, _ti_cap_numids[idx].id) == 0)
return _ti_numid(_ti_cap_numids[idx].ti);
return key;
@ -212,7 +212,7 @@ strname(const char *key)
uint32_t idx;
idx = _t_strhash((const unsigned char *)key, strlen(key));
if (idx <= __arraycount(_ti_cap_strids) &&
if (idx < __arraycount(_ti_cap_strids) &&
strcmp(key, _ti_cap_strids[idx].id) == 0)
return _ti_strid(_ti_cap_strids[idx].ti);