From 55e1e4cd033b8a132f38d70991c402f891ceb3db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Buchm=C3=BCller?= Date: Mon, 24 Sep 2018 19:19:55 +0200 Subject: [PATCH] csound: fix build w/ gcc-8.2.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jürgen Buchmüller --- srcpkgs/csound/patches/buffersize.patch | 27 ++++++ srcpkgs/csound/patches/replace-sprintf.patch | 89 ++++++++++++++++++++ srcpkgs/csound/template | 2 + 3 files changed, 118 insertions(+) create mode 100644 srcpkgs/csound/patches/replace-sprintf.patch diff --git a/srcpkgs/csound/patches/buffersize.patch b/srcpkgs/csound/patches/buffersize.patch index d7e9712196d..25da8021fa4 100644 --- a/srcpkgs/csound/patches/buffersize.patch +++ b/srcpkgs/csound/patches/buffersize.patch @@ -9,3 +9,30 @@ int32_t j = 0; int32_t len = 8192; while (*fmt) { +--- Engine/csound_orc_expressions.c.orig 2018-09-24 19:09:36.956995269 +0200 ++++ Engine/csound_orc_expressions.c 2018-09-24 19:11:09.401989759 +0200 +@@ -826,10 +826,10 @@ + + static TREE *create_synthetic_ident(CSOUND *csound, int32 count) + { +- char *label = (char *)csound->Calloc(csound, 20); ++ char *label = (char *)csound->Calloc(csound, 32); + ORCTOKEN *token; + +- snprintf(label, 20, "__synthetic_%"PRIi32, count); ++ snprintf(label, 32, "__synthetic_%"PRIi32, count); + if (UNLIKELY(PARSER_DEBUG)) + csound->Message(csound, "Creating Synthetic T_IDENT: %s\n", label); + token = make_token(csound, label); +@@ -840,9 +840,9 @@ + + static TREE *create_synthetic_label(CSOUND *csound, int32 count) + { +- char *label = (char *)csound->Calloc(csound, 20); ++ char *label = (char *)csound->Calloc(csound, 32); + ORCTOKEN *token; +- snprintf(label, 20, "__synthetic_%"PRIi32":", count); ++ snprintf(label, 32, "__synthetic_%"PRIi32":", count); + if (UNLIKELY(PARSER_DEBUG)) + csound->Message(csound, "Creating Synthetic label: %s\n", label); + token = make_label(csound, label); diff --git a/srcpkgs/csound/patches/replace-sprintf.patch b/srcpkgs/csound/patches/replace-sprintf.patch new file mode 100644 index 00000000000..6518514c704 --- /dev/null +++ b/srcpkgs/csound/patches/replace-sprintf.patch @@ -0,0 +1,89 @@ +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); diff --git a/srcpkgs/csound/template b/srcpkgs/csound/template index 81e8b996e30..91ba081ad99 100644 --- a/srcpkgs/csound/template +++ b/srcpkgs/csound/template @@ -19,6 +19,8 @@ distfiles="https://github.com/$pkgname/$pkgname/archive/$version.tar.gz" checksum=f47df73ff270faa70bf53bad68edc85b2dc5623b9c73d06054cd03f5d3332dc0 nocross=yes +CXXFLAGS="-Wno-error" + post_install() { vinstall ${FILESDIR}/csound.sh 755 etc/profile.d # Avoid conflict with libextractor