Re: [PATCH] Fix undefined behaviour

Klaus Schmidinger <[email protected]> Tue, 6 Dec 2022 18:04:14 +0100
Newsgroups gmane.linux.vdr
Message-ID <[email protected]>
On 06.12.22 14:25, Marko Mäkelä wrote:
> ...
> Maybe the simplest way to silence the warning would be to bloat the variable-length array with 1 extra element, wasting sizeof(int) bytes of stack space:
> 
>    int SlotPriority[NumCamSlots + 1];

OK, so this is it:

--- device.c    2022/01/24 16:53:45     5.5
+++ device.c    2022/12/06 17:01:41
@@ -249,7 +249,7 @@
  {
    // Collect the current priorities of all CAM slots that can decrypt the channel:
    int NumCamSlots = CamSlots.Count();
-  int SlotPriority[NumCamSlots];
+  int SlotPriority[NumCamSlots + 1]; // +1 to keep the compiler from doing crazy "optimizations" if NumCamSlots==0
    int NumUsableSlots = 0;
    bool InternalCamNeeded = false;
    if (Channel->Ca() >= CA_ENCRYPTED_MIN) {

Klaus


_______________________________________________
vdr mailing list
[email protected]
https://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr