diff --git a/gdb/record-full.c b/gdb/record-full.c
index aa451c05a5d..f6d603d2357 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -2796,11 +2796,11 @@ maintenance_print_record_instruction (const char *args, int from_tty)
   if (offset == record_full_log.size ())
     offset--;
   if (args != nullptr)
-    {
-      offset += value_as_long (parse_and_eval (args));
-      if (offset >= record_full_log.size () || offset < 0)
-	error (_("Not enough recorded history"));
-    }
+    offset += value_as_long (parse_and_eval (args));
+
+  if (offset >= record_full_log.size () || offset < 0)
+    error (_("Not enough recorded history"));
+
   auto to_print = record_full_log.begin () + offset;
 
   gdbarch *arch = current_inferior ()->arch ();
diff --git a/gdb/testsuite/gdb.reverse/maint-print-instruction.exp b/gdb/testsuite/gdb.reverse/maint-print-instruction.exp
index edf6ec081cd..199adebf08b 100644
--- a/gdb/testsuite/gdb.reverse/maint-print-instruction.exp
+++ b/gdb/testsuite/gdb.reverse/maint-print-instruction.exp
@@ -73,3 +73,8 @@ test_print true "1" "print following after reversing"
 
 test_print false "-10" "trying to print too far back"
 test_print false "10" "trying to print too far forward"
+
+# Return to the beginning of history and print.
+# This used to cause an internal error.
+gdb_test "reverse-continue" ".*" "moving to start of history"
+test_print false "" "Print at the start of history"
