mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-25 13:12:14 +00:00
* strncpy() refactor/fix
This commit is contained in:
@@ -55,8 +55,7 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
|
||||
putBlobByKey(id.pub_key, PUB_KEY_SIZE, temp_buf, plen);
|
||||
|
||||
// update
|
||||
strncpy(from->name, parser.getName(), sizeof(from->name)-1);
|
||||
from->name[sizeof(from->name)-1] = 0;
|
||||
StrHelper::strncpy(from->name, parser.getName(), sizeof(from->name));
|
||||
from->type = parser.getType();
|
||||
if (parser.hasLatLon()) {
|
||||
from->gps_lat = parser.getIntLat();
|
||||
|
||||
9
src/helpers/TxtDataHelpers.cpp
Normal file
9
src/helpers/TxtDataHelpers.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "TxtDataHelpers.h"
|
||||
|
||||
void StrHelper::strncpy(char* dest, const char* src, size_t buf_sz) {
|
||||
while (buf_sz > 1 && *src) {
|
||||
*dest++ = *src++;
|
||||
buf_sz--;
|
||||
}
|
||||
*dest = 0; // truncates if needed
|
||||
}
|
||||
@@ -6,3 +6,8 @@
|
||||
#define TXT_TYPE_PLAIN 0 // a plain text message
|
||||
#define TXT_TYPE_CLI_DATA 1 // a CLI command
|
||||
#define TXT_TYPE_SIGNED_PLAIN 2 // plain text, signed by sender
|
||||
|
||||
class StrHelper {
|
||||
public:
|
||||
static void strncpy(char* dest, const char* src, size_t buf_sz);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user