I was following http://code.google.com/p/dart/wiki/BuildingDartium#Build and attempted to build dartium in Release mode and encountered the following error:
$ ./dartium_tools/build.py --mode=Release
.
.
.
CXX(target) out/Release/obj.target/webrtc_video_coding/third_party/webrtc/modules/video_coding/main/source/rtt_filter.o
CXX(target) out/Release/obj.target/webrtc_video_coding/third_party/webrtc/modules/video_coding/main/source/session_info.o
CXX(target) out/Release/obj.target/webrtc_video_coding/third_party/webrtc/modules/video_coding/main/source/timestamp_extrapolator.o
third_party/webrtc/modules/video_coding/main/source/session_info.cc: In member function ‘int webrtc::VCMSessionInfo::PrepareForDecode(uint8_t*)’:
third_party/webrtc/modules/video_coding/main/source/session_info.cc:590:8: error: variable ‘previous_lost’ set but not used [-Werror=unused-but-set-variable]
cc1plus: all warnings being treated as errors
make: *** [out/Release/obj.target/webrtc_video_coding/third_party/webrtc/modules/video_coding/main/source/session_info.o] Error 1
make: *** Waiting for unfinished jobs....
Traceback (most recent call last):
File "./dartium_tools/build.py", line 67, in <module>
main()
File "./dartium_tools/build.py", line 64, in main
[target for (target, _) in targets])
File "/home/sangeeth/work/g/dartium/src/dartium_tools/utils.py", line 97, in runCommand
raise Exception('Failed to run command. return code=%s' % p.returncode)
Exception: Failed to run command. return code=2
$
But when I looked at the code dartium/src/third_party/webrtc/modules/video_coding/main/source/session_info.cc::VCMSessionInfo::PrepareForDecode(), I saw the following:
int VCMSessionInfo::PrepareForDecode(uint8_t* frame_buffer) {
int length = SessionLength();
int real_data_bytes = 0;
if (length == 0)
return length;
bool previous_lost = false;
PacketIterator it = packets_.begin();
PacketIterator prev_it = it;
for (; it != packets_.end(); ++it) {
bool packet_loss = ((*prev_it).sizeBytes == 0 ||
!InSequence(it, prev_it));
if ((*it).bits) {
if (prev_it != it) { // Not the first packet.
uint8_t* ptr_first_byte =
const_cast<uint8_t*>((*it).dataPtr);
if (packet_loss) {
// It is be better to throw away this packet if we are
// missing the previous packet.
memset(ptr_first_byte, 0, (*it).sizeBytes);
previous_lost = true;
++packets_not_decodable_;
} else if ((*it).sizeBytes > 0) {
// Glue with previous byte.
// Move everything from [this packet start + 1, end of buffer] one
// byte to the left.
uint8_t* ptr_prev_byte =
const_cast<uint8_t*>((*prev_it).dataPtr) +
(*prev_it).sizeBytes - 1;
*ptr_prev_byte = (*ptr_prev_byte) | (*ptr_first_byte);
memmove(const_cast<uint8_t*>((*it).dataPtr),
(*it).dataPtr + 1, (*it).sizeBytes - 1);
ShiftSubsequentPackets(it, -1);
(*it).sizeBytes--;
length--;
previous_lost = false;
real_data_bytes += (*it).sizeBytes;
}
} else {
memset(const_cast<uint8_t*>((*it).dataPtr), 0,
(*it).sizeBytes);
previous_lost = true;
++packets_not_decodable_;
}
} else if (packet_loss &&
(*it).codecSpecificHeader.codec == kRTPVideoH263) {
// Pad H.263 packet losses with 10 zeros to make it easier
// for the decoder.
const int kPaddingLength = 10;
WebRtc_UWord8 padding_data[kPaddingLength] = {0};
// Make a copy of the previous packet.
VCMPacket padding_packet(*it);
++padding_packet.seqNum;
padding_packet.dataPtr = padding_data;
padding_packet.sizeBytes = kPaddingLength;
length += InsertPacket(padding_packet, frame_buffer, false, 0);
previous_lost = true;
} else {
real_data_bytes += (*it).sizeBytes;
previous_lost = false;
}
prev_it = it;
}
if (real_data_bytes == 0) {
// Drop the frame since all it contains are zeros.
for (it = packets_.begin(); it != packets_.end(); ++it)
(*it).sizeBytes = 0;
length = 0;
}
return length;
}
The bool variable previous_lost has been used (set to false and true) at many places.
Any valuable input on how to go about this would be a great help.
Setting a bool to true or false is pointless if you don't then read the value later - in the code you posted, a value for previous_lost is indeed set in several places, but nowhere is the value that's set used to do anything (such as a if (previous_lost) ..., for example). That's what's meant by "used" in this context: a variable is used if its value is read.
Note that this (generally) applies for any type of variable: if I set an int to 42 and don't use it any later calculation, it's not "used" either.
In these cases, the variable is completely redundant - it does nothing useful since it is not used by other code. Generally this kind of warning is meant to indicate that perhaps the code that was supposed to use previous_lost was accidentally omitted (or was removed) and needs to be accounted for. Alternatively, the variable might simply be redundant and can be removed entirely.
Related
I know, I know - that question title is very much all over the place. However, I am not sure what could be an issue here that is causing what I am witnessing.
I have the following method in class Project that is being unit tested:
bool Project::DetermineID(std::string configFile, std::string& ID)
{
std::ifstream config;
config.open(configFile);
if (!config.is_open()) {
WARNING << "Failed to open the configuration file for processing ID at: " << configFile;
return false;
}
std::string line = "";
ID = "";
bool isConfigurationSection = false;
bool isConfiguration = false;
std::string tempID = "";
while (std::getline(config, line))
{
std::transform(line.begin(), line.end(), line.begin(), ::toupper); // transform the line to all capital letters
boost::trim(line);
if ((line.find("IDENTIFICATIONS") != std::string::npos) && (!isConfigurationSection)) {
// remove the "IDENTIFICATIONS" part from the current line we're working with
std::size_t idStartPos = line.find("IDENTIFICATIONS");
line = line.substr(idStartPos + strlen("IDENTIFICATIONS"), line.length() - idStartPos - strlen("IDENTIFICATIONS"));
boost::trim(line);
isConfigurationSection = true;
}
if ((line.find('{') != std::string::npos) && isConfigurationSection) {
std::size_t bracketPos = line.find('{');
// we are working within the ids configuration section
// determine if this is the first character of the line, or if there is an ID that precedes the {
if (bracketPos == 0) {
// is the first char
// remove the bracket and keep processing
line = line.substr(1, line.length() - 1);
boost::trim(line);
}
else {
// the text before { is a temp ID
tempID = line.substr(0, bracketPos - 1);
isConfiguration = true;
line = line.substr(bracketPos, line.length() - bracketPos);
boost::trim(line);
}
}
if ((line.find("PORT") != std::string::npos) && isConfiguration) {
std::size_t indexOfEqualSign = line.find('=');
if (indexOfEqualSign == std::string::npos) {
WARNING << "Unable to determine the port # assigned to " << tempID;
}
else {
std::string portString = "";
portString = line.substr(indexOfEqualSign + 1, line.length() - indexOfEqualSign - 1);
boost::trim(portString);
// confirm that the obtained port string is not an empty value
if (portString.empty()) {
WARNING << "Failed to obtain the \"Port\" value that is set to " << tempID;
}
else {
// attempt to convert the string to int
int workingPortNum = 0;
try {
workingPortNum = std::stoi(portString);
}
catch (...) {
WARNING << "Failed to convert the obtained \"Port\" value that is set to " << tempID;
}
if (workingPortNum != 0) {
// check if this port # is the same port # we are publishing data on
if (workingPortNum == this->port) {
ID = tempID;
break;
}
}
}
}
}
}
config.close();
if (ID.empty())
return false;
else
return true;
}
The goal of this method is to parse any text file for the ID portion, based on matching the port # that the application is publishing data to.
Format of the file is like this:
Idenntifications {
ID {
port = 1001
}
}
In a separate Visual Studio project that unit tests various methods, including this Project::DetermineID method.
#define STRINGIFY(x) #x
#define EXPAND(x) STRINGIFY(x)
TEST_CLASS(ProjectUnitTests) {
Project* parser;
std::string projectDirectory;
TEST_METHOD_INITIALIZE(ProjectUnitTestInitialization) {
projectDirectory = EXPAND(UNITTESTPRJ);
projectDirectory.erase(0, 1);
projectDirectory.erase(projectDirectory.size() - 2);
parser = Project::getClass(); // singleton method getter/initializer
}
// Other test methods are present and pass/fail accordingly
TEST_METHOD(DetermineID) {
std::string ID = "";
bool x = parser ->DetermineAdapterID(projectDirectory + "normal.cfg", ID);
Assert::IsTrue(x);
}
};
Now, when I run the tests, DetermineID fails and the stack trace states:
DetermineID
Source: Project Tests.cpp line 86
Duration: 2 sec
Message:
Assert failed
Stack Trace:
ProjectUnitTests::DetermineID() line 91
Now, in my test .cpp file, TEST_METHOD(DetermineID) { is present on line 86. But that method's } is located on line 91, as the stack trace indicates.
And, when debugging, the unit test passes, because the return of x in the TEST_METHOD is true.
Only when running the test individually or running all tests does that test method fail.
Some notes that may be relevant:
This is a single-threaded application with no tasks scheduled (no race condition to worry about supposedly)
There is another method in the Project class that also processes a file with an std::ifstream same as this method does
That method has its own test method that has been written and passes without any problems
The test method also access the "normal.cfg" file
Yes, this->port has an assigned value
Thus, my questions are:
Why does the stack trace reference the closing bracket for the test method instead of the single Assert within the method that is supposedly failing?
How to get the unit test to pass when it is ran? (Since it currently only plasses during debugging where I can confirm that x is true).
If the issue is a race condition where perhaps the other test method is accessing the "normal.cfg" file, why does the test method fail even when the method is individually ran?
Any support/assistance here is very much appreciated. Thank you!
My program (which uses libgit2) makes a commit to local repo (no push, only commit), then does something and then, according to the result, tries to revert the last commit by resetting repo to HEAD~1 (one commit before HEAD). Simply hard reset.
The problem: the code below does reset HEAD to HEAD~1, but leaves all changes between these 2 commit as "staged", while I need to simply erase these changes. What am I doing wrong?
bool RevertLastCommit(std::string &errorMessage)
{
int error;
git_object *head_commit_obj = nullptr;
error = git_revparse_single(&head_commit_obj, repo, "HEAD~1");
if (error < 0)
{
return false;
}
git_commit *head_commit = (git_commit *)head_commit_obj;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
int reset_result = git_reset(repo, const_cast<git_object *>(head_commit_obj), GIT_RESET_HARD, &opts);
if (reset_result < 0) {
printf("Reset failed!\n");
return false;
}
printf("Done reverting\n");
error = git_checkout_head(repo, &opts);
if (error < 0)
{
return false;
}
printf("Hard checkout\n");
return true;
}
I'm currently trying to process the absolute value of a drawing tablet's touch ring, through the Wintab API. However, despite following instructions as they are described in the documentation, it seems like the WTOpen call doesn't set any extension settings. Using the touch ring after initializing Wintab still triggers the default events, while the default events for pen inputs are suppressed and all pen inputs related to my application instead.
Here are the relevant segments of code:
...
#include "wintab.h"
#define PACKETDATA (PK_X | PK_Y | PK_Z | PK_NORMAL_PRESSURE | PK_ORIENTATION | PK_TIME | PK_BUTTONS)
#define PACKETMODE 0
#define PACKETTOUCHSTRIP PKEXT_ABSOLUTE
#define PACKETTOUCHRING PKEXT_ABSOLUTE
#include "pktdef.h"
...
internal b32
InitWinTab(HWND Window, window_mapping *Map)
{
if(!LoadWintabFunctions())
return false;
LOGCONTEXT Tablet;
AXIS TabletX, TabletY, TabletZ, Pressure;
if(!gpWTInfoA(WTI_DEFCONTEXT, 0, &Tablet))
return false;
gpWTInfoA(WTI_DEVICES, DVC_X, &TabletX);
gpWTInfoA(WTI_DEVICES, DVC_Y, &TabletY);
gpWTInfoA(WTI_DEVICES, DVC_Z, &TabletZ);
gpWTInfoA(WTI_DEVICES, DVC_NPRESSURE, &Pressure);
UINT TouchStripOffset = 0xFFFF;
UINT TouchRingOffset = 0xFFFF;
for(UINT i = 0, ScanTag = 0; gpWTInfoA(WTI_EXTENSIONS + i, EXT_TAG, &ScanTag); i++)
{
if (ScanTag == WTX_TOUCHSTRIP)
TouchStripOffset = i;
if (ScanTag == WTX_TOUCHRING)
TouchRingOffset = i;
}
Tablet.lcOptions |= CXO_MESSAGES;
Tablet.lcPktData = PACKETDATA;
Tablet.lcPktMode = PACKETMODE;
Tablet.lcMoveMask = PACKETDATA;
Tablet.lcBtnUpMask = Tablet.lcBtnDnMask;
Tablet.lcInOrgX = 0;
Tablet.lcInOrgY = 0;
Tablet.lcInExtX = TabletX.axMax;
Tablet.lcInExtY = TabletY.axMax;
if(TouchStripOffset != 0xFFFF)
{
WTPKT DataMask;
gpWTInfoA(WTI_EXTENSIONS + TouchStripOffset, EXT_MASK, &DataMask);
Tablet.lcPktData |= DataMask;
}
if(TouchRingOffset != 0xFFFF)
{
WTPKT DataMask;
gpWTInfoA(WTI_EXTENSIONS + TouchRingOffset, EXT_MASK, &DataMask);
Tablet.lcPktData |= DataMask;
}
Map->AxisMax.x = (r32)TabletX.axMax;
Map->AxisMax.y = (r32)TabletY.axMax;
Map->AxisMax.z = (r32)TabletZ.axMax;
Map->PressureMax = (r32)Pressure.axMax;
if(!gpWTOpenA(Window, &Tablet, TRUE))
return false;
return(TabletX.axMax && TabletY.axMax && TabletZ.axMax && Pressure.axMax);
}
...
case WT_PACKET:
{
PACKET Packet;
if(gpWTPacket((HCTX)LParam, (UINT)WParam, &Packet))
{
...
}
} break;
case WT_PACKETEXT:
{
PACKETEXT Packet;
if(gpWTPacket((HCTX)LParam, (UINT)WParam, &Packet))
{
...
}
} break;
...
The bitmask for the packet data in the initialization have sensible bits set for both extensions and don't overlap with the existing bitmask. No stage of the initialization fails. WT_PACKET gets called only with valid packet data while WT_PACKETEXT never gets called. Furthermore, calling WTPacketsGet with a PACKETEXT pointer on the HCTX returned by WTOpen fills the packet with garbage from the regular packet queue. This leaves me with the conclusion that somehow WTOpen didn't receive notification that the extensions should be loaded and I'm unable to find what else I should define in the LOGCONTEXT data structure to change that.
Is there a mistake in my initialization? Or is there a way to get a better readout to why the extensions didn't load?
It turned out that a driver setting prevented the extension packets from being sent, in favor of using the touch ring for different function. Changing this setting resolved the issue. The code didn't contain any errors itself.
I have a problem caused by this code:
char KernelFS::mount(Partition* part) {
WaitForSingleObject(mutexFS,INFINITE);
int pos;
for(pos=0; pos<26; pos++)
if(mountedPartitions[pos] == 0)
break;
if(pos < 26) {
mountedPartitions[pos] = part;
bitVectors[pos] = new BitVector(part);
fileEvidention[pos] = new ListHandler();
openedFiles[pos] = 0;
forbidOpening[pos] = false;
ReleaseMutex(mutexFS);
return intToChar(pos);
}
else {
ReleaseMutex(mutexFS);
return '0';
}
}
and
char KernelFS::format(char part){
WaitForSingleObject(mutexFS,INFINITE);
forbidOpening[charToInt(part)] = true;
ReleaseMutex(mutexFS);
while(openedFiles[charToInt(part)]>0)
WaitForSingleObject(unmountSem,INFINITE);
WaitForSingleObject(mutexFS,INFINITE);
// write fresh bit vector to cluster 0 of partition
bitVectors[charToInt(part)]->formatBitVector();
openedFiles[charToInt(part)] = 0;
forbidOpening[charToInt(part)] = false;
delete fileEvidention; //!!***!!
fileEvidention[charToInt(part)] = new ListHandler();
// some other stuff, irrelevant
ReleaseMutex(mutexFS);
return 1;
}
There are 3 thread executing, 1 is blocked and two are running through this code;
they first call mount, then format (each has its own argument Partition object, p1 and p2).
The first time mount is called, it always goes through - then there is an assertion failure at random during one of the next calls of mount/format by any of the two running threads.
Usually, it fails during thread 1 - it calls mount(..) completes it, then calls format(...) and fails around:
delete fileEvidention[charToInt(pos)];
(in debug mode, when I reach this instruction, even if I try to go into with F11, there is an assertion failure)
In case it matters... this is the initialization:
char KernelFS::firstLetter = 'A'; // 'A' = 65
Partition* KernelFS::mountedPartitions[26] = {0}; // init. no partitions are mounted
BitVector* KernelFS::bitVectors[26] = {0}; // init. no partitions are mounted
bool KernelFS::forbidOpening[26] = {false};
long KernelFS::openedFiles[26] = {0};
ListHandler* KernelFS::fileEvidention[26] = {0};
HANDLE KernelFS::mutexFS = CreateMutex(0,0,0);
HANDLE KernelFS::unmountSem = CreateSemaphore(0,0,INFINITE,0);
I have never had this error before, I have no idea how to debug this nor what could cause it.
Thanks for the help, in advance.
EDIT:
when i remove the marked line of code (and ignore the memory leak) there is no assertion failure. What is this witchcraft ?
! :)
Solved. should be
delete fileEvidention[charToInt(part)];
......
Im trying to copy a directory to a new location. So I am using SHFileOperation/SHFILEOPSTRUCT as follows:
SHFILEOPSTRUCT sf;
memset(&sf,0,sizeof(sf));
sf.hwnd = 0;
sf.wFunc = FO_COPY;
dirName += "\\*.*";
sf.pFrom = dirName.c_str();
string copyDir = homeDir + "\\CopyDir";
sf.pTo = copyDir.c_str();
sf.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI;
int n = SHFileOperation(&sf);
if(n != 0)
{
int x = 0;
}
So I set the values as above. There is a file I created in the folder (I have closed the Handle so it should be fine to move). The SHFileOperation call is returning 2, but I cant find anywhere where these error codes are explained. Does anyone know where I can find out what 2 means, or does anyone have any ideas why it might not be working? Cheers
Error code 2 means The system cannot find the file specified.
See Windows System Error Codes for full listing of error descriptions, or write a function that will obtain the description for the error code:
std::string error_to_string(const DWORD a_error_code)
{
// Get the last windows error message.
char msg_buf[1025] = { 0 };
// Get the error message for our os code.
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
0,
a_error_code,
0,
msg_buf,
sizeof(msg_buf) - 1,
0))
{
// Remove trailing newline character.
char* nl_ptr = 0;
if (0 != (nl_ptr = strchr(msg_buf, '\n')))
{
*nl_ptr = '\0';
}
if (0 != (nl_ptr = strchr(msg_buf, '\r')))
{
*nl_ptr = '\0';
}
return std::string(msg_buf);
}
return std::string("Failed to get error message");
}
From reading the documentation for SHFileOperation the strings specified for pTo and pFrom must be double null terminated: yours are only singly null terminated. Try the following:
dirName.append(1, '\0');
sf.pFrom = dirName.c_str();
string copyDir = homeDir + "\\CopyDir";
copyDir.append(1, '\0');
sf.pTo = copyDir.c_str();