forked from github/server
str_itoa for platforms that do not have itoa.
remove more static string buffer warning code (bsdstring) from reports.
This commit is contained in:
parent
037113b35d
commit
af72febebc
|
@ -2198,28 +2198,23 @@ static void eval_resources(struct opstack **stack, const void *userdata)
|
|||
const struct locale *lang = f ? f->locale : default_locale;
|
||||
const struct resource *res = (const struct resource *)opop(stack).v;
|
||||
char buf[1024]; /* but we only use about half of this */
|
||||
size_t size = sizeof(buf) - 1;
|
||||
variant var;
|
||||
|
||||
char *bufp = buf;
|
||||
while (res != NULL && size > 4) {
|
||||
sbstring sbs;
|
||||
|
||||
sbs_init(&sbs, buf, sizeof(buf));
|
||||
while (res != NULL) {
|
||||
const char *rname =
|
||||
resourcename(res->type, (res->number != 1) ? NMF_PLURAL : 0);
|
||||
int result = snprintf(bufp, size, "%d %s", res->number, LOC(lang, rname));
|
||||
if (wrptr(&bufp, &size, result) != 0 || size < sizeof(buf) / 2) {
|
||||
WARN_STATIC_BUFFER();
|
||||
break;
|
||||
}
|
||||
sbs_strcat(&sbs, str_itoa(res->number));
|
||||
sbs_strcat(&sbs, "");
|
||||
sbs_strcat(&sbs, LOC(lang, rname));
|
||||
|
||||
res = res->next;
|
||||
if (res != NULL && size > 2) {
|
||||
strcat(bufp, ", ");
|
||||
bufp += 2;
|
||||
size -= 2;
|
||||
if (res != NULL) {
|
||||
sbs_strcat(&sbs, ", ");
|
||||
}
|
||||
}
|
||||
*bufp = 0;
|
||||
var.v = strcpy(balloc((size_t)(bufp - buf + 1)), buf);
|
||||
var.v = strcpy(balloc(sbs_length(&sbs)), buf);
|
||||
opush(stack, var);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <string.h>
|
||||
#endif
|
||||
|
||||
const char *str_itoa(int n) {
|
||||
static char buf[12];
|
||||
snprintf(buf, sizeof(buf), "%d", n);
|
||||
return buf;
|
||||
}
|
||||
|
||||
size_t str_strlcpy(char *dst, const char *src, size_t len)
|
||||
{
|
||||
#ifdef HAVE_BSDSTRING
|
||||
|
|
|
@ -28,6 +28,7 @@ extern "C" {
|
|||
|
||||
void str_replace(char *buffer, size_t size, const char *tmpl, const char *var, const char *value);
|
||||
int str_hash(const char *s);
|
||||
const char *str_itoa(int i);
|
||||
size_t str_slprintf(char * dst, size_t size, const char * format, ...);
|
||||
size_t str_strlcpy(char *dst, const char *src, size_t len);
|
||||
size_t str_strlcat(char *dst, const char *src, size_t len);
|
||||
|
|
Loading…
Reference in New Issue