Skip to content

fix: strtok writes into const string buffer from c_str() - #11

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:bugfix/fmpm-strtok-writes-into-const-string-buffer
Open

fix: strtok writes into const string buffer from c_str()#11
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:bugfix/fmpm-strtok-writes-into-const-string-buffer

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

This PR addresses the following issue in fmpm.cpp: strtok writes into const string buffer from c_str().

Changes

  • fmpm.cpp: strtok writes into const string buffer from c_str().

Details

--- a/fmpm.cpp
+++ b/fmpm.cpp
@@ -1,6 +1,7 @@
 #include <iostream>
 #include <string.h>
+#include <vector>
 #include <json/json.h>
 #include "nv_fm_agent.h"
 
@@ -40,7 +41,8 @@
 fmReturn_t
 parsePartitionIdlistString(std::string & partitionListStr, unsigned int * partitionIds, unsigned * numPartitions)
 {
-    char * token = strtok((char *)partitionListStr.c_str(), ",");
+    std::vector<char> mutableCopy(partitionListStr.c_str(), partitionListStr.c_str() + partitionListStr.length() + 1);
+    char * token = strtok(mutableCopy.data(), ",");
     int haveSeen[FM_MAX_FABRIC_PARTITIONS] = { 0 };

Tests

Let me know if you want tests added for this fix or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant