Skip to content

Commit

Permalink
Fix cmdbuf->bool conversion
Browse files Browse the repository at this point in the history
Affected code was previously reading 3 uninitialized bytes, making the
conversion return wrong results.
  • Loading branch information
TuxSH committed Sep 7, 2024
1 parent faf5162 commit c5ecf54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions libctru/source/services/fspxi.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ Result FSPXI_HasFile(Handle serviceHandle, FSPXI_Archive archive, bool* out, FS_

if(R_FAILED(ret = svcSendSyncRequest(serviceHandle))) return ret;

if (out) *out = (bool)cmdbuf[2];
if (out) *out = (bool)(cmdbuf[2] & 1);

return (Result) cmdbuf[1];
}
Expand All @@ -396,7 +396,7 @@ Result FSPXI_HasDirectory(Handle serviceHandle, FSPXI_Archive archive, bool* out

if(R_FAILED(ret = svcSendSyncRequest(serviceHandle))) return ret;

if (out) *out = (bool)cmdbuf[2];
if (out) *out = (bool)(cmdbuf[2] & 1);

return (Result) cmdbuf[1];
}
Expand Down Expand Up @@ -441,7 +441,7 @@ Result FSPXI_Unknown0x17(Handle serviceHandle, FSPXI_Archive archive, bool* out)

if(R_FAILED(ret = svcSendSyncRequest(serviceHandle))) return ret;

if (out) *out = (bool)cmdbuf[2];
if (out) *out = (bool)(cmdbuf[2] & 1);

return (Result) cmdbuf[1];
}
Expand Down Expand Up @@ -523,7 +523,7 @@ Result FSPXI_IsSdmcDetected(Handle serviceHandle, bool* out)

if(R_FAILED(ret = svcSendSyncRequest(serviceHandle))) return ret;

if(out) *out = (bool)cmdbuf[2];
if(out) *out = (bool)(cmdbuf[2] & 1);

return (Result) cmdbuf[1];
}
Expand All @@ -537,7 +537,7 @@ Result FSPXI_IsSdmcWritable(Handle serviceHandle, bool* out)

if(R_FAILED(ret = svcSendSyncRequest(serviceHandle))) return ret;

if(out) *out = (bool)cmdbuf[2];
if(out) *out = (bool)(cmdbuf[2] & 1);

return (Result) cmdbuf[1];
}
Expand Down Expand Up @@ -663,7 +663,7 @@ Result FSPXI_CardSlotIsInserted(Handle serviceHandle, bool* inserted)

if(R_FAILED(ret = svcSendSyncRequest(serviceHandle))) return ret;

if(inserted) *inserted = (bool)cmdbuf[2];
if(inserted) *inserted = (bool)(cmdbuf[2] & 1);

return (Result) cmdbuf[1];
}
Expand All @@ -677,7 +677,7 @@ Result FSPXI_CardSlotPowerOn(Handle serviceHandle, bool* status)

if(R_FAILED(ret = svcSendSyncRequest(serviceHandle))) return ret;

if(status) *status = (bool)cmdbuf[2];
if(status) *status = (bool)(cmdbuf[2] & 1);

return (Result) cmdbuf[1];
}
Expand All @@ -691,7 +691,7 @@ Result FSPXI_CardSlotPowerOff(Handle serviceHandle, bool* status)

if(R_FAILED(ret = svcSendSyncRequest(serviceHandle))) return ret;

if(status) *status = (bool)cmdbuf[2];
if(status) *status = (bool)(cmdbuf[2] & 1);

return (Result) cmdbuf[1];
}
Expand All @@ -705,7 +705,7 @@ Result FSPXI_CardSlotGetCardIFPowerStatus(Handle serviceHandle, bool* status)

if(R_FAILED(ret = svcSendSyncRequest(serviceHandle))) return ret;

if(status) *status = (bool)cmdbuf[2];
if(status) *status = (bool)(cmdbuf[2] & 1);

return (Result) cmdbuf[1];
}
Expand Down
2 changes: 1 addition & 1 deletion libctru/source/services/ptmsysm.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Result PTMSYSM_CheckNew3DS(bool *out)
cmdbuf[0] = IPC_MakeHeader(0x040A,0,0); // 0x040A0000

if(R_FAILED(ret = svcSendSyncRequest(ptmSysmHandle)))return ret;
*out = (bool)cmdbuf[2]; // if cmdbuf[1] is != 0 then this is uninitialized (this is fine)
*out = (bool)(cmdbuf[2] & 1); // if cmdbuf[1] is != 0 then this is uninitialized (this is fine)

return (Result)cmdbuf[1];
}
Expand Down

0 comments on commit c5ecf54

Please sign in to comment.