From a31ac990cc82daeccd7c8deb39e0c634643418fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sat, 4 May 2013 13:41:26 +0200 Subject: [PATCH] Diskprobe: some 64 bit fixes * also warnings about comparisons between signed and non signed. --- src/apps/diskprobe/DataEditor.cpp | 18 +++++++++------ src/apps/diskprobe/DataView.cpp | 12 +++++----- src/apps/diskprobe/ProbeView.cpp | 36 ++++++++++++++++++------------ src/apps/diskprobe/TypeEditors.cpp | 20 ++++++++--------- 4 files changed, 49 insertions(+), 37 deletions(-) diff --git a/src/apps/diskprobe/DataEditor.cpp b/src/apps/diskprobe/DataEditor.cpp index 2fd85a28df..72701cfbd6 100644 --- a/src/apps/diskprobe/DataEditor.cpp +++ b/src/apps/diskprobe/DataEditor.cpp @@ -236,8 +236,10 @@ void ReplaceChange::Apply(off_t bufferOffset, uint8 *buffer, size_t bufferSize) { // is it in our range? - if (fOffset > bufferOffset + bufferSize || fOffset + fSize < bufferOffset) + if (fOffset > (bufferOffset + (off_t)bufferSize) + || (fOffset + (off_t)fSize) < bufferOffset) { return; + } // don't change anything outside the supplied buffer off_t offset = fOffset; @@ -263,8 +265,10 @@ void ReplaceChange::Revert(off_t bufferOffset, uint8 *buffer, size_t bufferSize) { // is it in our range? - if (fOffset - bufferOffset > bufferSize || fOffset + fSize < bufferOffset) + if ((fOffset - bufferOffset) > (off_t)bufferSize + || (fOffset + (off_t)fSize) < bufferOffset) { return; + } // don't change anything outside the supplied buffer off_t offset = fOffset; @@ -307,8 +311,8 @@ ReplaceChange::Merge(DataChange *_change) // are the changes adjacent? - if (change->fOffset + change->fSize != fOffset - && fOffset + fSize != change->fOffset) + if ((change->fOffset + (off_t)change->fSize) != fOffset + && (fOffset + (off_t)fSize) != change->fOffset) return false; // okay, we can try to merge the two changes @@ -560,7 +564,7 @@ DataEditor::Replace(off_t offset, const uint8 *data, size_t length) if (offset >= fSize) return B_BAD_VALUE; - if (offset + length > fSize) + if ((offset + (off_t)length) > fSize) length = fSize - offset; if (fNeedsUpdate) { @@ -705,7 +709,7 @@ DataEditor::Save() // don't try to change the file size size_t size = fRealViewSize; - if (fRealViewOffset + fRealViewSize > fSize) + if ((fRealViewOffset + (off_t)fRealViewSize) > (off_t)fSize) size = fSize - fRealViewOffset; ssize_t bytesWritten; @@ -1125,7 +1129,7 @@ DataEditor::Find(off_t startPosition, const uint8 *data, size_t dataSize, } for (size_t i = firstByte; i < fRealViewSize; i++) { - if (position + i + dataSize > fSize) + if (position + (off_t)(i + dataSize) > (off_t)fSize) break; if (!compareFunc(fView + i, data, 1)) { diff --git a/src/apps/diskprobe/DataView.cpp b/src/apps/diskprobe/DataView.cpp index bd01742cd8..59589437ad 100644 --- a/src/apps/diskprobe/DataView.cpp +++ b/src/apps/diskprobe/DataView.cpp @@ -163,19 +163,19 @@ DataView::UpdateFromEditor(BMessage *message) if (message != NULL && message->FindInt64("offset", &offset) == B_OK && message->FindInt64("size", &size) == B_OK) { - if (offset > fOffset + fDataSize - || offset + size < fOffset) { + if (offset > fOffset + (off_t)fDataSize + || offset + (off_t)size < fOffset) { // the changes are not within our scope, so we can ignore them return; } if (offset > fOffset) start = offset - fOffset; - if (offset + size < fOffset + fDataSize) + if (offset + (off_t)size < fOffset + (off_t)fDataSize) end = offset + size - fOffset; } - if (fOffset + fDataSize > fFileSize) + if (fOffset + (off_t)fDataSize > fFileSize) fSizeInView = fFileSize - fOffset; else fSizeInView = fDataSize; @@ -356,8 +356,8 @@ DataView::ConvertLine(char *line, off_t offset, const uint8 *buffer, size_t size return; } - line += sprintf(line, fBase == kHexBase ? "%0*Lx: " : "%0*Ld: ", - (int)fPositionLength, offset); + line += sprintf(line, fBase == kHexBase ? "%0*" B_PRIxOFF": " : "%0*" + B_PRIdOFF": ", (int)fPositionLength, offset); for (uint32 i = 0; i < kBlockSize; i++) { if (i >= size) { diff --git a/src/apps/diskprobe/ProbeView.cpp b/src/apps/diskprobe/ProbeView.cpp index 2aef09dcaa..943889fcd6 100644 --- a/src/apps/diskprobe/ProbeView.cpp +++ b/src/apps/diskprobe/ProbeView.cpp @@ -216,7 +216,7 @@ get_type_string(char *buffer, size_t bufferSize, type_code type) for (int32 i = 0; i < 4; i++) { buffer[i] = type >> (24 - 8 * i); if (buffer[i] < ' ' || buffer[i] == 0x7f) { - snprintf(buffer, bufferSize, "0x%04lx", type); + snprintf(buffer, bufferSize, "0x%04" B_PRIx32, type); break; } else if (i == 3) buffer[4] = '\0'; @@ -705,7 +705,8 @@ HeaderView::UpdateIcon() void HeaderView::FormatValue(char *buffer, size_t bufferSize, off_t value) { - snprintf(buffer, bufferSize, fBase == kHexBase ? "0x%Lx" : "%Ld", value); + snprintf(buffer, bufferSize, fBase == kHexBase ? "0x%" B_PRIxOFF : "%" + B_PRIdOFF, value); } @@ -1550,7 +1551,7 @@ ProbeView::AttachedToWindow() const uint32 blockSizes[] = {512, 1024, 2048}; for (uint32 i = 0; i < sizeof(blockSizes) / sizeof(blockSizes[0]); i++) { char buffer[32]; - snprintf(buffer, sizeof(buffer), "%ld%s", blockSizes[i], + snprintf(buffer, sizeof(buffer), "%" B_PRId32 "%s", blockSizes[i], fEditor.IsDevice() && fEditor.BlockSize() == blockSizes[i] ? B_TRANSLATE(" (native)") : ""); subMenu->AddItem(item = new BMenuItem(buffer, @@ -1582,7 +1583,7 @@ ProbeView::AttachedToWindow() fontSize = 0; for (uint32 i = 0; i < sizeof(fontSizes) / sizeof(fontSizes[0]); i++) { char buffer[16]; - snprintf(buffer, sizeof(buffer), "%ld", fontSizes[i]); + snprintf(buffer, sizeof(buffer), "%" B_PRId32, fontSizes[i]); subMenu->AddItem(item = new BMenuItem(buffer, message = new BMessage(kMsgFontSize))); message->AddFloat("font_size", fontSizes[i]); @@ -1653,23 +1654,30 @@ ProbeView::_UpdateSelectionMenuItems(int64 start, int64 end) // update menu items char buffer[128]; - if (fDataView->Base() == kHexBase) - snprintf(buffer, sizeof(buffer), B_TRANSLATE("Native: 0x%0*Lx"), size * 2, position); - else - snprintf(buffer, sizeof(buffer), B_TRANSLATE("Native: %Ld (0x%0*Lx)"), position, size * 2, position); + if (fDataView->Base() == kHexBase) { + snprintf(buffer, sizeof(buffer), B_TRANSLATE("Native: 0x%0*Lx"), + size * 2, position); + } else { + snprintf(buffer, sizeof(buffer), B_TRANSLATE("Native: %Ld (0x%0*Lx)"), + position, size * 2, position); + } fNativeMenuItem->SetLabel(buffer); - fNativeMenuItem->SetEnabled(position >= 0 && (position * fEditor.BlockSize()) < fEditor.FileSize()); + fNativeMenuItem->SetEnabled(position >= 0 + && (off_t)(position * fEditor.BlockSize()) < fEditor.FileSize()); fNativeMenuItem->Message()->ReplaceInt64("block", position); position = B_SWAP_INT64(position) >> (8 * (8 - size)); - if (fDataView->Base() == kHexBase) - snprintf(buffer, sizeof(buffer), B_TRANSLATE("Swapped: 0x%0*Lx"), size * 2, position); - else - snprintf(buffer, sizeof(buffer), B_TRANSLATE("Swapped: %Ld (0x%0*Lx)"), position, size * 2, position); + if (fDataView->Base() == kHexBase) { + snprintf(buffer, sizeof(buffer), B_TRANSLATE("Swapped: 0x%0*Lx"), + size * 2, position); + } else { + snprintf(buffer, sizeof(buffer), B_TRANSLATE("Swapped: %Ld (0x%0*Lx)"), + position, size * 2, position); + } fSwappedMenuItem->SetLabel(buffer); - fSwappedMenuItem->SetEnabled(position >= 0 && (position * fEditor.BlockSize()) < fEditor.FileSize()); + fSwappedMenuItem->SetEnabled(position >= 0 && (off_t)(position * fEditor.BlockSize()) < fEditor.FileSize()); fSwappedMenuItem->Message()->ReplaceInt64("block", position); } diff --git a/src/apps/diskprobe/TypeEditors.cpp b/src/apps/diskprobe/TypeEditors.cpp index 2183ff81c2..39bfbf8cb2 100644 --- a/src/apps/diskprobe/TypeEditors.cpp +++ b/src/apps/diskprobe/TypeEditors.cpp @@ -226,7 +226,7 @@ StringEditor::_UpdateText() size_t viewSize = fEditor.ViewSize(); // that may need some more memory... - if (viewSize < fEditor.FileSize()) + if ((off_t)viewSize < fEditor.FileSize()) fEditor.SetViewSize(fEditor.FileSize()); const char *buffer; @@ -486,7 +486,7 @@ NumberEditor::_UpdateText() bool NumberEditor::TypeMatches() { - return fEditor.FileSize() >= _Size(); + return fEditor.FileSize() >= (off_t)_Size(); // we only look at as many bytes we need to } @@ -949,7 +949,7 @@ ImageView::_UpdateImage() size_t viewSize = fEditor.ViewSize(); // that may need some more memory... - if (viewSize < fEditor.FileSize()) + if ((off_t)viewSize < fEditor.FileSize()) fEditor.SetViewSize(fEditor.FileSize()); const char *data; @@ -1169,7 +1169,7 @@ MessageView::_TypeToString(type_code type) for (int32 i = 0; i < 4; i++) { text[i] = type >> (24 - 8 * i); if (text[i] < ' ' || text[i] == 0x7f) { - snprintf(text, sizeof(text), "0x%04lx", type); + snprintf(text, sizeof(text), "0x%04" B_PRIx32, type); break; } else if (i == 3) text[4] = '\0'; @@ -1226,16 +1226,16 @@ MessageView::SetTo(BMessage& message) switch (type) { case B_INT64_TYPE: - snprintf(text, sizeof(text), "%Ld", *(int64*)data); + snprintf(text, sizeof(text), "%" B_PRId64, *(int64*)data); break; case B_UINT64_TYPE: - snprintf(text, sizeof(text), "%Lu", *(uint64*)data); + snprintf(text, sizeof(text), "%" B_PRIu64, *(uint64*)data); break; case B_INT32_TYPE: - snprintf(text, sizeof(text), "%ld", *(int32*)data); + snprintf(text, sizeof(text), "%" B_PRId32, *(int32*)data); break; case B_UINT32_TYPE: - snprintf(text, sizeof(text), "%lu", *(uint32*)data); + snprintf(text, sizeof(text), "%" B_PRIu32, *(uint32*)data); break; case B_BOOL_TYPE: if (*(uint8*)data) @@ -1255,7 +1255,7 @@ MessageView::SetTo(BMessage& message) fTextView->Insert("\t\t"); if (count > 1) { char index[16]; - snprintf(index, sizeof(index), "%ld.\t", j); + snprintf(index, sizeof(index), "%" B_PRId32 ".\t", j); fTextView->Insert(index); } fTextView->Insert(text); @@ -1273,7 +1273,7 @@ MessageView::_UpdateMessage() size_t viewSize = fEditor.ViewSize(); // that may need some more memory... - if (viewSize < fEditor.FileSize()) + if ((off_t)viewSize < fEditor.FileSize()) fEditor.SetViewSize(fEditor.FileSize()); const char *buffer;