d3dadapter9: use snprintf(..., "%s", ...) instead of strncpy
authorAndre Heider <a.heider@gmail.com>
Sun, 25 Nov 2018 09:49:59 +0000 (10:49 +0100)
committerAxel Davy <davyaxel0@gmail.com>
Sat, 1 Dec 2018 20:32:53 +0000 (21:32 +0100)
Fixes -Wstringop-truncation compiler warnings.
See f836d799f9066adf58f36 "intel/decoder: use snprintf(..., "%s", ...) instead of strncpy"

Signed-off-by: Andre Heider <a.heider@gmail.com>
Reviewed-by: Axel Davy <davyaxel0@gmail.com>
src/gallium/targets/d3dadapter9/description.c
src/gallium/targets/d3dadapter9/drm.c

index c0a86782f8ef7368cb3af372931b8e11512002b6..a3e4cd61770c2e3f147d75f0e849ef9cd548b4e9 100644 (file)
@@ -20,6 +20,7 @@
  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  * USE OR OTHER DEALINGS IN THE SOFTWARE. */
 
+#include <stdio.h>
 #include <string.h>
 #include "adapter9.h"
 
@@ -239,7 +240,7 @@ d3d_match_vendor_id( D3DADAPTER_IDENTIFIER9* drvid,
     DBG("unknown vendor 0x4%x, emulating 0x4%x\n", drvid->VendorId, fallback_ven);
     drvid->VendorId = fallback_ven;
     drvid->DeviceId = fallback_dev;
-    strncpy(drvid->Description, fallback_name, sizeof(drvid->Description));
+    snprintf(drvid->Description, sizeof(drvid->Description), "%s", fallback_name);
 }
 
 /* fill in driver name and version */
@@ -277,46 +278,54 @@ void d3d_fill_cardname(D3DADAPTER_IDENTIFIER9* drvid) {
     case HW_VENDOR_INTEL:
         for (i = 0; i < sizeof(cards_intel) / sizeof(cards_intel[0]); i++) {
             if (strstr(drvid->Description, cards_intel[i].mesaname)) {
-                strncpy(drvid->Description, cards_intel[i].d3d9name, sizeof(drvid->Description));
+                snprintf(drvid->Description, sizeof(drvid->Description),
+                         "%s", cards_intel[i].d3d9name);
                 return;
             }
         }
         /* use a fall-back if nothing matches */
         DBG("Unknown card name %s!\n", drvid->DeviceName);
-        strncpy(drvid->Description, cards_intel[0].d3d9name, sizeof(drvid->Description));
+        snprintf(drvid->Description, sizeof(drvid->Description),
+                 "%s", cards_intel[0].d3d9name);
         break;
     case HW_VENDOR_VMWARE:
         for (i = 0; i < sizeof(cards_vmware) / sizeof(cards_vmware[0]); i++) {
             if (strstr(drvid->Description, cards_vmware[i].mesaname)) {
-                strncpy(drvid->Description, cards_vmware[i].d3d9name, sizeof(drvid->Description));
+                snprintf(drvid->Description, sizeof(drvid->Description),
+                         "%s", cards_vmware[i].d3d9name);
                 return;
             }
         }
         /* use a fall-back if nothing matches */
         DBG("Unknown card name %s!\n", drvid->DeviceName);
-        strncpy(drvid->Description, cards_vmware[0].d3d9name, sizeof(drvid->Description));
+        snprintf(drvid->Description, sizeof(drvid->Description),
+                 "%s", cards_vmware[0].d3d9name);
         break;
     case HW_VENDOR_AMD:
         for (i = 0; i < sizeof(cards_amd) / sizeof(cards_amd[0]); i++) {
             if (strstr(drvid->Description, cards_amd[i].mesaname)) {
-                strncpy(drvid->Description, cards_amd[i].d3d9name, sizeof(drvid->Description));
+                snprintf(drvid->Description, sizeof(drvid->Description),
+                         "%s", cards_amd[i].d3d9name);
                 return;
             }
         }
         /* use a fall-back if nothing matches */
         DBG("Unknown card name %s!\n", drvid->DeviceName);
-        strncpy(drvid->Description, cards_amd[0].d3d9name, sizeof(drvid->Description));
+        snprintf(drvid->Description, sizeof(drvid->Description),
+                 "%s", cards_amd[0].d3d9name);
         break;
     case HW_VENDOR_NVIDIA:
         for (i = 0; i < sizeof(cards_nvidia) / sizeof(cards_nvidia[0]); i++) {
             if (strstr(drvid->Description, cards_nvidia[i].mesaname)) {
-                strncpy(drvid->Description, cards_nvidia[i].d3d9name, sizeof(drvid->Description));
+                snprintf(drvid->Description, sizeof(drvid->Description),
+                         "%s", cards_nvidia[i].d3d9name);
                 return;
             }
         }
         /* use a fall-back if nothing matches */
         DBG("Unknown card name %s!\n", drvid->DeviceName);
-        strncpy(drvid->Description, cards_nvidia[0].d3d9name, sizeof(drvid->Description));
+        snprintf(drvid->Description, sizeof(drvid->Description),
+                 "%s", cards_nvidia[0].d3d9name);
         break;
     default:
         break;
index 6fb8caf5c2fa3ef5acb98dc77209f1617e29570e..e08778b81d429aba43ff78169375a8c26f5eb869 100644 (file)
@@ -149,8 +149,8 @@ read_descriptor( struct d3dadapter9_context *ctx,
                  &drvid->SubSysId, &drvid->Revision);
     snprintf(drvid->DeviceName, sizeof(drvid->DeviceName),
                  "Gallium 0.4 with %s", ctx->hal->get_vendor(ctx->hal));
-    strncpy(drvid->Description, ctx->hal->get_name(ctx->hal),
-                 sizeof(drvid->Description));
+    snprintf(drvid->Description, sizeof(drvid->Description),
+                 "%s", ctx->hal->get_name(ctx->hal));
 
     if (override_vendorid > 0) {
         found = FALSE;
@@ -163,8 +163,8 @@ read_descriptor( struct d3dadapter9_context *ctx,
                         fallback_cards[i].device_id);
                 drvid->VendorId = fallback_cards[i].vendor_id;
                 drvid->DeviceId = fallback_cards[i].device_id;
-                strncpy(drvid->Description, fallback_cards[i].name,
-                             sizeof(drvid->Description));
+                snprintf(drvid->Description, sizeof(drvid->Description),
+                             "%s", fallback_cards[i].name);
                 found = TRUE;
                 break;
             }