void badSink(list<wchar_t *> dataList)
{
    /* copy data out of dataList */
    wchar_t * data = dataList.back();
    {
        wchar_t source[100];
        wmemset(source, L'C', 100-1); /* fill with L'C's */
        source[100-1] = L'\0'; /* null terminate */
        /* POTENTIAL FLAW: Possible buffer overflow if the size of data is less than the length of source */
        memmove(data, source, 100*sizeof(wchar_t));
        data[100-1] = L'\0'; /* Ensure the destination buffer is null terminated */
        printWLine(data);
    }
}
void badSink(list<char *> dataList)
{
    /* copy data out of dataList */
    char * data = dataList.back();
    {
        int fileDesc;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        fileDesc = OPEN(data, O_RDWR|O_CREAT, S_IREAD|S_IWRITE);
        if (fileDesc != -1)
        {
            CLOSE(fileDesc);
        }
    }
}
/* goodG2B uses the GoodSource with the BadSink */
void goodG2BSink(list<char *> dataList)
{
    char * data = dataList.back();
    {
        char source[100];
        memset(source, 'C', 100-1); /* fill with 'C's */
        source[100-1] = '\0'; /* null terminate */
        /* POTENTIAL FLAW: Possible buffer overflow if source is larger than data */
        memmove(data, source, 100*sizeof(char));
        data[100-1] = '\0'; /* Ensure the destination buffer is null terminated */
        printLine(data);
        delete [] data;
    }
}
void PCB_Priority(list<Process> ready, list<Process> finish) {  
  while (ready.size() != 0) {
    ready.sort(Compare);
    ready.front().BeforeRun();
    Display(ready, finish);
    ready.front().AfterRun();

    if (ready.front().IsFinish()) {
      finish.push_back(ready.front());
      for (list<Process>::iterator iter=ready.begin(); iter!=ready.end(); ++iter) {
        iter->Wait();
      }
    } else {
      ready.push_back(ready.front());
      for (list<Process>::iterator iter=ready.begin(); iter!=ready.end(); ++iter) {
        iter->Wait();
      }
      ready.back().priority -= ready.back().round;
    }
    ready.pop_front();    
  }
  
  Display(ready, finish);
}
void badSink(list<char *> dataList)
{
    /* copy data out of dataList */
    char * data = dataList.back();
    {
        char dest[100];
        memset(dest, 'C', 100-1); /* fill with 'C's */
        dest[100-1] = '\0'; /* null terminate */
        /* POTENTIAL FLAW: Possibly copy from a memory location located before the source buffer */
        memcpy(dest, data, 100*sizeof(char));
        /* Ensure null termination */
        dest[100-1] = '\0';
        printLine(dest);
    }
}
    kmerRecord* sortAndFindTopKmer() {
        if(kmers.size()==0)
            return NULL;

        //cerr<<"b1"<<endl;
        kmers.sort(); //sort the linked list by enrichment score
        //cerr<<"b2"<<endl;
        kmerRecord*result=kmers.back();
        //cerr<<"b3"<<endl;
        kmers.pop_back(); //remove the best kmer.
        //cerr<<"b4"<<endl;
        kmersMap.erase(result->kmerSeq); //remove that also from the kmer map
        //cerr<<"b5"<<endl;
        return result;
    }
Example #7
0
// Registers 
batch_dot_args& cache_batch_dot_args(const void* A, const void* B, void* C, dtype_t dt,
		int n, int m, int k, int p, bool broadcast_A)
{
	batch_dot_args args(A, B, C, dt, n, m, k, p, broadcast_A);
	for (auto& entry : g_batch_dot_arg_cache) {
		if (args == entry)
			return entry;
	}
	g_batch_dot_arg_cache.push_front(args);
	if (g_batch_dot_arg_cache.size() > 30) {
		g_batch_dot_arg_cache.back().free_ptrs();
		g_batch_dot_arg_cache.pop_back();
	}
	return g_batch_dot_arg_cache.front();
}
void badSink(list<wchar_t *> dataList)
{
    /* copy data out of dataList */
    wchar_t * data = dataList.back();
    {
        wchar_t source[100];
        wmemset(source, L'C', 100-1); /* fill with 'C's */
        source[100-1] = L'\0'; /* null terminate */
        /* POTENTIAL FLAW: Possibly copying data to memory before the destination buffer */
        wcscpy(data, source);
        printWLine(data);
        /* INCIDENTAL CWE-401: Memory Leak - data may not point to location
         * returned by new [] so can't safely call delete [] on it */
    }
}
Example #9
0
Message *HistoryFileIterator::operator --()
{
    if (m_msg){
        delete m_msg;
        m_msg = NULL;
    }
    if (msgs.empty())
        loadBlock(false);
    if (!msgs.empty()){
        m_msg = msgs.back();
        msgs.pop_back();
        return m_msg;
    }
    return NULL;
}
void badSink(list<wchar_t *> dataList)
{
    /* copy data out of dataList */
    wchar_t * data = dataList.back();
    {
        wchar_t source[100];
        wmemset(source, L'C', 100-1); /* fill with 'C's */
        source[100-1] = L'\0'; /* null terminate */
        /* POTENTIAL FLAW: Possibly copying data to memory before the destination buffer */
        memcpy(data, source, 100*sizeof(wchar_t));
        /* Ensure the destination buffer is null terminated */
        data[100-1] = L'\0';
        printWLine(data);
    }
}
void VisualDictionaryApp::layoutWords( vector<string> words, float radius )
{
	int radiusDivisor = 26;//std::max<int>( 10, words.size() ); // don't let the circles get too small
	mCurrentCircleRadius = radius / radiusDivisor * M_PI;
	for( size_t w = 0; w < words.size(); ++w ) {
		int wordLength	= words[w].length();
		string s		= words[w];
		int charIndex	= (int)s[wordLength-1] - 97;
		float charPer	= charIndex/26.0f;
		float angle		= charPer * 2.0f * M_PI;
		//float angle = w / (float)words.size() * 2 * M_PI;
		vec2 pos = getWindowCenter() + radius * vec2( cos( angle ), sin( angle ) );
		Color col(  CM_HSV, charPer, 0.875f, 1 );
		mNodes.push_back( WordNode( words[w] ) );
		mNodes.back().mPos = getWindowCenter() + radius * 0.5f * vec2( cos( angle ), sin( angle ) );
		mNodes.back().mColor = ColorA( col, 0.0f );
		mNodes.back().mRadiusDest = mCurrentCircleRadius;
		mNodes.back().mRadius = 0;
		
		timeline().apply( &mNodes.back().mRadius, mNodes.back().mRadiusDest, 0.4f, EaseOutAtan( 10 ) ).timelineEnd( -0.39f );
		timeline().apply( &mNodes.back().mPos, pos, 0.4f, EaseOutAtan( 10 ) ).timelineEnd( -0.39f );
		timeline().apply( &mNodes.back().mColor, ColorA( col, 1.0f ), 0.4f, EaseOutAtan( 10 ) ).timelineEnd( -0.39f );
	}
}
Example #12
0
		void set(int key, int value) {
			auto temp_iter = page_map.find(key);
			if(temp_iter != page_map.end()){
				virtual_page.erase(temp_iter->second);
				page_map.erase(key);
			}else if(list_length == capacity){
				page_map.erase(virtual_page.back().first);
				virtual_page.pop_back();
			}else{
				list_length++;
			}
			// update the list
			virtual_page.insert(virtual_page.begin(), pair<int, int>(key, value));
			page_map[key] = virtual_page.begin();
		} 
/* goodB2G uses the BadSource with the GoodSink */
void goodB2GSink(list<int> countList)
{
    int count = countList.back();
    {
        size_t i = 0;
        /* FIX: Validate count before using it as the for loop variant */
        if (count > 0 && count <= 20)
        {
            for (i = 0; i < (size_t)count; i++)
            {
                printLine("Hello");
            }
        }
    }
}
Example #14
0
void mark_incomplete_cuts(seq_t &sequence, list<cut_t> &cuts) {
    for(auto cut = cuts.begin(); cut != cuts.end(); ++cut) {
        if(cut->is_n) {
            if(cut->begin != 0) {
                previous(cut)->is_incomplete = true;
            }
            if(cut->end != sequence.len) {
                next(cut)->is_incomplete = true;
            }
        }
    }

    cuts.front().is_incomplete = true;
    cuts.back().is_incomplete = true;
}
Example #15
0
 void set(int key, int value) {
     if (mp.find(key) == mp.end()) {
         if (cacheList.size() == size) {
             mp.erase(cacheList.back().key);
             cacheList.pop_back();
         }
         cacheList.push_front(Node(key , value));
         mp[key] = cacheList.begin();
     } else {
         it = mp[key];
         cacheList.splice(cacheList.begin() , cacheList , it);
         mp[key] = cacheList.begin();
         cacheList.begin()->val = value;
     }
 }
void badSink(list<char *> dataList)
{
    /* copy data out of dataList */
    char * data = dataList.back();
    {
        char source[100];
        memset(source, 'C', 100-1); /* fill with 'C's */
        source[100-1] = '\0'; /* null terminate */
        /* POTENTIAL FLAW: Possibly copying data to memory before the destination buffer */
        strncpy(data, source, 100-1);
        /* Ensure the destination buffer is null terminated */
        data[100-1] = '\0';
        printLine(data);
    }
}
/* goodG2B uses the GoodSource with the BadSink */
void goodG2BSink(list<int> dataList)
{
    int data = dataList.back();
    /* Assume we want to allocate a relatively small buffer */
    if (data < 100)
    {
        /* POTENTIAL FLAW: malloc() takes a size_t (unsigned int) as input and therefore if it is negative,
         * the conversion will cause malloc() to allocate a very large amount of data or fail */
        char * dataBuffer = (char *)malloc(data);
        /* Do something with dataBuffer */
        memset(dataBuffer, 'A', data-1);
        dataBuffer[data-1] = '\0';
        printLine(dataBuffer);
        free(dataBuffer);
    }
}
/* goodG2B uses the GoodSource with the BadSink */
void goodG2BSink(list<char *> dataList)
{
    char * data = dataList.back();
    {
        char dest[100];
        memset(dest, 'C', 100-1); /* fill with 'C's */
        dest[100-1] = '\0'; /* null terminate */
        /* POTENTIAL FLAW: Possibly copy from a memory location located before the source buffer */
        memmove(dest, data, 100*sizeof(char));
        /* Ensure null termination */
        dest[100-1] = '\0';
        printLine(dest);
        /* INCIDENTAL CWE-401: Memory Leak - data may not point to location
         * returned by new [] so can't safely call delete [] on it */
    }
}
Example #19
0
  T const Back(bool doPop)
  {
    threads::ConditionGuard g(m_Cond);

    if (WaitNonEmpty())
      return T();

    T res = m_list.back();

    if (doPop)
      m_list.pop_back();

    m_isEmpty = m_list.empty();

    return res;
  }
/* goodG2B uses the GoodSource with the BadSink */
void goodG2BSink(list<char *> dataList)
{
    char * data = dataList.back();
    {
        char source[10+1] = SRC_STRING;
        size_t i, sourceLen;
        sourceLen = strlen(source);
        /* Copy length + 1 to include NUL terminator from source */
        /* POTENTIAL FLAW: data may not have enough space to hold source */
        for (i = 0; i < sourceLen + 1; i++)
        {
            data[i] = source[i];
        }
        printLine(data);
    }
}
Example #21
0
bool MenuGestureStrategy::isGesture(list<Vector4>& l,bool leftHand,bool updateLastTime)
{
	int time=(l.size()-1)*intervalTime;
	FLOAT length=abs(l.back().x-l.front().x);
	if((time>SwipeMininalDuration)&&(time<SwipeMaximalDuration)&&(length>SwipeMinimalLength))
	{
		if(updateLastTime)
			if(leftHand)
				lastLeftHandTime=currentTime;
			else
				lastRightHandTime=currentTime;
		return true;
	}
	else
		return false;
}
Example #22
0
bool lru_fetch(const string &url)
{
    int i = lru_hash(url);
    if (dict.find(i) == dict.end()) {
        if (dict.size() == m) {
            dict.erase(lru.back());
            lru.pop_back();
        }
        dict.insert(make_pair(i, lru.insert(lru.begin(), i)));
        return false;
    } else {
        lru.erase(dict[i]);
        dict[i] = lru.insert(lru.begin(), i);
        return true;
    }
}
/* goodB2G uses the BadSource with the GoodSink */
void goodB2GSink(list<int> dataList)
{
    int data = dataList.back();
    {
        int buffer[10] = { 0 };
        /* FIX: Properly validate the array index and prevent a buffer underread */
        if (data >= 0 && data < (10))
        {
            printIntLine(buffer[data]);
        }
        else
        {
            printLine("ERROR: Array index is out-of-bounds");
        }
    }
}
Example #24
0
 void set(int key, int value) {
     auto iter = mm.find(key);
     if(iter != mm.end()){
         iter->second->second = value;
         ll.splice(ll.begin(), ll, iter->second); // move the record
     }
     else {
         if(mm.size() == cap){
             auto back = ll.back(); // NOTICE: back() returns a reference
             mm.erase(back.first);
             ll.pop_back();
         }
         ll.emplace_front(key, value);
         mm[key] = ll.begin();
     }
 }
Example #25
0
File: main.cpp Project: CCJY/coliru
bool isprime::operator()(int number)
{
    if(number == 1)              // returns false for 1
        return false;

    if(number > primes.back()){ // Tests to see if the list of primes range would include the number, if not it runs the morePrimes function
        morePrimes(number);
    }

    it = binary_search(primes.begin(),primes.end(),number); // uses stl find to see if the number is in the list of primes.

    if(it)                      // if the returned iterator points to a value = to number then number is prim.
        return true;

    return false;               // returns false if the number wasnt found
}
Example #26
0
bool isPal(list<int> number) {

    int nSize = number.size();
    int mid = nSize/2;

    for(int i = 0; i < mid; i++) {
        if(number.front() != number.back()) {
            return false; 
        } 
        number.pop_front();
        number.pop_back();
    }

    return true;

}
Example #27
0
/**
* Prepares the map for IP and visited sites
*/
void persistData(map<string, list<string> > &ipTable, list<string> &parsedInputLine){

    string ip = parsedInputLine.front();
    string visitedSite = parsedInputLine.back();
    map<string, list<string> >::iterator elemIt = ipTable.find(ip);

    if(elemIt == ipTable.end()) {
        // no element yet inserted for the IP
        list<string> siteList;
        siteList.push_back(visitedSite);
        ipTable[ip] = siteList;
    } else {
        // going to add the new site in the list associated to this IP
        elemIt->second.push_back(visitedSite);
    }
}
/* goodG2B uses the GoodSource with the BadSink */
void goodG2BSink(list<wchar_t *> dataList)
{
    wchar_t * data = dataList.back();
    {
        wchar_t dest[50] = L"";
        size_t i, dataLen;
        dataLen = wcslen(data);
        /* POTENTIAL FLAW: Possible buffer overflow if data is larger than dest */
        for (i = 0; i < dataLen; i++)
        {
            dest[i] = data[i];
        }
        dest[50-1] = L'\0'; /* Ensure the destination buffer is null terminated */
        printWLine(data);
    }
}
/* goodG2B uses the GoodSource with the BadSink */
void goodG2BSink(list<int64_t *> dataList)
{
    int64_t * data = dataList.back();
    {
        int64_t source[100] = {0}; /* fill with 0's */
        {
            size_t i;
            /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
            for (i = 0; i < 100; i++)
            {
                data[i] = source[i];
            }
            printLongLongLine(data[0]);
            delete [] data;
        }
    }
}
/* goodG2B uses the GoodSource with the BadSink */
void goodG2BSink(list<int> dataList)
{
    int data = dataList.back();
    {
        size_t dataBytes,i;
        int *intPointer;
        /* POTENTIAL FLAW: dataBytes may overflow to a small value */
        dataBytes = data * sizeof(int); /* sizeof array in bytes */
        intPointer = (int*)new char[dataBytes];
        for (i = 0; i < (size_t)data; i++)
        {
            intPointer[i] = 0; /* may write beyond limit of intPointer if integer overflow occured above */
        }
        printIntLine(intPointer[0]);
        delete [] intPointer;
    }
}