Skip to content

Commit 6842912

Browse files
authored
[Python] Drop unnecessary null termination (#33915)
The ctypes data type `c_char_p` takes care of null-terminating the byte array provided to it. The additional null termination doesn't hurt in practice, but it's unnecessary.
1 parent 18903b3 commit 6842912

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/controller/python/chip/ChipDeviceCtrl.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ def DiscoverCommissionableNodes(self, filterType: discovery.FilterType = discove
732732

733733
self._ChipStack.Call(
734734
lambda: self._dmLib.pychip_DeviceController_DiscoverCommissionableNodes(
735-
self.devCtrl, int(filterType), str(filter).encode("utf-8") + b"\x00")).raise_on_error()
735+
self.devCtrl, int(filterType), str(filter).encode("utf-8"))).raise_on_error()
736736

737737
if timeoutSecond != 0:
738738
if stopOnFirst:
@@ -2019,7 +2019,7 @@ def CommissionOnNetwork(self, nodeId: int, setupPinCode: int,
20192019
self._enablePairingCompeleteCallback(True)
20202020
self._ChipStack.Call(
20212021
lambda: self._dmLib.pychip_DeviceController_OnNetworkCommission(
2022-
self.devCtrl, self.pairingDelegate, nodeId, setupPinCode, int(filterType), str(filter).encode("utf-8") + b"\x00" if filter is not None else None, discoveryTimeoutMsec)
2022+
self.devCtrl, self.pairingDelegate, nodeId, setupPinCode, int(filterType), str(filter).encode("utf-8") if filter is not None else None, discoveryTimeoutMsec)
20232023
).raise_on_error()
20242024

20252025
return self._commissioning_complete_future.result()
@@ -2032,15 +2032,13 @@ def CommissionWithCode(self, setupPayload: str, nodeid: int, discoveryType: Disc
20322032
'''
20332033
self.CheckIsActive()
20342034

2035-
setupPayload = setupPayload.encode() + b'\0'
2036-
20372035
self._commissioning_complete_future = concurrent.futures.Future()
20382036

20392037
try:
20402038
self._enablePairingCompeleteCallback(True)
20412039
self._ChipStack.Call(
20422040
lambda: self._dmLib.pychip_DeviceController_ConnectWithCode(
2043-
self.devCtrl, setupPayload, nodeid, discoveryType.value)
2041+
self.devCtrl, setupPayload.encode("utf-8"), nodeid, discoveryType.value)
20442042
).raise_on_error()
20452043

20462044
return self._commissioning_complete_future.result()

0 commit comments

Comments
 (0)