I can't for the life of me figure out why this keeps giving me a segfault, but I'm pretty sure it has something to do with the test--;

The program is supposed to solve sudoku puzzles and this portion of my code is supposed to use a brute force approach to solve the sudoku once all single candidates have been found. Basically, it runs through each empty square from left to right starting from the top row and ending at the bottom row. If all 9 numbers cannot be legally placed in an empty square, it will backtrack to the last empty square and increment its value. If that square holds a 9, it will clear it and move back to another empty square.

Any suggestions?

Code:
   if (escount > 0)
   {
      test = 0;
      do
      {
         num = puzzle[row][col] + 1;
         find = 0;
         row = es_row[test];
         col = es_col[test];

         do
         {
            if (check_valid(puzzle, row, col, num) == 1)
            {
               puzzle[row][col] = num;
               attempt++;
               find++;
               break;
            }
            else
            {
               num++;
            }
         }
         while (num < 10);

         if (find == 0)
         {
            test--;
            back++;
            row = es_row[test];
            col = es_col[test];

            while (puzzle[row][col] == 9)
            {
               puzzle[row][col] = 0;
               test--;
               back++;
               row = es_row[test];
               col = es_col[test];
            }
         }
         else
         {
            test++;
         }

      }
      while (test < escount);
   }