paolo-caroni / ps3mca-ps1

A program to read and write PS1 memory card with the Memory Card Adaptor CECHZM1 (SCPH-98042)
GNU General Public License v3.0
57 stars 10 forks source link

Improve argument parse behaviour #2

Closed ticky closed 7 years ago

ticky commented 7 years ago

This patch fixes some undefined behaviour in the argument parser. Previously, it was possible for the application to encounter a segmentation fault due to the *argv pointer floating into invalid memory. It also avoids segmentation faults from passing zero arguments.

The parser has been simplified to accept a single operation per program invocation, and as a consequence it no longer plays with pointer incrementation to operate!

I also shifted the ps3mca initialisation code into a function (mirroring close_ps3mca) and made it the responsibility of each individual operation's function to call it, and close_ps3mca. This means you don't have to wait for the ps3mca to be initialised (possibly failing in the process!) in order to get output from the argument parser.