Skip to content

Instantly share code, notes, and snippets.

@orbitcowboy
orbitcowboy / A216983.cpp
Created September 27, 2012 19:54
C++ Version of OEIS sequence A216983
#include <iostream>
#include <string>
// ------------------------------------------------------------------
/// Generate and print the sequence A216983 to a std::string.
/// Weblink: http://oeis.org/A216983
//
// Usage:
// ------
// unsigned int uiMax(88);
// std::cout << PrintSequnce_A216983(uiMax)) << std::endl;
@orbitcowboy
orbitcowboy / A217574.hpp
Created October 11, 2012 15:15
Generate and print the sequence A217574 from http://oeis.org/A217574
// ------------------------------------------------------------------
/// Generate and print the sequence A217574 to a std::string.
/// Weblink: http://oeis.org/A217574
//
// Usage:
// ------
// unsigned int uiMax(25);
// std::cout << strPrint_A217574(200)) << std::endl;
//
// Output:
@orbitcowboy
orbitcowboy / FlexeLint Valgrind output with crash
Created August 8, 2014 17:52
Information for the FlexeLint developers to fix a potential bug. FlexeLint crashes when scanning sources of cppcheck on Linux
Here is the valgrind output. It states that there is something wrong with FlexeLint. Take a look at the line (==8590== Invalid read of size 4):
_
const Token *expr1 = cond1->astOperand1();
/home/martin/cppcheck/lib/checkassignif.cpp 267 Error 40: Undeclared
identifier 'cond1'
/home/martin/cppcheck/lib/checkassignif.cpp 267 Error 10: Expecting a
structure or union
/home/martin/cppcheck/lib/checkassignif.cpp 267 Error 1013: Symbol
'astOperand1' not a member of class ''
/home/martin/cppcheck/lib/checkassignif.cpp 267 Error 118: Too few arguments
@orbitcowboy
orbitcowboy / crash_0001.cpp
Created August 9, 2014 18:15
Crash FlexeLint for C/C++ (Linux) Vers. 9.00k3
// Author Dr. Martin Ettl
// Date 2014-08-09
// -------------------------------------------------------------------------------------------------
//
// ./flint9 -v
// FlexeLint for C/C++ (Linux) Vers. 9.00k3, Copyright Gimpel Software 1985-2013
// FlexeLint was compiled with gcc and enabled address-sanitizer and undefined behavior santizier:
// gcc --sanitze=address --sanitze=undefined *.c -o flint9
// This file is able to crash the application.
// Call it with the following parameters:
@orbitcowboy
orbitcowboy / generateExpression.cpp
Last active August 29, 2015 14:05
A program to generate test cases for ticket (http://trac.cppcheck.net/ticket/6074)
#include <iostream>
#include <string>
int main()
{
const std::string operand[6] = { "a", "!(a)", "!(!a)", "~(a)", "~(!a)", "!(~a)" };
const std::string op[2] = { "==" , "!=" };
std::cout << "void f(bool a)\n"
"{\n";
for(unsigned int l = 0; l < 6; ++l)
@orbitcowboy
orbitcowboy / .gitignore
Last active August 29, 2015 14:10 — forked from sehe/.gitignore
*.o
a.out
test
.*.swp
*~
*.png
tags
@orbitcowboy
orbitcowboy / concat.c
Created June 10, 2015 08:22
How to concatenate two strings in a C macro?
#include <stdio.h>
#define concat0(str1, str2) (str1 " " str2)
#define concat1(str1, str2) (#str1 " " #str2)
int main()
{
printf("%s\n%s\n",
concat0 ("a","b"),
concat1 ("a","b"));
#include <inttypes.h>
#include <iostream>
#include <cstdio>
// def.h
struct INFO {
uint32_t val1;
uint32_t val2;
};
struct INFO_LIST {
@orbitcowboy
orbitcowboy / runCppcheckOnProjects.sh
Created August 13, 2016 16:07
Run cppcheck on multiple sln files
#!/bin/bash
find . -type f -name '*.sln' -exec readlink -f {} \; | uniq | sed -e 's/^/cppcheck --enable=all --std=posix --library=std,windows --project=/' > /tmp/cppcheck.sh && sh /tmp/cppcheck.sh && rm /tmp/cppcheck.sh
//
// RGB to HSV convert sample
//
// see also : http://ja.wikipedia.org/wiki/HSV%E8%89%B2%E7%A9%BA%E9%96%93
//
#include <stdio.h>
#include <math.h>
#define min_f(a, b, c) (fminf(a, fminf(b, c)))