Compiler warning
-
-
Die Patche aus Beitrag #12, #14 und #18 anwenden. Man kann sie auch mit copy and paste in eine Datei packen.
-
Danke, damit ist klar, was rein muss und was nicht.
-
RHS : Wenn du in ci.c, Zeile 1584 strncpy ebenfalls durch memcpy sollte diese Warnung auch nicht mehr auftauchen. Hier soll kein "C"-String in den Buffer geschrieben werden.
Damit werden aber immer 256 Byte kopiert, auch wenn Text nur sehr kurz ist. Wobei das freilich kein Fehler wäre, aber unnötig.
Während der Tausch von strncpy() gegen memcpy() lediglich den Compiler zufriedenstellt, aber keinen Fehler behebt, lauert da aber immer noch ein Problem, wenn Text länger als 256 Byte sein sollte. Dann würde nämlich bei SendData() eine zu große zu kopierende Puffergröße angegeben. Daher schlage ich folgenden Patch vor:
Diff
Display More--- ci.c 2019/05/05 14:15:56 5.3 +++ ci.c 2019/05/06 11:47:42 @@ -1591,9 +1591,12 @@ struct tAnswer { uint8_t id; char text[256]; };//XXX tAnswer answer; answer.id = Text ? AI_ANSWER : AI_CANCEL; - if (Text) - strncpy(answer.text, Text, sizeof(answer.text)); - SendData(AOT_ANSW, Text ? strlen(Text) + 1 : 1, (uint8_t *)&answer); + int len = 0; + if (Text) { + len = min(sizeof(answer.text), strlen(Text)); + memcpy(answer.text, Text, len); + } + SendData(AOT_ANSW, len + 1, (uint8_t *)&answer); return true; }
-
Die Länge von struct tIndexPes (64 Bit) ist kleiner als die der struct tIndexTs
Nein, beide sind exakt gleich groß, nämlich 64 Bit.
recording.c:2637:52: warning: 'void* memcpy(void*, const void*, size_t)' copying an object of non-trivial type 'struct tIndexTs' from an array of 'struct tIndexPes' [-Wclass-memaccess]
memcpy(IndexTs, &IndexPes, sizeof(*IndexTs));Hier nimmt es der Compiler wohl etwas sehr genau, weil tIndexTs einen Konstruktor hat.
Na gut, soll er. Aber wenn schon, dann würde ich nach (void *) casten:
Diff
Display More--- recording.c 2019/05/06 11:26:06 5.3 +++ recording.c 2019/05/06 12:37:13 @@ -2640,7 +2640,7 @@ IndexPes.type = uchar(IndexTs->independent ? 1 : 2); // I_FRAME : "not I_FRAME" (exact frame type doesn't matter) IndexPes.number = uchar(IndexTs->number); IndexPes.reserved = 0; - memcpy(IndexTs, &IndexPes, sizeof(*IndexTs)); + memcpy((void *)IndexTs, &IndexPes, sizeof(*IndexTs)); IndexTs++; } }
RHS: kannst du bitte verifizieren, ob dieser Patch das Problem auch behebt?
-
Nein, beide sind exakt gleich groß, nämlich 64 Bit.
Richtig. Ich habe übersehen, das hier Bitfelder definiert werden - die genutzen Bits sind in beiden Fällen 64 Bit.
Sofern die Bitfelder und die andere Elemente vom Compiler ohne Füllbytes zusammengefügt ist die Größe ident.
Aber sollte hier nicht zur Sicherheit ein __attribute__ ((__packed__)) oder ähnliches angewendet werden?
Helmut
-
Man würde damit sicher nichts verkehrt machen ;-).
-
-
Mein vdr läuft auf opensuse thumbleweed. Beim letzten update wurde auch der compiler auf 9.1.1
Codeg++ (SUSE Linux) 9.1.1 20190520 [gcc-9-branch revision 271396] Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
hochgezogen. Und schwupps gibt es eine neue Compiler
Warnung:
Code
Display Moreg++ -g -O3 -Wall -march=native -Woverloaded-virtual -Wno-parentheses -fPIC -c -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DREMOTE_KBD -DLIRC_DEVICE=\"/var/run/lirc/lircd\" -DVIDEODIR=\"/srv/vdr/video\" -DCONFDIR=\"/var/lib/vdr\" -DARGSDIR=\"/etc/vdr/conf.d\" -DCACHEDIR=\"/var/cache/vdr\" -DRESDIR=\"/usr/local/share/vdr\" -DPLUGINDIR=\"/usr/local/lib/vdr\" -DLOCDIR=\"/usr/local/share/locale\" -I/usr/include/uuid -I/usr/include/freetype2 -o sections.o sections.c In file included from i18n.h:14, from config.h:19, from channels.h:13, from recording.h:14, from recording.c:10: In constructor 'cFileName::cFileName(const char*, bool, bool, bool)', inlined from 'cFileName::cFileName(const char*, bool, bool, bool)' at recording.c:2883:1: tools.h:35:64: warning: '%s' directive argument is null [-Wformat-overflow=] 35 | #define esyslog(a...) void( (SysLogLevel > 0) ? syslog_with_tid(LOG_ERR, a) : void() ) | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~ recording.c:2893:6: note: in expansion of macro 'esyslog' 2893 | esyslog("ERROR: can't copy file name '%s'", fileName); | ^~~~~~~ recording.c: In constructor 'cFileName::cFileName(const char*, bool, bool, bool)': recording.c:2893:44: note: format string is defined here 2893 | esyslog("ERROR: can't copy file name '%s'", fileName); | ^~ CC shutdown.o
-
Da hat er recht.
Es muss heissen:
esyslog("ERROR: can't copy file name '%s'", FileName);
(fileName -> FileName)
Wobei, wenn er an diese Stelle kommt, ist eh alles aus... ;-).
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!