Skip to content

Commit

Permalink
[Python] Drop unnecessary null termination (project-chip#33915)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
agners committed Jun 14, 2024
1 parent 18903b3 commit 6842912
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/controller/python/chip/ChipDeviceCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ def DiscoverCommissionableNodes(self, filterType: discovery.FilterType = discove

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

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

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

setupPayload = setupPayload.encode() + b'\0'

self._commissioning_complete_future = concurrent.futures.Future()

try:
self._enablePairingCompeleteCallback(True)
self._ChipStack.Call(
lambda: self._dmLib.pychip_DeviceController_ConnectWithCode(
self.devCtrl, setupPayload, nodeid, discoveryType.value)
self.devCtrl, setupPayload.encode("utf-8"), nodeid, discoveryType.value)
).raise_on_error()

return self._commissioning_complete_future.result()
Expand Down

0 comments on commit 6842912

Please sign in to comment.