Skip to content

Commit c5ecf54

Browse files
committed
Fix cmdbuf->bool conversion
Affected code was previously reading 3 uninitialized bytes, making the conversion return wrong results.
1 parent faf5162 commit c5ecf54

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

libctru/source/services/fspxi.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ Result FSPXI_HasFile(Handle serviceHandle, FSPXI_Archive archive, bool* out, FS_
376376

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

379-
if (out) *out = (bool)cmdbuf[2];
379+
if (out) *out = (bool)(cmdbuf[2] & 1);
380380

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

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

399-
if (out) *out = (bool)cmdbuf[2];
399+
if (out) *out = (bool)(cmdbuf[2] & 1);
400400

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

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

444-
if (out) *out = (bool)cmdbuf[2];
444+
if (out) *out = (bool)(cmdbuf[2] & 1);
445445

446446
return (Result) cmdbuf[1];
447447
}
@@ -523,7 +523,7 @@ Result FSPXI_IsSdmcDetected(Handle serviceHandle, bool* out)
523523

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

526-
if(out) *out = (bool)cmdbuf[2];
526+
if(out) *out = (bool)(cmdbuf[2] & 1);
527527

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

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

540-
if(out) *out = (bool)cmdbuf[2];
540+
if(out) *out = (bool)(cmdbuf[2] & 1);
541541

542542
return (Result) cmdbuf[1];
543543
}
@@ -663,7 +663,7 @@ Result FSPXI_CardSlotIsInserted(Handle serviceHandle, bool* inserted)
663663

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

666-
if(inserted) *inserted = (bool)cmdbuf[2];
666+
if(inserted) *inserted = (bool)(cmdbuf[2] & 1);
667667

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

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

680-
if(status) *status = (bool)cmdbuf[2];
680+
if(status) *status = (bool)(cmdbuf[2] & 1);
681681

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

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

694-
if(status) *status = (bool)cmdbuf[2];
694+
if(status) *status = (bool)(cmdbuf[2] & 1);
695695

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

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

708-
if(status) *status = (bool)cmdbuf[2];
708+
if(status) *status = (bool)(cmdbuf[2] & 1);
709709

710710
return (Result) cmdbuf[1];
711711
}

libctru/source/services/ptmsysm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Result PTMSYSM_CheckNew3DS(bool *out)
105105
cmdbuf[0] = IPC_MakeHeader(0x040A,0,0); // 0x040A0000
106106

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

110110
return (Result)cmdbuf[1];
111111
}

0 commit comments

Comments
 (0)