[tools] fix segfault when using the maxlen argument (#4359)