diff options
Diffstat (limited to 'member.cxx')
-rw-r--r-- | member.cxx | 32 |
1 files changed, 18 insertions, 14 deletions
@@ -126,24 +126,28 @@ namespace QInterchange { void Member::logIn(QString const& username, QString const& password, QString const& nextPage, QString const& failPage) { - auto unData = username.toLatin1().constData(); - unCopy = (char*)malloc(strlen(unData) + 1); - strcpy(unCopy, unData); - auto pwData = password.toLatin1().constData(); - pwCopy = (char*)malloc(strlen(pwData) + 1); - strcpy(pwCopy, pwData); - auto npData = nextPage.toLatin1().constData(); - npCopy = (char*)malloc(strlen(npData) + 1); - strcpy(npCopy, npData); - auto fpData = failPage.toLatin1().constData(); - fpCopy = (char*)malloc(strlen(fpData) + 1); - strcpy(fpCopy, fpData); + unCopy = (char*)malloc(username.size() + 1); + strcpy(unCopy, username.toLatin1().constData()); + pwCopy = (char*)malloc(password.size() + 1); + strcpy(pwCopy, password.toLatin1().constData()); + if (nextPage.isEmpty()) + npCopy = nullptr; + else { + npCopy = (char*)malloc(nextPage.size() + 1); + strcpy(npCopy, nextPage.toLatin1().constData()); + } + if (failPage.isEmpty()) + fpCopy = nullptr; + else { + fpCopy = (char*)malloc(failPage.size() + 1); + strcpy(fpCopy, failPage.toLatin1().constData()); + } interchange_member_login(unCopy, pwCopy, npCopy, fpCopy, [](interchange_response* response) { free(unCopy); free(pwCopy); - free(npCopy); - free(fpCopy); + if (npCopy) free(npCopy); + if (fpCopy) free(fpCopy); member->emitLogin(QString{response->data}); interchange_free_response(response); }, nullptr); |