Skip to contentSkip to conversation

staging: android: ion: Replace strncpy() for stracpy()

PATCH In review Adam Zerella 2 participants 2 messages Sep 8, 2019 – Sep 10, 2019 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: android: ion: Replace strncpy() for stracpy()

Using strncpy() does not always terminate the destination string. stracpy() is a alternative function that does, by using this new function we will no longer need to insert a null separator.

---
 drivers/staging/android/ion/ion.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/android/ion/ion.c +1 -2
index e6b1ca141b93..17901bd626be 100644
@@ -433,8 +433,7 @@ static int ion_query_heaps(struct ion_heap_query *query)
 	max_cnt = query->cnt;
 
 	plist_for_each_entry(heap, &dev->heaps, node) {
-		strncpy(hdata.name, heap->name, MAX_HEAP_NAME);
-		hdata.name[sizeof(hdata.name) - 1] = '\0';
+		stracpy(hdata.name, heap->name, MAX_HEAP_NAME);
 		hdata.type = heap->type;
 		hdata.heap_id = heap->id;
 
Signature · 1 line
2.21.0
#1 lore raw
Quoted 14 lines · Adam Zerella

Using strncpy() does not always terminate the destination string. stracpy() is a alternative function that does, by using this new function we will no longer need to insert a null separator.

---
 drivers/staging/android/ion/ion.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/android/ion/ion.c +0 -0
index e6b1ca141b93..17901bd626be 100644

drivers/staging/android/ion/ion.c static int ion_query_heaps(struct ion_heap_query *query) · line 436

Quoted 6 lines
drivers/staging/android/ion/ion.c +1 -2
@@ -433,8 +433,7 @@ static int ion_query_heaps(struct ion_heap_query *query)
 	max_cnt = query->cnt;
 
 	plist_for_each_entry(heap, &dev->heaps, node) {
-		strncpy(hdata.name, heap->name, MAX_HEAP_NAME);
-		hdata.name[sizeof(hdata.name) - 1] = '\0';
+		stracpy(hdata.name, heap->name, MAX_HEAP_NAME);

stracpy() only takes two arguments. This doesn't compile.

regards,
dan carpenter

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel