Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more
#include <stdlib.h>
#include <string.h>

char *my_strdup_1(const char *str) {
  const size_t len = strlen(str);
  char *const res = malloc(len); // <- BUG
  memcpy(res, str, len);
  return res;
}

char *my_strdup_2(const char *str) {
  const size_t len = strlen(str);
  char *const res = malloc(len); // <- BUG
  memcpy(res, str, len + 1);
  return res;
}

Without tests and a Log container...

Code
Diff
  • function profilePicture() {
      distance = (x1, y1, x2, y2) => Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
      random = t => t[~~(Math.random() * t.length)];
      var width = 56, height = 32;
      var ratio = height / width;
      var grid = [...Array(height)].map(a => []);
      for (var x = 0; x < width; x++) {
        for (var y = 0; y < height; y++) {
          var isIncluded =
            distance(width * 0.5 * ratio, height * 0.50, (x+.5) * ratio, y + .5) < height * 0.47 &&
            distance(width * 0.6 * ratio, height * 0.45, (x+.5) * ratio, y + .5) >= height * 0.41;
          grid[y].push(isIncluded ? random("£@$%€0&#¥") : ' ');
        }
      }
      return grid.map(a => a.join``).join`\n`;
    }
    
    console.log('<OUT:ESC:>' + profilePicture().replace(/\n/g, '<:LF:>'));
    
  • 1111 distance(width * 0.6 * ratio, height * 0.45, (x+.5) * ratio, y + .5) >= height * 0.41;
    1212 grid[y].push(isIncluded ? random("£@$%€0&#¥") : ' ');
    1313 }
    1414 }
    1515 return grid.map(a => a.join``).join`\n`;
    1616 }
    17+
    18+console.log('<OUT:ESC:>' + profilePicture().replace(/\n/g, '<:LF:>'));
Code
Diff
  • fn foo() -> i32 {
        2
    }
  • 11 fn foo() -> i32 {
    2- 0
    2+ 2
    33 }
fn foo() -> i32 {
    0
}

Checking fixed output.

Code
Diff
  • let foo x = 0;;
  • 1-let foo x = 0
    1+let foo x = 0;;
let foo x = 0
;
Unnamedvs. UnnamedFailed Tests

Fixed

Code
Diff
  • var foo* = -1
  • 1-var foo* = 0
    1+var foo* = -1
var foo* = 0
Code
Diff
  • public class Algorithms {
      public static int reverseInt(int n) {
        return Integer.parseInt(new StringBuilder().append(n).reverse().toString());
      }
    }
  • 11 public class Algorithms {
    22 public static int reverseInt(int n) {
    3- return Integer.parseInt(new StringBuffer(String.valueOf(n)).reverse().toString());
    4- }
    3+ return Integer.parseInt(new StringBuilder().append(n).reverse().toString());
    4+ }
    55 }
public class Adder {
    public static int add(int a, int b) {
        return a + b + 1;
    }
}
UnnamedFailed Tests

fast-check

function add1(a, b) {
  return a + b;
}

function add2(a, b) {
  return a + b + 1;
}

function add3(a, b) {
  throw new Error('boo');
}
object Tail {
  def tail[T](xs: List[T]): List[T] =
    xs.tail
}

A mistake they don't want to fix...

function describePhp() {
  return 2 * 2 == 4 ? 'php is good' : 2 * 2 == 5 ? 'php is weird' : 'php has features';
}
Loading more items...