summaryrefslogtreecommitdiff
path: root/member.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'member.cxx')
-rw-r--r--member.cxx32
1 files changed, 18 insertions, 14 deletions
diff --git a/member.cxx b/member.cxx
index 175a355..a346d74 100644
--- a/member.cxx
+++ b/member.cxx
@@ -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);