Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation warnings (2) #210

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ INCLUDE(FindPkgConfig)
IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug)
ENDIF()
MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
IF (CMAKE_BUILD_TYPE=Debug)
ADD_DEFINITIONS(-DSTICK20_DEBUG)
ADD_DEFINITIONS(-DDEBUG_PRINTF)
ENDIF()
MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
ADD_DEFINITIONS(-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}")
ADD_DEFINITIONS(-DCMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER_ID}, ${CMAKE_CXX_COMPILER}")
ADD_DEFINITIONS(-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}")
Expand Down Expand Up @@ -299,6 +303,8 @@ ADD_EXECUTABLE(nitrokey-app ${GUI_TYPE}
${resources_ouput}
)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF) ## on g++ this ensures: -std=c++11
set_property(TARGET nitrokey-app PROPERTY CXX_STANDARD 11)

INSTALL(TARGETS nitrokey-app DESTINATION bin)
Expand Down
8 changes: 4 additions & 4 deletions src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,13 +657,13 @@ bool Device::is_HOTP_slot_number(const uint8_t slotNumber) const {
}

bool Device::is_secret320_supported() const {
return is_nk_pro() && get_major_firmware_version() >= 8 ||
is_nk_storage() && get_major_firmware_version() >= 44;
return (is_nk_pro() && get_major_firmware_version() >= 8) ||
(is_nk_storage() && get_major_firmware_version() >= 44);
}

bool Device::is_auth08_supported() const {
return is_nk_pro() && get_major_firmware_version() >= 8 ||
is_nk_storage() && get_major_firmware_version() >= 44;
return (is_nk_pro() && get_major_firmware_version() >= 8) ||
(is_nk_storage() && get_major_firmware_version() >= 44);
}

bool Device::is_TOTP_slot_number(const uint8_t slotNumber) const {
Expand Down
49 changes: 36 additions & 13 deletions src/response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,34 @@ void Response::DebugResponse() {
// responseCRC = ((uint32_t *)(reportBuffer+61))[0];
}

/*******************************************************************************

getResponse
#ifndef __WIN32
#define __packed __attribute__((packed))
#endif

#ifdef __WIN32
#define __packed
#pragma pack(push)
#pragma pack(1)
#endif

struct DeviceResponse{
union{
struct{
uint8_t _reserved;
uint8_t deviceStatus;
uint8_t lastCommandType;
uint32_t lastCommandCRC;
uint8_t lastCommandStatus;
uint8_t data[PAYLOAD_SIZE];
uint32_t responseCRC;
} __packed;
uint8_t rawData[65];
};
};
#ifdef __WIN32
#pragma pack(pop)
#endif

Reviews
Date Reviewer Info
12.08.13 RB First review

*******************************************************************************/
int Response::getResponse(Device *device) {
int res;

Expand All @@ -415,11 +434,15 @@ int Response::getResponse(Device *device) {
if (res == -1) {
return -1;
}
deviceStatus = reportBuffer[1];
lastCommandType = reportBuffer[2];
lastCommandCRC = reinterpret_cast<uint32_t *>(reportBuffer + 3)[0];
lastCommandStatus = reportBuffer[7];
responseCRC = reinterpret_cast<uint32_t *>(reportBuffer + 61)[0];
DeviceResponse response;
static_assert(sizeof(DeviceResponse) == sizeof(reportBuffer),
"response struct size not equal buffer size - please check pack instructions for your compiler");
memcpy (response.rawData, reportBuffer, sizeof(reportBuffer));
deviceStatus = response.deviceStatus;
lastCommandType = response.lastCommandType;
lastCommandCRC = response.lastCommandCRC;
lastCommandStatus = response.lastCommandStatus;
responseCRC = response.responseCRC;

size_t len = std::min(sizeof(data), sizeof(reportBuffer) - 8);
memcpy(data, reportBuffer + 8, len);
Expand Down
10 changes: 6 additions & 4 deletions src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3394,14 +3394,16 @@ void MainWindow::on_eraseButton_clicked() {
displayCurrentSlotConfig();
}

#include <memory>

void MainWindow::on_randomSecretButton_clicked() {
int i = 0;


int local_secret_length = get_supported_secret_length_base32();
uint8_t secret[local_secret_length];
const int local_secret_length = get_supported_secret_length_base32();
std::array<uint8_t, SECRET_LENGTH_BASE32> secret;

char temp;
uint8_t temp;

while (i < local_secret_length) {
temp = qrand() & 0xFF;
Expand All @@ -3411,7 +3413,7 @@ void MainWindow::on_randomSecretButton_clicked() {
}
}

QByteArray secretArray((char *)secret, local_secret_length);
QByteArray secretArray((char*)secret.data(), local_secret_length);

ui->base32RadioButton->setChecked(true);
ui->secretEdit->setText(secretArray);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/pindialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

PinDialog::PinDialog(const QString &title, const QString &label, Device *cryptostick, Usage usage,
PinType pinType, bool ShowMatrix, QWidget *parent)
: cryptostick(cryptostick), _usage(usage), _pinType(pinType), QDialog(parent),
ui(new Ui::PinDialog) {
: QDialog(parent), cryptostick(cryptostick), ui(new Ui::PinDialog), _usage(usage), _pinType(pinType)
{
ui->setupUi(this);

connect(ui->okButton, SIGNAL(clicked()), this, SLOT(onOkButtonClicked()));
Expand Down
5 changes: 4 additions & 1 deletion src/ui/stick20-response-task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ void Stick20ResponseTask::checkStick20Status() {
}
}

void Stick20ResponseTask::done(int Status) { EndFlag = TRUE; Status;}
void Stick20ResponseTask::done(int Status) {
EndFlag = TRUE;
(void)Status; //pretend to use, do not cut out for possible later use
}

void Stick20ResponseTask::GetResponse(void) {
int i;
Expand Down
8 changes: 3 additions & 5 deletions src/ui/stick20changepassworddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ int DialogChangePassword::CheckResponse(bool NoStopFlag) {
bool DialogChangePassword::SendNewPassword(void) {
bool communicationSuccess;
QByteArray PasswordString;
int password_length = STICK20_PASSOWRD_LEN;
constexpr int password_length = STICK20_PASSOWRD_LEN;
unsigned char Data[password_length + 2];

// Set kind of password
Expand Down Expand Up @@ -244,9 +244,8 @@ bool DialogChangePassword::SendNewPassword(void) {

bool DialogChangePassword::Stick10ChangePassword(void) {
int ret;
int password_length;
constexpr int password_length = STICK10_PASSWORD_LEN;
QByteArray PasswordString;
password_length = STICK10_PASSWORD_LEN;
unsigned char old_pin[password_length + 1];
unsigned char new_pin[password_length + 1];

Expand Down Expand Up @@ -350,9 +349,8 @@ bool DialogChangePassword::ResetUserPasswordStick10(void) {

bool DialogChangePassword::Stick20ChangeUpdatePassword(void) {
bool commandSuccess;
int password_length;
QByteArray PasswordString;
password_length = CS20_MAX_UPDATE_PASSWORD_LEN;
constexpr int password_length = CS20_MAX_UPDATE_PASSWORD_LEN;
unsigned char old_pin[password_length + 1];
unsigned char new_pin[password_length + 1];

Expand Down
4 changes: 1 addition & 3 deletions src/utils/hid_libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,6 @@ extern "C"

libusb_device* usb_dev;

ssize_t num_devs;

int res;

int d = 0;
Expand All @@ -883,7 +881,7 @@ extern "C"

hid_init ();

num_devs = libusb_get_device_list (usb_context, &devs);
libusb_get_device_list (usb_context, &devs);
while ((usb_dev = devs[d++]) != NULL)
{
struct libusb_device_descriptor desc;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/stick20hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ typeStick20ProductionInfos_st Stick20ProductionInfos_st;
#define CMAKE_CXX_FLAGS ""
#endif
#ifndef HAVE_LIBAPPINDICATOR
#define HAVE_LIBAPPINDICATOR "NO"
#define CMAKE_HAVE_LIBAPPINDICATOR "NO"
#else
#define CMAKE_HAVE_LIBAPPINDICATOR "YES"
#endif

/* forward declaration */
Expand All @@ -123,7 +125,7 @@ void initDebugging (void)
DebugAppendTextGui ("CMAKE_BUILD_TYPE " CMAKE_BUILD_TYPE "\n");
DebugAppendTextGui ("CMAKE_CXX_COMPILER " CMAKE_CXX_COMPILER "\n");
DebugAppendTextGui ("CMAKE_CXX_FLAGS " CMAKE_CXX_FLAGS "\n");
DebugAppendTextGui ("HAVE_LIBAPPINDICATOR: " HAVE_LIBAPPINDICATOR "\n");
DebugAppendTextGui ("HAVE_LIBAPPINDICATOR: " CMAKE_HAVE_LIBAPPINDICATOR "\n");

DebugAppendTextGui ((char *) "Start Debug - ");
#ifdef WIN32
Expand Down Expand Up @@ -223,8 +225,6 @@ void DebugAppendTimestampToLog (void)
{
char* OutputString;

char CrString[2] = "\n";

OutputString = GetTimeStampForLog ();

if (0 == strlen (OutputString))
Expand Down