55e1e4cd03
Signed-off-by: Jürgen Buchmüller <pullmoll@t-online.de>
89 lines
2.7 KiB
Diff
89 lines
2.7 KiB
Diff
Source: written by @pullmoll
|
|
Upstream: n/a
|
|
Reason: replace legacy sprintf with snprintf to avoid buffer overruns and fix gcc-8 warnings/errors.
|
|
|
|
--- OOps/schedule.c.orig 2018-09-24 18:54:29.373049365 +0200
|
|
+++ OOps/schedule.c 2018-09-24 19:04:41.067012905 +0200
|
|
@@ -56,22 +56,27 @@
|
|
return eventOpcodeI_(csound, &pp, 0, 'i');
|
|
}
|
|
|
|
-static void add_string_arg(char *s, const char *arg) {
|
|
- int32_t offs = strlen(s) ;
|
|
- //char *c = s;
|
|
- s += offs;
|
|
- *s++ = ' ';
|
|
-
|
|
- *s++ ='\"';
|
|
- while(*arg != '\0') {
|
|
- if(*arg == '\"')
|
|
- *s++ = '\\';
|
|
- *s++ = *arg++;
|
|
+static void add_string_arg(char *s, size_t size, const char *arg) {
|
|
+ size_t offs = strlen(s);
|
|
+ size_t len;
|
|
+ len = snprintf(s + offs, size - offs, " \"");
|
|
+ if (len <= 0)
|
|
+ return;
|
|
+ offs += len;
|
|
+ while (*arg != '\0') {
|
|
+ if (*arg == '\"') {
|
|
+ len = snprintf(s + offs, size - offs, "\\");
|
|
+ if (len <= 0)
|
|
+ return;
|
|
+ offs += len;
|
|
+ }
|
|
+ len = snprintf(s + offs, size - offs, "%c", *arg);
|
|
+ if (len <= 0)
|
|
+ return;
|
|
+ offs += len;
|
|
+ arg++;
|
|
}
|
|
-
|
|
- *s++ = '\"';
|
|
- *s = '\0';
|
|
- //printf("%s \n", c);
|
|
+ snprintf(s + offs, size - offs, "\"");
|
|
}
|
|
|
|
|
|
@@ -79,15 +84,16 @@
|
|
{
|
|
int32_t i;
|
|
int32_t argno = p->INOCOUNT+1;
|
|
+ size_t len;
|
|
char s[16384];
|
|
- sprintf(s, "i %f %f %f", *p->which, *p->when, *p->dur);
|
|
+ len = snprintf(s, sizeof(s), "i %f %f %f", *p->which, *p->when, *p->dur);
|
|
for (i=4; i < argno ; i++) {
|
|
MYFLT *arg = p->argums[i-4];
|
|
if (csoundGetTypeForArg(arg) == &CS_VAR_TYPE_S) {
|
|
- add_string_arg(s, ((STRINGDAT *)arg)->data);
|
|
- //sprintf(s, "%s \"%s\" ", s, ((STRINGDAT *)arg)->data);
|
|
+ add_string_arg(s, sizeof(s), ((STRINGDAT *)arg)->data);
|
|
+ //snprintf(s, sizeof(s), "%s \"%s\" ", s, ((STRINGDAT *)arg)->data);
|
|
}
|
|
- else sprintf(s, "%s %f", s, *arg);
|
|
+ else snprintf(s + len, sizeof(s) - len, " %f", *arg);
|
|
|
|
}
|
|
|
|
@@ -99,14 +105,14 @@
|
|
{
|
|
int32_t i;
|
|
int32_t argno = p->INOCOUNT+1;
|
|
+ size_t len;
|
|
char s[16384];
|
|
- sprintf(s, "i \"%s\" %f %f", ((STRINGDAT *)p->which)->data, *p->when, *p->dur);
|
|
+ len = snprintf(s, sizeof(s), "i \"%s\" %f %f", ((STRINGDAT *)p->which)->data, *p->when, *p->dur);
|
|
for (i=4; i < argno ; i++) {
|
|
MYFLT *arg = p->argums[i-4];
|
|
if (csoundGetTypeForArg(arg) == &CS_VAR_TYPE_S)
|
|
- //sprintf(s, "%s \"%s\" ", s, ((STRINGDAT *)arg)->data);
|
|
- add_string_arg(s, ((STRINGDAT *)arg)->data);
|
|
- else sprintf(s, "%s %f", s, *arg);
|
|
+ add_string_arg(s, sizeof(s), ((STRINGDAT *)arg)->data);
|
|
+ else snprintf(s + len, sizeof(s) - len, " %f", *arg);
|
|
}
|
|
//printf("%s\n", s);
|
|
csoundInputMessageInternal(csound, s);
|