Skip to content

Commit

Permalink
Fix underflow in Printer::printList
Browse files Browse the repository at this point in the history
Analogous to 9b88bf8 / three commits back
  • Loading branch information
roberth committed Jun 29, 2024
1 parent bfc5416 commit b2c7f09
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/libexpr/print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,14 @@ class Printer
output << "[";
auto listItems = v.listItems();
auto prettyPrint = shouldPrettyPrintList(listItems);

size_t currentListItemsPrinted = 0;

for (auto elem : listItems) {
printSpace(prettyPrint);

if (totalListItemsPrinted >= options.maxListItems) {
printElided(listItems.size() - totalListItemsPrinted, "item", "items");
printElided(listItems.size() - currentListItemsPrinted, "item", "items");
break;
}

Expand All @@ -419,6 +422,7 @@ class Printer
printNullptr();
}
totalListItemsPrinted++;
currentListItemsPrinted++;
}

decreaseIndent();
Expand Down
9 changes: 9 additions & 0 deletions tests/functional/lang/eval-fail-nested-list-items.err.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error:
… while evaluating a path segment
at /pwd/lang/eval-fail-nested-list-items.nix:11:6:
10|
11| "" + (let v = [ [ 1 2 3 4 5 6 7 8 ] [1 2 3 4]]; in builtins.deepSeq v v)
| ^
12|

error: cannot coerce a list to a string: [ [ 1 2 3 4 5 6 7 8 ] [ 1 «3 items elided» ] ]
11 changes: 11 additions & 0 deletions tests/functional/lang/eval-fail-nested-list-items.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This reproduces https://github.com/NixOS/nix/issues/10993, for lists
# $ nix run nix/2.23.1 -- eval --expr '"" + (let v = [ [ 1 2 3 4 5 6 7 8 ] [1 2 3 4]]; in builtins.deepSeq v v)'
# error:
# … while evaluating a path segment
# at «string»:1:6:
# 1| "" + (let v = [ [ 1 2 3 4 5 6 7 8 ] [1 2 3 4]]; in builtins.deepSeq v v)
# | ^
#
# error: cannot coerce a list to a string: [ [ 1 2 3 4 5 6 7 8 ] [ 1 «4294967290 items elided» ] ]

"" + (let v = [ [ 1 2 3 4 5 6 7 8 ] [1 2 3 4]]; in builtins.deepSeq v v)

0 comments on commit b2c7f09

Please sign in to comment.