From 3ce67444380325e2691feef79ae62c3016328a9c Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Tue, 18 Nov 2025 21:52:13 +0100
Subject: [PATCH] lib: Use C99 initialization syntax for single-variable 'for'
 loops.

* lib/acl-internal.c (acl_nontrivial, acl_ace_nontrivial,
aclv_nontrivial, acl_nfs4_nontrivial): Declare variable of
single-variable 'for' loops in the 'for' clause.
* lib/arcfour.c (arcfour_setkey): Likewise.
* lib/arctwo.c (arctwo_encrypt, arctwo_decrypt, arctwo_setkey_ekb):
Likewise.
* lib/argmatch.c (argmatch, argmatch_exact, argmatch_valid,
argmatch_to_argument): Likewise.
* lib/argz.c (argz_create): Likewise.
* lib/argz.in.h (error_t): Likewise.
* lib/basename-lgpl.c (last_component): Likewise.
* lib/bcp47.c (xpg_to_bcp47, bcp47_to_xpg): Likewise.
* lib/bitset/list.c (lbitset_empty_p): Likewise.
* lib/bitset/vector.c (vbitset_or_and_cmp): Likewise.
* lib/classpath.c (new_classpath): Likewise.
* lib/clean-temp-simple.c (cleanup_action): Likewise.
* lib/clean-temp.c (create_temp_dir, cleanup_temp_dir): Likewise.
* lib/count-leading-zeros.h (COUNT_LEADING_ZEROS): Likewise.
* lib/count-one-bits.h (COUNT_ONE_BITS_GENERIC): Likewise.
* lib/count-trailing-zeros.h (COUNT_TRAILING_ZEROS): Likewise.
* lib/crc-generate-table.c (make_crc_table): Likewise.
* lib/crc.c (crc32_update_no_xor_slice_by_n, crc32_update_no_xor):
Likewise.
* lib/csharpcomp.c (compile_csharp_using_mono,
compile_csharp_using_dotnet, compile_csharp_using_sscli): Likewise.
* lib/csharpexec.c (execute_csharp_using_mono,
execute_csharp_using_dotnet, execute_csharp_using_sscli): Likewise.
* lib/cygpath.c (cygpath_w): Likewise.
* lib/des.c (gl_des_is_weak_key, des_key_schedule, gl_des_setkey,
gl_3des_set2keys, gl_3des_set3keys): Likewise.
* lib/dfa.c (state_index, transit_state, free_mbdata): Likewise.
* lib/di-set.c (di_ent_hash): Likewise.
* lib/diffseq.h (diag): Likewise.
* lib/duplocale.c (duplocale): Likewise.
* lib/execve.c (execve): Likewise.
* lib/fatal-signal.c (init_fatal_signals, uninstall_handlers,
install_handlers, gl_lock_define_initialized, do_init_fatal_signal_set,
get_fatal_signals): Likewise.
* lib/fcntl.c (dupfd): Likewise.
* lib/ffs.c (ffs): Likewise.
* lib/ffsl.h (unsigned): Likewise.
* lib/file-remote.c (file_is_remote): Likewise.
* lib/findprog-in.c (find_in_given_path): Likewise.
* lib/findprog.c (find_in_path): Likewise.
* lib/fma.c (decode, multiply, FUNC): Likewise.
* lib/freelocale.c (freelocale): Likewise.
* lib/fstrcmp.c (fstrcmp_bounded): Likewise.
* lib/ftoastr.c (FTOASTR): Likewise.
* lib/fts.c (find_matching_ancestor, fts_cross_check): Likewise.
* lib/fwriteerror.c (main): Likewise.
* lib/gai_strerror.c (gai_strerror): Likewise.
* lib/gc-gnulib.c (gc_cipher_setkey, gc_cipher_setiv,
gc_cipher_encrypt_inline, gc_cipher_decrypt_inline): Likewise.
* lib/gc-pbkdf2.c (gc_pbkdf2_prf): Likewise.
* lib/gen-uni-tables.c (fill_attributes, debug_output_predicate,
output_predicate_test, output_predicate, output_category,
output_combclass, output_bidi_category, output_decimal_digit_test,
output_decimal_digit, output_digit_test, output_digit,
output_numeric_test, output_numeric, fill_mirror, get_mirror_value,
output_mirror, clear_properties, fill_properties, fill_property30,
output_indic_conjunct_break_test, output_indic_conjunct_break,
fill_arabicshaping, output_joining_type_test, output_joining_type,
output_joining_group_test, output_joining_group, fill_scripts,
output_scripts, output_scripts_byname, output_blocks,
output_ident_category, output_charclass, output_charmap, output_tables,
fill_width, output_nonspacing_property, output_width_property_test,
debug_output_lbp, fill_org_lbp, debug_output_org_lbp, output_lbpea,
output_lbrk_tables, debug_output_wbp, fill_org_wbp,
debug_output_org_wbp, output_wbp, output_gbp_test, output_gbp_table,
fill_org_gbp, output_decomposition, output_decomposition_tables,
fill_composition_exclusions, debug_output_composition_tables,
output_composition_tables, output_simple_mapping_test,
output_simple_mapping, fill_casing_rules, fill_casefolding_rules,
redistribute_casefolding_rules, output_casing_rules): Likewise.
* lib/get_ppid_of.c (get_ppid_of): Likewise.
* lib/getdtablesize.c (getdtablesize): Likewise.
* lib/getloadavg.c (getloadavg): Likewise.
* lib/getlocalename_l-unsafe.c (get_locale_t_name_unsafe, newlocale,
duplocale, freelocale): Likewise.
* lib/getlogin.c (getlogin): Likewise.
* lib/getprogname.c (getprogname): Likewise.
* lib/getugroups.c (getugroups): Likewise.
* lib/gl_anyavltree_list2.h (gl_tree_remove_node_from_tree,
gl_tree_nx_add_first, gl_tree_nx_add_last, gl_tree_nx_add_before,
gl_tree_nx_add_after): Likewise.
* lib/gl_anyhash2.h (hash_resize): Likewise.
* lib/gl_anyhash_primes.h (next_prime): Likewise.
* lib/gl_anylinked_list2.h (gl_linked_nx_create,
gl_linked_search_from_to, gl_linked_list_free,
gl_linked_iterator_from_to, gl_linked_sortedlist_search,
gl_linked_sortedlist_nx_add, gl_linked_sortedlist_remove): Likewise.
* lib/gl_anyrbtree_list2.h (gl_tree_remove_node_from_tree,
gl_tree_nx_add_first, gl_tree_nx_add_last, gl_tree_nx_add_before,
gl_tree_nx_add_after): Likewise.
* lib/gl_anytree_list2.h (gl_tree_sortedlist_search,
gl_tree_sortedlist_search_from_to): Likewise.
* lib/gl_anytree_omap.h (gl_tree_search, gl_tree_search_atleast,
gl_tree_getremove): Likewise.
* lib/gl_anytree_oset.h (gl_tree_search, gl_tree_search_atleast,
gl_tree_search_node, gl_tree_iterator_atleast): Likewise.
* lib/gl_anytreehash_list1.h (add_to_bucket, remove_from_bucket):
Likewise.
* lib/gl_anytreehash_list2.h (gl_tree_search_from_to,
gl_tree_list_free): Likewise.
* lib/gl_array_list.c (gl_array_indexof_from_to, gl_array_nx_add_first,
gl_array_nx_add_before, gl_array_nx_add_after, gl_array_nx_add_at,
gl_array_remove_node, gl_array_remove_at): Likewise.
* lib/gl_array_map.c (gl_array_indexof, gl_array_remove_at): Likewise.
* lib/gl_array_omap.c (gl_array_nx_add_at, gl_array_remove_at):
Likewise.
* lib/gl_array_oset.c (gl_array_nx_add_at, gl_array_remove_at,
gl_array_update): Likewise.
* lib/gl_array_set.c (gl_array_search, gl_array_remove_at,
gl_array_remove): Likewise.
* lib/gl_carray_list.c (gl_carray_nx_add_at, gl_carray_remove_at,
gl_carray_list_free): Likewise.
* lib/gl_hash_map.c (gl_hash_search, gl_hash_nx_getput,
gl_hash_getremove, gl_hash_free): Likewise.
* lib/gl_hash_set.c (gl_hash_search, gl_hash_nx_add, gl_hash_remove,
gl_hash_free): Likewise.
* lib/gl_linkedhash_list.c (remove_from_bucket): Likewise.
* lib/gl_linkedhash_map.c (gl_linkedhash_search,
gl_linkedhash_nx_getput, gl_linkedhash_getremove, gl_linkedhash_free):
Likewise.
* lib/gl_linkedhash_set.c (gl_linkedhash_search, gl_linkedhash_nx_add,
gl_linkedhash_remove, gl_linkedhash_free): Likewise.
* lib/group-member.c (group_member, main): Likewise.
* lib/hash.c (hash_get_max_bucket_length, hash_table_ok, hash_lookup,
hash_get_first, hash_get_entries, hash_do_for_each, hash_clear,
hash_free, find_entry, transfer_entries, hash_print): Likewise.
* lib/hashcode-mem.c (hash_pjw_bare): Likewise.
* lib/hashcode-string2.c (hash_pjw): Likewise.
* lib/human.c (human_readable): Likewise.
* lib/i-ring.c (i_ring_init): Likewise.
* lib/idcache.c (getuser, getuidbyname, getgroup, getgidbyname):
Likewise.
* lib/inet_ntop.c (inet_ntop6): Likewise.
* lib/inet_pton.c (inet_pton6): Likewise.
* lib/ino-map.c (ino_hash): Likewise.
* lib/integer_length.c (integer_length): Likewise.
* lib/integer_length_l.c (FUNC): Likewise.
* lib/javacomp.c (compile_using_envjavac, compile_using_javac):
Likewise.
* lib/javaexec.c (execute_java_class): Likewise.
* lib/kwset.c (kwsprep): Likewise.
* lib/ldexpl.c (main): Likewise.
* lib/localeinfo.c (case_folded_counterparts): Likewise.
* lib/localename-unsafe.c (script_entry, gl_locale_name_canonicalize):
Likewise.
* lib/login_tty.c (login_tty): Likewise.
* lib/mbscasestr.c (knuth_morris_pratt_multibyte): Likewise.
* lib/mbsstr.c (knuth_morris_pratt_multibyte): Likewise.
* lib/md2.c (md2_finish_ctx, md2_update_chksum, md2_compress): Likewise.
* lib/md4.c (md4_process_block): Likewise.
* lib/mem-hash-map.c (resize): Likewise.
* lib/memcasecmp.c (memcasecmp): Likewise.
* lib/memchr.c (__memchr): Likewise.
* lib/memchr2.c (memchr2): Likewise.
* lib/memrchr.c (__memrchr): Likewise.
* lib/mgetgroups.c (mgetgroups): Likewise.
* lib/mktime.c (__mktime_internal): Likewise.
* lib/modechange.c (mode_compile): Likewise.
* lib/mountlist.c (unescape_tab, read_file_system_list): Likewise.
* lib/mpsort.c (mpsort_with_tmp): Likewise.
* lib/nproc.c (num_processors_via_affinity_mask): Likewise.
* lib/obstack.c (strong_alias): Likewise.
* lib/os2-spawn.c (prepare_spawn): Likewise.
* lib/pipe-filter-ii.c (WaitForMultipleObjects): Likewise.
* lib/pipe-safer.c (pipe_safer): Likewise.
* lib/pipe2-safer.c (pipe2_safer): Likewise.
* lib/poll.c (windows_compute_revents, poll): Likewise.
* lib/progreloc.c (find_executable): Likewise.
* lib/pselect.c (rpl_pselect): Likewise.
* lib/putenv.c (SetEnvironmentVariable): Likewise.
* lib/qsort.c (_quicksort): Likewise.
* lib/quotearg.c (quotearg_buffer_restyled, quotearg_free): Likewise.
* lib/random_r.c (__srandom_r): Likewise.
* lib/readtokens.c (readtoken): Likewise.
* lib/readutmp.c (read_utmp_from_systemd): Likewise.
* lib/regex-quote.c (regex_quote_length, regex_quote_copy): Likewise.
* lib/relocwrapper.c (relocate_libdirs, activate_libdirs): Likewise.
* lib/scandir.c (cancel_handler): Likewise.
* lib/select.c (windows_poll_handle, rpl_select): Likewise.
* lib/set-permissions.c (set_acls_from_mode): Likewise.
* lib/setlocale-fixes.c (fill_lc_all_name, setlocale_fixed): Likewise.
* lib/setlocale.c (search, setlocale_unixlike): Likewise.
* lib/setlocale_null-unlocked.c (setlocale_null_r_unlocked): Likewise.
* lib/sh-quote.c (shell_quote_argv): Likewise.
* lib/sha1.c (sha1_process_block): Likewise.
* lib/sha256.c (sha256_read_ctx, sha224_read_ctx, sha256_process_block):
Likewise.
* lib/sha512.c (sha512_read_ctx, sha384_read_ctx, sha512_process_block):
Likewise.
* lib/sig2str.c (str2signum, sig2str): Likewise.
* lib/sigprocmask.c (sigpending, sigprocmask): Likewise.
* lib/sm3.c (sm3_read_ctx, sm3_process_block): Likewise.
* lib/spawn_faction_destroy.c (posix_spawn_file_actions_destroy):
Likewise.
* lib/spawni.c (do_remaining_delayed_dup2, shrink_inheritable_handles,
close_inheritable_handles, __spawni): Likewise.
* lib/ssfmalloc-bitmap.h (init_bitmap_all_bits_clear,
init_bitmap_all_bits_set): Likewise.
* lib/ssfmalloc.h (add_update, drop_update,
allocate_medium_block_in_page, free_medium_block_in_page): Likewise.
* lib/stack-trace-impl.h (print_stack_trace_to): Likewise.
* lib/stat-time.h (stat_time_normalize): Likewise.
* lib/stat-w32.c (_gl_fstat_by_handle): Likewise.
* lib/stat.c (rpl_stat): Likewise.
* lib/stdopen.c (stdopen): Likewise.
* lib/str-kmp.h (knuth_morris_pratt): Likewise.
* lib/str-two-way.h (two_way_long_needle): Likewise.
* lib/strchrnul.c (strchrnul): Likewise.
* lib/strfmon_l.c (rpl_strfmon_l): Likewise.
* lib/strftime.c (underlying_strftime, __strftime_internal): Likewise.
* lib/striconveh.c (iconv_carefully, iconv_carefully_1, tmpbuf):
Likewise.
* lib/striconveha.c (mem_iconveha_notranslit, str_iconveha_notranslit):
Likewise.
* lib/string-desc.c (_sd_c_casecmp, sd_concat): Likewise.
* lib/strnlen.c (strnlen): Likewise.
* lib/strtod.c (parse_number): Likewise.
* lib/strtol.c (INTERNAL(strtol)): Likewise.
* lib/struniq.h (gl_lock_define_initialized): Likewise.
* lib/sys_select.in.h (rpl_fd_isset): Likewise.
* lib/sys_socket.in.h (rpl_fd_isset): Likewise.
* lib/system-quote.c (windows_createprocess_quote, windows_cmd_quote,
system_quote_argv): Likewise.
* lib/tempname.c (try_tempname_len): Likewise.
* lib/term-style-control.c (init_relevant_signal_set,
fatal_or_stopping_signal_handler, continuing_signal_handler,
ensure_other_signal_handlers): Likewise.
* lib/tsearch.c (check_tree): Likewise.
* lib/unicase/u-casemap.h (FUNC): Likewise.
* lib/unicase/u-ct-totitle.h (FUNC): Likewise.
* lib/uniconv/u-conv-from-enc.h (FUNC): Likewise.
* lib/uniconv/u-conv-to-enc.h (FUNC): Likewise.
* lib/uniconv/u8-conv-from-enc.c (u8_conv_from_encoding): Likewise.
* lib/unictype/3level.h (CONCAT(TABLE,_add), CONCAT(TABLE,_iterate),
CONCAT(TABLE,_finalize)): Likewise.
* lib/unictype/3levelbit.h (CONCAT(TABLE,_add), CONCAT(TABLE,_iterate),
CONCAT(TABLE,_finalize)): Likewise.
* lib/unigbrk/ulc-grapheme-breaks.c (ascii_grapheme_breaks,
ulc_grapheme_breaks): Likewise.
* lib/unilbrk/u8-possible-linebreaks.c (main): Likewise.
* lib/unilbrk/u8-width-linebreaks.c (main): Likewise.
* lib/unilbrk/ulc-possible-linebreaks.c
(ulc_possible_linebreaks_internal, main): Likewise.
* lib/unilbrk/ulc-width-linebreaks.c (ulc_width_linebreaks_internal,
main): Likewise.
* lib/uniname/uniname.c (unicode_character_name,
unicode_name_character): Likewise.
* lib/uninorm/u-normalize-internal.h (FUNC): Likewise.
* lib/uninorm/uninorm-filter.c (uninorm_filter_write,
uninorm_filter_flush): Likewise.
* lib/uniwbrk/u8-wordbreaks.c (main): Likewise.
* lib/uniwbrk/ulc-wordbreaks.c (ulc_wordbreaks, main): Likewise.
* lib/userspec.c (main): Likewise.
* lib/vasnprintf.c (multiply, divide, convert_to_decimal,
decode_long_double, decode_double, scale10_round_decimal_decoded,
VASNPRINTF): Likewise.
* lib/vma-iter.c (vma_iterate): Likewise.
* lib/windows-cond.c (glwthread_waitqueue_notify_all): Likewise.
* lib/windows-path.c (extended_PATH, extended_environ): Likewise.
* lib/windows-rwlock.c (glwthread_waitqueue_add,
glwthread_waitqueue_notify_all): Likewise.
* lib/windows-spawn.c (quoted_arg_length, quoted_arg_string,
prepare_spawn, compose_command, compose_envblock,
init_inheritable_handles, compose_handles_block): Likewise.
* lib/windows-timedrwlock.c (glwthread_waitqueue_notify_all): Likewise.
* lib/windows-tls.c (glwthread_tls_process_destructors,
glwthread_tls_key_delete): Likewise.
* lib/xstring-desc.c (xsd_concat): Likewise.
* lib/xvasprintf.c (xstrcat, xvasprintf): Likewise.
* lib/newlocale.c (newlocale): Likewise. Move the fail_with_err label
into the loop.
---
 ChangeLog                             | 279 ++++++++++++
 lib/acl-internal.c                    |  33 +-
 lib/arcfour.c                         |   5 +-
 lib/arctwo.c                          |  17 +-
 lib/argmatch.c                        |  14 +-
 lib/argz.c                            |   3 +-
 lib/argz.in.h                         |   3 +-
 lib/basename-lgpl.c                   |   3 +-
 lib/bcp47.c                           |  20 +-
 lib/bitset/list.c                     |   8 +-
 lib/bitset/vector.c                   |   4 +-
 lib/classpath.c                       |   5 +-
 lib/clean-temp-simple.c               |   4 +-
 lib/clean-temp.c                      |  10 +-
 lib/count-leading-zeros.h             |   3 +-
 lib/count-one-bits.h                  |   3 +-
 lib/count-trailing-zeros.h            |   3 +-
 lib/crc-generate-table.c              |   5 +-
 lib/crc.c                             |   8 +-
 lib/csharpcomp.c                      |  44 +-
 lib/csharpexec.c                      |  24 +-
 lib/cygpath.c                         |   4 +-
 lib/des.c                             |  19 +-
 lib/dfa.c                             |  10 +-
 lib/di-set.c                          |   3 +-
 lib/diffseq.h                         |   8 +-
 lib/duplocale.c                       |   3 +-
 lib/execve.c                          |   3 +-
 lib/fatal-signal.c                    |  21 +-
 lib/fcntl.c                           |   3 +-
 lib/ffs.c                             |   3 +-
 lib/ffsl.h                            |   4 +-
 lib/file-remote.c                     |  36 +-
 lib/findprog-in.c                     |  37 +-
 lib/findprog.c                        |   3 +-
 lib/fma.c                             |  45 +-
 lib/freelocale.c                      |   3 +-
 lib/fstrcmp.c                         |   9 +-
 lib/ftoastr.c                         |   3 +-
 lib/fts.c                             |  29 +-
 lib/fwriteerror.c                     |   5 +-
 lib/gai_strerror.c                    |   3 +-
 lib/gc-gnulib.c                       |  12 +-
 lib/gc-pbkdf2.c                       |   9 +-
 lib/gen-uni-tables.c                  | 632 +++++++++++---------------
 lib/get_ppid_of.c                     |   3 +-
 lib/getdtablesize.c                   |  11 +-
 lib/getloadavg.c                      |   8 +-
 lib/getlocalename_l-unsafe.c          |  29 +-
 lib/getlogin.c                        |   3 +-
 lib/getprogname.c                     |   4 +-
 lib/getugroups.c                      |   3 +-
 lib/gl_anyavltree_list2.h             |  56 +--
 lib/gl_anyhash2.h                     |   3 +-
 lib/gl_anyhash_primes.h               |   4 +-
 lib/gl_anylinked_list2.h              |  62 +--
 lib/gl_anyrbtree_list2.h              |  56 +--
 lib/gl_anytree_list2.h                |   8 +-
 lib/gl_anytree_omap.h                 |  10 +-
 lib/gl_anytree_oset.h                 |  13 +-
 lib/gl_anytreehash_list1.h            |  12 +-
 lib/gl_anytreehash_list2.h            |   9 +-
 lib/gl_array_list.c                   |  26 +-
 lib/gl_array_map.c                    |  11 +-
 lib/gl_array_omap.c                   |   6 +-
 lib/gl_array_oset.c                   |  12 +-
 lib/gl_array_set.c                    |  19 +-
 lib/gl_carray_list.c                  |  45 +-
 lib/gl_hash_map.c                     |  39 +-
 lib/gl_hash_set.c                     |  31 +-
 lib/gl_linkedhash_list.c              |   3 +-
 lib/gl_linkedhash_map.c               |  39 +-
 lib/gl_linkedhash_set.c               |  31 +-
 lib/group-member.c                    |   7 +-
 lib/hash.c                            |  72 ++-
 lib/hashcode-mem.c                    |   3 +-
 lib/hashcode-string2.c                |   3 +-
 lib/human.c                           |   3 +-
 lib/i-ring.c                          |   3 +-
 lib/idcache.c                         |  22 +-
 lib/inet_ntop.c                       |   7 +-
 lib/inet_pton.c                       |   3 +-
 lib/ino-map.c                         |   3 +-
 lib/integer_length.c                  |   4 +-
 lib/integer_length_l.c                |   4 +-
 lib/javacomp.c                        |   8 +-
 lib/javaexec.c                        |  14 +-
 lib/kwset.c                           |   3 +-
 lib/ldexpl.c                          |   3 +-
 lib/localeinfo.c                      |   3 +-
 lib/localename-unsafe.c               |   7 +-
 lib/login_tty.c                       |   6 +-
 lib/mbscasestr.c                      |   4 +-
 lib/mbsstr.c                          |   4 +-
 lib/md2.c                             |  14 +-
 lib/md4.c                             |   3 +-
 lib/mem-hash-map.c                    |   3 +-
 lib/memcasecmp.c                      |   3 +-
 lib/memchr.c                          |  14 +-
 lib/memchr2.c                         |  16 +-
 lib/memrchr.c                         |  14 +-
 lib/mgetgroups.c                      |   3 +-
 lib/mktime.c                          |   6 +-
 lib/modechange.c                      |   5 +-
 lib/mountlist.c                       |  15 +-
 lib/mpsort.c                          |   3 +-
 lib/newlocale.c                       |  42 +-
 lib/nproc.c                           |  16 +-
 lib/obstack.c                         |   3 +-
 lib/os2-spawn.c                       |   5 +-
 lib/pipe-filter-ii.c                  |   3 +-
 lib/pipe-safer.c                      |   3 +-
 lib/pipe2-safer.c                     |   3 +-
 lib/poll.c                            |  13 +-
 lib/progreloc.c                       |  18 +-
 lib/pselect.c                         |   4 +-
 lib/putenv.c                          |   4 +-
 lib/qsort.c                           |   5 +-
 lib/quotearg.c                        |   9 +-
 lib/random_r.c                        |   3 +-
 lib/readtokens.c                      |   5 +-
 lib/readutmp.c                        |   3 +-
 lib/regex-quote.c                     |   8 +-
 lib/relocwrapper.c                    |   9 +-
 lib/scandir.c                         |   3 +-
 lib/select.c                          |  20 +-
 lib/set-permissions.c                 |   4 +-
 lib/setlocale-fixes.c                 |  10 +-
 lib/setlocale.c                       | 130 +++---
 lib/setlocale_null-unlocked.c         |   8 +-
 lib/sh-quote.c                        |   5 +-
 lib/sha1.c                            |   3 +-
 lib/sha256.c                          |   9 +-
 lib/sha512.c                          |   9 +-
 lib/sig2str.c                         |   6 +-
 lib/sigprocmask.c                     |  26 +-
 lib/sm3.c                             |   8 +-
 lib/spawn_faction_destroy.c           |   4 +-
 lib/spawni.c                          | 123 +++--
 lib/ssfmalloc-bitmap.h                |   6 +-
 lib/ssfmalloc.h                       |  14 +-
 lib/stack-trace-impl.h                |   4 +-
 lib/stat-time.h                       |   3 +-
 lib/stat-w32.c                        |   3 +-
 lib/stat.c                            |   3 +-
 lib/stdopen.c                         |   3 +-
 lib/str-kmp.h                         |   4 +-
 lib/str-two-way.h                     |   9 +-
 lib/strchrnul.c                       |  14 +-
 lib/strfmon_l.c                       |  41 +-
 lib/strftime.c                        |   9 +-
 lib/striconveh.c                      |  15 +-
 lib/striconveha.c                     |  12 +-
 lib/string-desc.c                     |  37 +-
 lib/strnlen.c                         |   3 +-
 lib/strtod.c                          |   3 +-
 lib/strtol.c                          |   5 +-
 lib/struniq.h                         |   5 +-
 lib/sys_select.in.h                   |   3 +-
 lib/sys_socket.in.h                   |   3 +-
 lib/system-quote.c                    |  33 +-
 lib/tempname.c                        |   3 +-
 lib/term-style-control.c              | 101 ++--
 lib/tsearch.c                         |   3 +-
 lib/unicase/u-casemap.h               | 130 +++---
 lib/unicase/u-ct-totitle.h            | 130 +++---
 lib/uniconv/u-conv-from-enc.h         |   6 +-
 lib/uniconv/u-conv-to-enc.h           |  10 +-
 lib/uniconv/u8-conv-from-enc.c        |  26 +-
 lib/unictype/3level.h                 |  33 +-
 lib/unictype/3levelbit.h              |  36 +-
 lib/unigbrk/ulc-grapheme-breaks.c     |   8 +-
 lib/unilbrk/u8-possible-linebreaks.c  |   3 +-
 lib/unilbrk/u8-width-linebreaks.c     |   3 +-
 lib/unilbrk/ulc-possible-linebreaks.c |   7 +-
 lib/unilbrk/ulc-width-linebreaks.c    |   8 +-
 lib/uniname/uniname.c                 |  15 +-
 lib/uninorm/u-normalize-internal.h    |  82 ++--
 lib/uninorm/uninorm-filter.c          |  98 ++--
 lib/uniwbrk/u8-wordbreaks.c           |   3 +-
 lib/uniwbrk/ulc-wordbreaks.c          |   7 +-
 lib/userspec.c                        |   4 +-
 lib/vasnprintf.c                      | 143 +++---
 lib/vma-iter.c                        | 155 +++----
 lib/windows-cond.c                    |   4 +-
 lib/windows-path.c                    |  32 +-
 lib/windows-rwlock.c                  |   9 +-
 lib/windows-spawn.c                   | 128 +++---
 lib/windows-timedrwlock.c             |   4 +-
 lib/windows-tls.c                     |  13 +-
 lib/xstring-desc.c                    |  32 +-
 lib/xvasprintf.c                      |   8 +-
 192 files changed, 1886 insertions(+), 2360 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c8569b6420..ce3dff591d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,282 @@
+2025-11-18  Bruno Haible  <bruno@clisp.org>
+
+	lib: Use C99 initialization syntax for single-variable 'for' loops.
+	* lib/acl-internal.c (acl_nontrivial, acl_ace_nontrivial,
+	aclv_nontrivial, acl_nfs4_nontrivial): Declare variable of
+	single-variable 'for' loops in the 'for' clause.
+	* lib/arcfour.c (arcfour_setkey): Likewise.
+	* lib/arctwo.c (arctwo_encrypt, arctwo_decrypt, arctwo_setkey_ekb):
+	Likewise.
+	* lib/argmatch.c (argmatch, argmatch_exact, argmatch_valid,
+	argmatch_to_argument): Likewise.
+	* lib/argz.c (argz_create): Likewise.
+	* lib/argz.in.h (error_t): Likewise.
+	* lib/basename-lgpl.c (last_component): Likewise.
+	* lib/bcp47.c (xpg_to_bcp47, bcp47_to_xpg): Likewise.
+	* lib/bitset/list.c (lbitset_empty_p): Likewise.
+	* lib/bitset/vector.c (vbitset_or_and_cmp): Likewise.
+	* lib/classpath.c (new_classpath): Likewise.
+	* lib/clean-temp-simple.c (cleanup_action): Likewise.
+	* lib/clean-temp.c (create_temp_dir, cleanup_temp_dir): Likewise.
+	* lib/count-leading-zeros.h (COUNT_LEADING_ZEROS): Likewise.
+	* lib/count-one-bits.h (COUNT_ONE_BITS_GENERIC): Likewise.
+	* lib/count-trailing-zeros.h (COUNT_TRAILING_ZEROS): Likewise.
+	* lib/crc-generate-table.c (make_crc_table): Likewise.
+	* lib/crc.c (crc32_update_no_xor_slice_by_n, crc32_update_no_xor):
+	Likewise.
+	* lib/csharpcomp.c (compile_csharp_using_mono,
+	compile_csharp_using_dotnet, compile_csharp_using_sscli): Likewise.
+	* lib/csharpexec.c (execute_csharp_using_mono,
+	execute_csharp_using_dotnet, execute_csharp_using_sscli): Likewise.
+	* lib/cygpath.c (cygpath_w): Likewise.
+	* lib/des.c (gl_des_is_weak_key, des_key_schedule, gl_des_setkey,
+	gl_3des_set2keys, gl_3des_set3keys): Likewise.
+	* lib/dfa.c (state_index, transit_state, free_mbdata): Likewise.
+	* lib/di-set.c (di_ent_hash): Likewise.
+	* lib/diffseq.h (diag): Likewise.
+	* lib/duplocale.c (duplocale): Likewise.
+	* lib/execve.c (execve): Likewise.
+	* lib/fatal-signal.c (init_fatal_signals, uninstall_handlers,
+	install_handlers, gl_lock_define_initialized, do_init_fatal_signal_set,
+	get_fatal_signals): Likewise.
+	* lib/fcntl.c (dupfd): Likewise.
+	* lib/ffs.c (ffs): Likewise.
+	* lib/ffsl.h (unsigned): Likewise.
+	* lib/file-remote.c (file_is_remote): Likewise.
+	* lib/findprog-in.c (find_in_given_path): Likewise.
+	* lib/findprog.c (find_in_path): Likewise.
+	* lib/fma.c (decode, multiply, FUNC): Likewise.
+	* lib/freelocale.c (freelocale): Likewise.
+	* lib/fstrcmp.c (fstrcmp_bounded): Likewise.
+	* lib/ftoastr.c (FTOASTR): Likewise.
+	* lib/fts.c (find_matching_ancestor, fts_cross_check): Likewise.
+	* lib/fwriteerror.c (main): Likewise.
+	* lib/gai_strerror.c (gai_strerror): Likewise.
+	* lib/gc-gnulib.c (gc_cipher_setkey, gc_cipher_setiv,
+	gc_cipher_encrypt_inline, gc_cipher_decrypt_inline): Likewise.
+	* lib/gc-pbkdf2.c (gc_pbkdf2_prf): Likewise.
+	* lib/gen-uni-tables.c (fill_attributes, debug_output_predicate,
+	output_predicate_test, output_predicate, output_category,
+	output_combclass, output_bidi_category, output_decimal_digit_test,
+	output_decimal_digit, output_digit_test, output_digit,
+	output_numeric_test, output_numeric, fill_mirror, get_mirror_value,
+	output_mirror, clear_properties, fill_properties, fill_property30,
+	output_indic_conjunct_break_test, output_indic_conjunct_break,
+	fill_arabicshaping, output_joining_type_test, output_joining_type,
+	output_joining_group_test, output_joining_group, fill_scripts,
+	output_scripts, output_scripts_byname, output_blocks,
+	output_ident_category, output_charclass, output_charmap, output_tables,
+	fill_width, output_nonspacing_property, output_width_property_test,
+	debug_output_lbp, fill_org_lbp, debug_output_org_lbp, output_lbpea,
+	output_lbrk_tables, debug_output_wbp, fill_org_wbp,
+	debug_output_org_wbp, output_wbp, output_gbp_test, output_gbp_table,
+	fill_org_gbp, output_decomposition, output_decomposition_tables,
+	fill_composition_exclusions, debug_output_composition_tables,
+	output_composition_tables, output_simple_mapping_test,
+	output_simple_mapping, fill_casing_rules, fill_casefolding_rules,
+	redistribute_casefolding_rules, output_casing_rules): Likewise.
+	* lib/get_ppid_of.c (get_ppid_of): Likewise.
+	* lib/getdtablesize.c (getdtablesize): Likewise.
+	* lib/getloadavg.c (getloadavg): Likewise.
+	* lib/getlocalename_l-unsafe.c (get_locale_t_name_unsafe, newlocale,
+	duplocale, freelocale): Likewise.
+	* lib/getlogin.c (getlogin): Likewise.
+	* lib/getprogname.c (getprogname): Likewise.
+	* lib/getugroups.c (getugroups): Likewise.
+	* lib/gl_anyavltree_list2.h (gl_tree_remove_node_from_tree,
+	gl_tree_nx_add_first, gl_tree_nx_add_last, gl_tree_nx_add_before,
+	gl_tree_nx_add_after): Likewise.
+	* lib/gl_anyhash2.h (hash_resize): Likewise.
+	* lib/gl_anyhash_primes.h (next_prime): Likewise.
+	* lib/gl_anylinked_list2.h (gl_linked_nx_create,
+	gl_linked_search_from_to, gl_linked_list_free,
+	gl_linked_iterator_from_to, gl_linked_sortedlist_search,
+	gl_linked_sortedlist_nx_add, gl_linked_sortedlist_remove): Likewise.
+	* lib/gl_anyrbtree_list2.h (gl_tree_remove_node_from_tree,
+	gl_tree_nx_add_first, gl_tree_nx_add_last, gl_tree_nx_add_before,
+	gl_tree_nx_add_after): Likewise.
+	* lib/gl_anytree_list2.h (gl_tree_sortedlist_search,
+	gl_tree_sortedlist_search_from_to): Likewise.
+	* lib/gl_anytree_omap.h (gl_tree_search, gl_tree_search_atleast,
+	gl_tree_getremove): Likewise.
+	* lib/gl_anytree_oset.h (gl_tree_search, gl_tree_search_atleast,
+	gl_tree_search_node, gl_tree_iterator_atleast): Likewise.
+	* lib/gl_anytreehash_list1.h (add_to_bucket, remove_from_bucket):
+	Likewise.
+	* lib/gl_anytreehash_list2.h (gl_tree_search_from_to,
+	gl_tree_list_free): Likewise.
+	* lib/gl_array_list.c (gl_array_indexof_from_to, gl_array_nx_add_first,
+	gl_array_nx_add_before, gl_array_nx_add_after, gl_array_nx_add_at,
+	gl_array_remove_node, gl_array_remove_at): Likewise.
+	* lib/gl_array_map.c (gl_array_indexof, gl_array_remove_at): Likewise.
+	* lib/gl_array_omap.c (gl_array_nx_add_at, gl_array_remove_at):
+	Likewise.
+	* lib/gl_array_oset.c (gl_array_nx_add_at, gl_array_remove_at,
+	gl_array_update): Likewise.
+	* lib/gl_array_set.c (gl_array_search, gl_array_remove_at,
+	gl_array_remove): Likewise.
+	* lib/gl_carray_list.c (gl_carray_nx_add_at, gl_carray_remove_at,
+	gl_carray_list_free): Likewise.
+	* lib/gl_hash_map.c (gl_hash_search, gl_hash_nx_getput,
+	gl_hash_getremove, gl_hash_free): Likewise.
+	* lib/gl_hash_set.c (gl_hash_search, gl_hash_nx_add, gl_hash_remove,
+	gl_hash_free): Likewise.
+	* lib/gl_linkedhash_list.c (remove_from_bucket): Likewise.
+	* lib/gl_linkedhash_map.c (gl_linkedhash_search,
+	gl_linkedhash_nx_getput, gl_linkedhash_getremove, gl_linkedhash_free):
+	Likewise.
+	* lib/gl_linkedhash_set.c (gl_linkedhash_search, gl_linkedhash_nx_add,
+	gl_linkedhash_remove, gl_linkedhash_free): Likewise.
+	* lib/group-member.c (group_member, main): Likewise.
+	* lib/hash.c (hash_get_max_bucket_length, hash_table_ok, hash_lookup,
+	hash_get_first, hash_get_entries, hash_do_for_each, hash_clear,
+	hash_free, find_entry, transfer_entries, hash_print): Likewise.
+	* lib/hashcode-mem.c (hash_pjw_bare): Likewise.
+	* lib/hashcode-string2.c (hash_pjw): Likewise.
+	* lib/human.c (human_readable): Likewise.
+	* lib/i-ring.c (i_ring_init): Likewise.
+	* lib/idcache.c (getuser, getuidbyname, getgroup, getgidbyname):
+	Likewise.
+	* lib/inet_ntop.c (inet_ntop6): Likewise.
+	* lib/inet_pton.c (inet_pton6): Likewise.
+	* lib/ino-map.c (ino_hash): Likewise.
+	* lib/integer_length.c (integer_length): Likewise.
+	* lib/integer_length_l.c (FUNC): Likewise.
+	* lib/javacomp.c (compile_using_envjavac, compile_using_javac):
+	Likewise.
+	* lib/javaexec.c (execute_java_class): Likewise.
+	* lib/kwset.c (kwsprep): Likewise.
+	* lib/ldexpl.c (main): Likewise.
+	* lib/localeinfo.c (case_folded_counterparts): Likewise.
+	* lib/localename-unsafe.c (script_entry, gl_locale_name_canonicalize):
+	Likewise.
+	* lib/login_tty.c (login_tty): Likewise.
+	* lib/mbscasestr.c (knuth_morris_pratt_multibyte): Likewise.
+	* lib/mbsstr.c (knuth_morris_pratt_multibyte): Likewise.
+	* lib/md2.c (md2_finish_ctx, md2_update_chksum, md2_compress): Likewise.
+	* lib/md4.c (md4_process_block): Likewise.
+	* lib/mem-hash-map.c (resize): Likewise.
+	* lib/memcasecmp.c (memcasecmp): Likewise.
+	* lib/memchr.c (__memchr): Likewise.
+	* lib/memchr2.c (memchr2): Likewise.
+	* lib/memrchr.c (__memrchr): Likewise.
+	* lib/mgetgroups.c (mgetgroups): Likewise.
+	* lib/mktime.c (__mktime_internal): Likewise.
+	* lib/modechange.c (mode_compile): Likewise.
+	* lib/mountlist.c (unescape_tab, read_file_system_list): Likewise.
+	* lib/mpsort.c (mpsort_with_tmp): Likewise.
+	* lib/nproc.c (num_processors_via_affinity_mask): Likewise.
+	* lib/obstack.c (strong_alias): Likewise.
+	* lib/os2-spawn.c (prepare_spawn): Likewise.
+	* lib/pipe-filter-ii.c (WaitForMultipleObjects): Likewise.
+	* lib/pipe-safer.c (pipe_safer): Likewise.
+	* lib/pipe2-safer.c (pipe2_safer): Likewise.
+	* lib/poll.c (windows_compute_revents, poll): Likewise.
+	* lib/progreloc.c (find_executable): Likewise.
+	* lib/pselect.c (rpl_pselect): Likewise.
+	* lib/putenv.c (SetEnvironmentVariable): Likewise.
+	* lib/qsort.c (_quicksort): Likewise.
+	* lib/quotearg.c (quotearg_buffer_restyled, quotearg_free): Likewise.
+	* lib/random_r.c (__srandom_r): Likewise.
+	* lib/readtokens.c (readtoken): Likewise.
+	* lib/readutmp.c (read_utmp_from_systemd): Likewise.
+	* lib/regex-quote.c (regex_quote_length, regex_quote_copy): Likewise.
+	* lib/relocwrapper.c (relocate_libdirs, activate_libdirs): Likewise.
+	* lib/scandir.c (cancel_handler): Likewise.
+	* lib/select.c (windows_poll_handle, rpl_select): Likewise.
+	* lib/set-permissions.c (set_acls_from_mode): Likewise.
+	* lib/setlocale-fixes.c (fill_lc_all_name, setlocale_fixed): Likewise.
+	* lib/setlocale.c (search, setlocale_unixlike): Likewise.
+	* lib/setlocale_null-unlocked.c (setlocale_null_r_unlocked): Likewise.
+	* lib/sh-quote.c (shell_quote_argv): Likewise.
+	* lib/sha1.c (sha1_process_block): Likewise.
+	* lib/sha256.c (sha256_read_ctx, sha224_read_ctx, sha256_process_block):
+	Likewise.
+	* lib/sha512.c (sha512_read_ctx, sha384_read_ctx, sha512_process_block):
+	Likewise.
+	* lib/sig2str.c (str2signum, sig2str): Likewise.
+	* lib/sigprocmask.c (sigpending, sigprocmask): Likewise.
+	* lib/sm3.c (sm3_read_ctx, sm3_process_block): Likewise.
+	* lib/spawn_faction_destroy.c (posix_spawn_file_actions_destroy):
+	Likewise.
+	* lib/spawni.c (do_remaining_delayed_dup2, shrink_inheritable_handles,
+	close_inheritable_handles, __spawni): Likewise.
+	* lib/ssfmalloc-bitmap.h (init_bitmap_all_bits_clear,
+	init_bitmap_all_bits_set): Likewise.
+	* lib/ssfmalloc.h (add_update, drop_update,
+	allocate_medium_block_in_page, free_medium_block_in_page): Likewise.
+	* lib/stack-trace-impl.h (print_stack_trace_to): Likewise.
+	* lib/stat-time.h (stat_time_normalize): Likewise.
+	* lib/stat-w32.c (_gl_fstat_by_handle): Likewise.
+	* lib/stat.c (rpl_stat): Likewise.
+	* lib/stdopen.c (stdopen): Likewise.
+	* lib/str-kmp.h (knuth_morris_pratt): Likewise.
+	* lib/str-two-way.h (two_way_long_needle): Likewise.
+	* lib/strchrnul.c (strchrnul): Likewise.
+	* lib/strfmon_l.c (rpl_strfmon_l): Likewise.
+	* lib/strftime.c (underlying_strftime, __strftime_internal): Likewise.
+	* lib/striconveh.c (iconv_carefully, iconv_carefully_1, tmpbuf):
+	Likewise.
+	* lib/striconveha.c (mem_iconveha_notranslit, str_iconveha_notranslit):
+	Likewise.
+	* lib/string-desc.c (_sd_c_casecmp, sd_concat): Likewise.
+	* lib/strnlen.c (strnlen): Likewise.
+	* lib/strtod.c (parse_number): Likewise.
+	* lib/strtol.c (INTERNAL(strtol)): Likewise.
+	* lib/struniq.h (gl_lock_define_initialized): Likewise.
+	* lib/sys_select.in.h (rpl_fd_isset): Likewise.
+	* lib/sys_socket.in.h (rpl_fd_isset): Likewise.
+	* lib/system-quote.c (windows_createprocess_quote, windows_cmd_quote,
+	system_quote_argv): Likewise.
+	* lib/tempname.c (try_tempname_len): Likewise.
+	* lib/term-style-control.c (init_relevant_signal_set,
+	fatal_or_stopping_signal_handler, continuing_signal_handler,
+	ensure_other_signal_handlers): Likewise.
+	* lib/tsearch.c (check_tree): Likewise.
+	* lib/unicase/u-casemap.h (FUNC): Likewise.
+	* lib/unicase/u-ct-totitle.h (FUNC): Likewise.
+	* lib/uniconv/u-conv-from-enc.h (FUNC): Likewise.
+	* lib/uniconv/u-conv-to-enc.h (FUNC): Likewise.
+	* lib/uniconv/u8-conv-from-enc.c (u8_conv_from_encoding): Likewise.
+	* lib/unictype/3level.h (CONCAT(TABLE,_add), CONCAT(TABLE,_iterate),
+	CONCAT(TABLE,_finalize)): Likewise.
+	* lib/unictype/3levelbit.h (CONCAT(TABLE,_add), CONCAT(TABLE,_iterate),
+	CONCAT(TABLE,_finalize)): Likewise.
+	* lib/unigbrk/ulc-grapheme-breaks.c (ascii_grapheme_breaks,
+	ulc_grapheme_breaks): Likewise.
+	* lib/unilbrk/u8-possible-linebreaks.c (main): Likewise.
+	* lib/unilbrk/u8-width-linebreaks.c (main): Likewise.
+	* lib/unilbrk/ulc-possible-linebreaks.c
+	(ulc_possible_linebreaks_internal, main): Likewise.
+	* lib/unilbrk/ulc-width-linebreaks.c (ulc_width_linebreaks_internal,
+	main): Likewise.
+	* lib/uniname/uniname.c (unicode_character_name,
+	unicode_name_character): Likewise.
+	* lib/uninorm/u-normalize-internal.h (FUNC): Likewise.
+	* lib/uninorm/uninorm-filter.c (uninorm_filter_write,
+	uninorm_filter_flush): Likewise.
+	* lib/uniwbrk/u8-wordbreaks.c (main): Likewise.
+	* lib/uniwbrk/ulc-wordbreaks.c (ulc_wordbreaks, main): Likewise.
+	* lib/userspec.c (main): Likewise.
+	* lib/vasnprintf.c (multiply, divide, convert_to_decimal,
+	decode_long_double, decode_double, scale10_round_decimal_decoded,
+	VASNPRINTF): Likewise.
+	* lib/vma-iter.c (vma_iterate): Likewise.
+	* lib/windows-cond.c (glwthread_waitqueue_notify_all): Likewise.
+	* lib/windows-path.c (extended_PATH, extended_environ): Likewise.
+	* lib/windows-rwlock.c (glwthread_waitqueue_add,
+	glwthread_waitqueue_notify_all): Likewise.
+	* lib/windows-spawn.c (quoted_arg_length, quoted_arg_string,
+	prepare_spawn, compose_command, compose_envblock,
+	init_inheritable_handles, compose_handles_block): Likewise.
+	* lib/windows-timedrwlock.c (glwthread_waitqueue_notify_all): Likewise.
+	* lib/windows-tls.c (glwthread_tls_process_destructors,
+	glwthread_tls_key_delete): Likewise.
+	* lib/xstring-desc.c (xsd_concat): Likewise.
+	* lib/xvasprintf.c (xstrcat, xvasprintf): Likewise.
+	* lib/newlocale.c (newlocale): Likewise. Move the fail_with_err label
+	into the loop.
+
 2025-11-18  Bruno Haible  <bruno@clisp.org>
 
 	nstrftime, fprintftime: Fix a -Wshadow=local warning (regr. 2024-02-08).
diff --git a/lib/acl-internal.c b/lib/acl-internal.c
index b8a6ed06c3..7d7cbb7981 100644
--- a/lib/acl-internal.c
+++ b/lib/acl-internal.c
@@ -161,9 +161,7 @@ acl_default_nontrivial (acl_t acl)
 int
 acl_nontrivial (int count, aclent_t *entries)
 {
-  int i;
-
-  for (i = 0; i < count; i++)
+  for (int i = 0; i < count; i++)
     {
       aclent_t *ace = &entries[i];
 
@@ -192,8 +190,6 @@ acl_nontrivial (int count, aclent_t *entries)
 int
 acl_ace_nontrivial (int count, ace_t *entries)
 {
-  int i;
-
   /* The flags in the ace_t structure changed in a binary incompatible way
      when ACL_NO_TRIVIAL etc. were introduced in <sys/acl.h> version 1.15.
      How to distinguish the two conventions at runtime?
@@ -202,7 +198,7 @@ acl_ace_nontrivial (int count, ace_t *entries)
      convention, these values are not used.  */
   int old_convention = 0;
 
-  for (i = 0; i < count; i++)
+  for (int i = 0; i < count; i++)
     if (entries[i].a_flags & (OLD_ACE_OWNER | OLD_ACE_GROUP | OLD_ACE_OTHER))
       {
         old_convention = 1;
@@ -211,7 +207,7 @@ acl_ace_nontrivial (int count, ace_t *entries)
 
   if (old_convention)
     /* Running on Solaris 10.  */
-    for (i = 0; i < count; i++)
+    for (int i = 0; i < count; i++)
       {
         ace_t *ace = &entries[i];
 
@@ -238,7 +234,7 @@ acl_ace_nontrivial (int count, ace_t *entries)
           0  /* everyone@ allow */
         };
 
-      for (i = 0; i < count; i++)
+      for (int i = 0; i < count; i++)
         {
           ace_t *ace = &entries[i];
           unsigned int index1;
@@ -374,12 +370,10 @@ acl_ace_nontrivial (int count, ace_t *entries)
 int
 acl_nontrivial (int count, struct acl_entry *entries)
 {
-  int i;
-
   if (count > 3)
     return 1;
 
-  for (i = 0; i < count; i++)
+  for (int i = 0; i < count; i++)
     {
       struct acl_entry *ace = &entries[i];
 
@@ -396,9 +390,7 @@ acl_nontrivial (int count, struct acl_entry *entries)
 int
 aclv_nontrivial (int count, struct acl *entries)
 {
-  int i;
-
-  for (i = 0; i < count; i++)
+  for (int i = 0; i < count; i++)
     {
       struct acl *ace = &entries[i];
 
@@ -424,10 +416,8 @@ int
 acl_nontrivial (struct acl *a)
 {
   /* The normal way to iterate through an ACL is like this:
-       struct acl_entry *ace;
-       for (ace = a->acl_ext; ace != acl_last (a); ace = acl_nxt (ace))
+       for (struct acl_entry *ace = a->acl_ext; ace != acl_last (a); ace = acl_nxt (ace))
          {
-           struct ace_id *aei;
            switch (ace->ace_type)
              {
              case ACC_PERMIT:
@@ -435,7 +425,7 @@ acl_nontrivial (struct acl *a)
              case ACC_SPECIFY:
                ...;
              }
-           for (aei = ace->ace_id; aei != id_last (ace); aei = id_nxt (aei))
+           for (struct ace_id *aei = ace->ace_id; aei != id_last (ace); aei = id_nxt (aei))
              ...
          }
    */
@@ -453,9 +443,8 @@ acl_nfs4_nontrivial (nfs4_acl_int_t *a)
   return (a->aclEntryN > 0 ? 1 : 0);
 #  else
   int count = a->aclEntryN;
-  int i;
 
-  for (i = 0; i < count; i++)
+  for (int i = 0; i < count; i++)
     {
       nfs4_ace_int_t *ace = &a->aclEntry[i];
 
@@ -484,9 +473,7 @@ acl_nfs4_nontrivial (nfs4_acl_int_t *a)
 int
 acl_nontrivial (int count, struct acl *entries)
 {
-  int i;
-
-  for (i = 0; i < count; i++)
+  for (int i = 0; i < count; i++)
     {
       struct acl *ace = &entries[i];
 
diff --git a/lib/arcfour.c b/lib/arcfour.c
index 595bbe86a4..67e8b9f48b 100644
--- a/lib/arcfour.c
+++ b/lib/arcfour.c
@@ -56,12 +56,13 @@ arcfour_stream (arcfour_context * context, const char *inbuf, char *outbuf,
 void
 arcfour_setkey (arcfour_context * context, const char *key, size_t keylen)
 {
-  size_t i, j, k;
   char *sbox = context->sbox;
 
   context->idx_i = context->idx_j = 0;
-  for (i = 0; i < ARCFOUR_SBOX_SIZE; i++)
+  for (size_t i = 0; i < ARCFOUR_SBOX_SIZE; i++)
     sbox[i] = i;
+
+  size_t i, j, k;
   for (i = j = k = 0; i < ARCFOUR_SBOX_SIZE; i++)
     {
       char t;
diff --git a/lib/arctwo.c b/lib/arctwo.c
index 7e1dc93efe..e56cba4145 100644
--- a/lib/arctwo.c
+++ b/lib/arctwo.c
@@ -80,7 +80,7 @@ arctwo_encrypt (arctwo_context *context, const char *inbuf,
   for (; length >= ARCTWO_BLOCK_SIZE; length -= ARCTWO_BLOCK_SIZE,
          inbuf += ARCTWO_BLOCK_SIZE, outbuf += ARCTWO_BLOCK_SIZE)
     {
-      size_t i, j;
+      size_t j;
       uint16_t word0 = 0, word1 = 0, word2 = 0, word3 = 0;
 
       word0 = (word0 << 8) | to_uchar (inbuf[1]);
@@ -92,7 +92,7 @@ arctwo_encrypt (arctwo_context *context, const char *inbuf,
       word3 = (word3 << 8) | to_uchar (inbuf[7]);
       word3 = (word3 << 8) | to_uchar (inbuf[6]);
 
-      for (i = 0; i < 16; i++)
+      for (size_t i = 0; i < 16; i++)
         {
           j = i * 4;
           /* For some reason I cannot combine those steps. */
@@ -135,7 +135,7 @@ arctwo_decrypt (arctwo_context *context, const char *inbuf,
   for (; length >= ARCTWO_BLOCK_SIZE; length -= ARCTWO_BLOCK_SIZE,
          inbuf += ARCTWO_BLOCK_SIZE, outbuf += ARCTWO_BLOCK_SIZE)
     {
-      size_t i, j;
+      size_t j;
       uint16_t word0 = 0, word1 = 0, word2 = 0, word3 = 0;
 
       word0 = (word0 << 8) | to_uchar (inbuf[1]);
@@ -147,7 +147,7 @@ arctwo_decrypt (arctwo_context *context, const char *inbuf,
       word3 = (word3 << 8) | to_uchar (inbuf[7]);
       word3 = (word3 << 8) | to_uchar (inbuf[6]);
 
-      for (i = 16; i > 0; i--)
+      for (size_t i = 16; i > 0; i--)
         {
           j = (i - 1) * 4;
 
@@ -187,7 +187,6 @@ void
 arctwo_setkey_ekb (arctwo_context *context,
                    size_t keylen, const char *key, size_t effective_keylen)
 {
-  size_t i;
   uint8_t *S, x;
 
   if (keylen < 40 / 8 || effective_keylen > 1024)
@@ -195,10 +194,10 @@ arctwo_setkey_ekb (arctwo_context *context,
 
   S = (uint8_t *) context->S;
 
-  for (i = 0; i < keylen; i++)
+  for (size_t i = 0; i < keylen; i++)
     S[i] = (uint8_t) key[i];
 
-  for (i = keylen; i < 128; i++)
+  for (size_t i = keylen; i < 128; i++)
     S[i] = arctwo_sbox[(S[i - keylen] + S[i - 1]) & 255];
 
   S[0] = arctwo_sbox[S[0]];
@@ -209,7 +208,7 @@ arctwo_setkey_ekb (arctwo_context *context,
   if (effective_keylen)
     {
       size_t len = (effective_keylen + 7) >> 3;
-      i = 128 - len;
+      size_t i = 128 - len;
       x = arctwo_sbox[S[i] & (255 >> (7 & -effective_keylen))];
       S[i] = x;
 
@@ -221,6 +220,6 @@ arctwo_setkey_ekb (arctwo_context *context,
     }
 
   /* Make the expanded key, endian independent. */
-  for (i = 0; i < 64; i++)
+  for (size_t i = 0; i < 64; i++)
     context->S[i] = ((uint16_t) S[i * 2] | (((uint16_t) S[i * 2 + 1]) << 8));
 }
diff --git a/lib/argmatch.c b/lib/argmatch.c
index a1efc6fa22..301db760a7 100644
--- a/lib/argmatch.c
+++ b/lib/argmatch.c
@@ -80,7 +80,6 @@ ptrdiff_t
 argmatch (const char *arg, const char *const *arglist,
           const void *vallist, size_t valsize)
 {
-  size_t i;                     /* Temporary index in ARGLIST.  */
   size_t arglen;                /* Length of ARG.  */
   ptrdiff_t matchind = -1;      /* Index of first nonexact match.  */
   bool ambiguous = false;       /* If true, multiple nonexact match(es).  */
@@ -88,7 +87,7 @@ argmatch (const char *arg, const char *const *arglist,
   arglen = strlen (arg);
 
   /* Test all elements for either exact match or abbreviated matches.  */
-  for (i = 0; arglist[i]; i++)
+  for (size_t i = 0; arglist[i]; i++)
     {
       if (!strncmp (arglist[i], arg, arglen))
         {
@@ -121,10 +120,8 @@ argmatch (const char *arg, const char *const *arglist,
 ptrdiff_t
 argmatch_exact (const char *arg, const char *const *arglist)
 {
-  size_t i;
-
   /* Test elements for exact match.  */
-  for (i = 0; arglist[i]; i++)
+  for (size_t i = 0; arglist[i]; i++)
     {
       if (streq (arglist[i], arg))
         return i;
@@ -157,13 +154,12 @@ void
 argmatch_valid (const char *const *arglist,
                 const void *vallist, size_t valsize)
 {
-  size_t i;
   const char *last_val = NULL;
 
   /* We try to put synonyms on the same line.  The assumption is that
      synonyms follow each other */
   fputs (_("Valid arguments are:"), stderr);
-  for (i = 0; arglist[i]; i++)
+  for (size_t i = 0; arglist[i]; i++)
     if ((i == 0)
         || !memeq (last_val, (char const *) vallist + valsize * i, valsize))
       {
@@ -216,9 +212,7 @@ argmatch_to_argument (const void *value,
                       const char *const *arglist,
                       const void *vallist, size_t valsize)
 {
-  size_t i;
-
-  for (i = 0; arglist[i]; i++)
+  for (size_t i = 0; arglist[i]; i++)
     if (memeq (value, (char const *) vallist + valsize * i, valsize))
       return arglist[i];
   return NULL;
diff --git a/lib/argz.c b/lib/argz.c
index ed49e7205e..9b983b717d 100644
--- a/lib/argz.c
+++ b/lib/argz.c
@@ -250,12 +250,11 @@ argz_extract (const char *argz, size_t len, char **argv)
 error_t
 argz_create (char *const argv[], char **argz, size_t *len)
 {
-  int argc;
   size_t tlen = 0;
   char *const *ap;
   char *p;
 
-  for (argc = 0; argv[argc] != NULL; ++argc)
+  for (int argc = 0; argv[argc] != NULL; ++argc)
     tlen += strlen (argv[argc]) + 1;
 
   if (tlen == 0)
diff --git a/lib/argz.in.h b/lib/argz.in.h
index c201c2036d..28924bacba 100644
--- a/lib/argz.in.h
+++ b/lib/argz.in.h
@@ -123,8 +123,7 @@ extern error_t argz_replace (char **restrict /*argz*/,
 
    or
 
-    char *entry;
-    for (entry = argz; entry; entry = argz_next (argz, argz_len, entry))
+    for (char *entry = argz; entry; entry = argz_next (argz, argz_len, entry))
       ...;
 */
 
diff --git a/lib/basename-lgpl.c b/lib/basename-lgpl.c
index 2aecb0dd00..0d712ecdc3 100644
--- a/lib/basename-lgpl.c
+++ b/lib/basename-lgpl.c
@@ -29,13 +29,12 @@ char *
 last_component (char const *name)
 {
   char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
-  char const *p;
   bool last_was_slash = false;
 
   while (ISSLASH (*base))
     base++;
 
-  for (p = base; *p; p++)
+  for (char const *p = base; *p; p++)
     {
       if (ISSLASH (*p))
         last_was_slash = true;
diff --git a/lib/bcp47.c b/lib/bcp47.c
index dc7e06e28b..67fd524709 100644
--- a/lib/bcp47.c
+++ b/lib/bcp47.c
@@ -274,8 +274,7 @@ xpg_to_bcp47 (char *bcp47, const char *xpg)
   /* Determine script from the modifier.  */
   if (modifier_len > 0)
     {
-      size_t i;
-      for (i = 0; i < NUM_SCRIPTS; i++)
+      for (size_t i = 0; i < NUM_SCRIPTS; i++)
         if (strlen (scripts[i].name) == modifier_len
             && memeq (scripts[i].name, modifier_start, modifier_len))
           script_subtag = scripts[i].code;
@@ -457,11 +456,8 @@ bcp47_to_xpg (char *xpg, const char *bcp47, const char *codeset)
     goto fail;
 
   /* Copy the language to the result buffer, converting it to lower case.  */
-  {
-    size_t i;
-    for (i = 0; i < language_len; i++)
-      xpg[i] = c_tolower (language_start[i]);
-  }
+  for (size_t i = 0; i < language_len; i++)
+    xpg[i] = c_tolower (language_start[i]);
 
   /* Canonicalize the language.  */
   /* For Quechua, Microsoft uses the ISO 639-3 code "quz" instead of the
@@ -482,11 +478,8 @@ bcp47_to_xpg (char *xpg, const char *bcp47, const char *codeset)
   /* Copy the region to a temporary buffer, converting it to upper case.  */
   char territory[3];
   size_t territory_len = region_len; /* == 2 or 3 */
-  {
-    size_t i;
-    for (i = 0; i < region_len; i++)
-      territory[i] = c_toupper (region_start[i]);
-  }
+  for (size_t i = 0; i < region_len; i++)
+    territory[i] = c_toupper (region_start[i]);
 
   /* Determine script from the script subtag.  */
   const char *script = NULL;
@@ -494,8 +487,7 @@ bcp47_to_xpg (char *xpg, const char *bcp47, const char *codeset)
   if (script_len > 0)
     {
       /* Here script_len == 4.  */
-      size_t i;
-      for (i = 0; i < NUM_SCRIPTS; i++)
+      for (size_t i = 0; i < NUM_SCRIPTS; i++)
         if (c_toupper (script_start[0] == scripts[i].code[0])
             && c_tolower (script_start[1] == scripts[i].code[1])
             && c_tolower (script_start[2] == scripts[i].code[2])
diff --git a/lib/bitset/list.c b/lib/bitset/list.c
index 15ac51945d..9d30274a48 100644
--- a/lib/bitset/list.c
+++ b/lib/bitset/list.c
@@ -787,16 +787,14 @@ lbitset_list (bitset bset, bitset_bindex *list,
 static bool
 lbitset_empty_p (bitset dst)
 {
-  lbitset_elt *elt;
-  lbitset_elt *next;
-
-  for (elt = LBITSET_HEAD (dst); elt; elt = next)
+  for (lbitset_elt *elt = LBITSET_HEAD (dst); elt; )
     {
-      next = elt->next;
+      lbitset_elt *next = elt->next;
       if (!lbitset_elt_zero_p (elt))
         return false;
       /* Weed as we go.  */
       lbitset_elt_unlink (dst, elt);
+      elt = next;
     }
 
   return true;
diff --git a/lib/bitset/vector.c b/lib/bitset/vector.c
index e6f00a08ba..efd73d4b37 100644
--- a/lib/bitset/vector.c
+++ b/lib/bitset/vector.c
@@ -893,8 +893,7 @@ vbitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
   bitset_windex size = VBITSET_SIZE (dst);
 
   bool changed = false;
-  unsigned i;
-  for (i = 0; i < size; i++, dstp++)
+  for (unsigned int i = 0; i < size; i++)
     {
       bitset_word tmp = (*src1p++ | *src2p++) & *src3p++;
 
@@ -903,6 +902,7 @@ vbitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
           changed = true;
           *dstp = tmp;
         }
+      dstp++;
     }
   return changed;
 }
diff --git a/lib/classpath.c b/lib/classpath.c
index e7df756cbd..6ecf0d4ec5 100644
--- a/lib/classpath.c
+++ b/lib/classpath.c
@@ -54,7 +54,6 @@ new_classpath (const char * const *classpaths, unsigned int classpaths_count,
 {
   const char *old_classpath;
   unsigned int length;
-  unsigned int i;
   char *result;
   char *p;
 
@@ -63,7 +62,7 @@ new_classpath (const char * const *classpaths, unsigned int classpaths_count,
     old_classpath = "";
 
   length = 0;
-  for (i = 0; i < classpaths_count; i++)
+  for (unsigned int i = 0; i < classpaths_count; i++)
     length += strlen (classpaths[i]) + 1;
   length += strlen (old_classpath);
   if (classpaths_count > 0 && old_classpath[0] == '\0')
@@ -71,7 +70,7 @@ new_classpath (const char * const *classpaths, unsigned int classpaths_count,
 
   result = XNMALLOC (length + 1, char);
   p = result;
-  for (i = 0; i < classpaths_count; i++)
+  for (unsigned int i = 0; i < classpaths_count; i++)
     {
       memcpy (p, classpaths[i], strlen (classpaths[i]));
       p += strlen (classpaths[i]);
diff --git a/lib/clean-temp-simple.c b/lib/clean-temp-simple.c
index aae2290daa..34af089d55 100644
--- a/lib/clean-temp-simple.c
+++ b/lib/clean-temp-simple.c
@@ -159,8 +159,6 @@ clean_temp_init_asyncsafe_close (void)
 static _GL_ASYNC_SAFE void
 cleanup_action (_GL_UNUSED int sig)
 {
-  size_t i;
-
   /* First close all file descriptors to temporary files.  */
   {
     gl_list_t fds = descriptors;
@@ -197,7 +195,7 @@ cleanup_action (_GL_UNUSED int sig)
       }
   }
 
-  for (i = 0; i < dir_cleanup_list.tempdir_count; i++)
+  for (size_t i = 0; i < dir_cleanup_list.tempdir_count; i++)
     {
       struct tempdir *dir = dir_cleanup_list.tempdir_list[i];
 
diff --git a/lib/clean-temp.c b/lib/clean-temp.c
index a0b7ed99f6..8c62275886 100644
--- a/lib/clean-temp.c
+++ b/lib/clean-temp.c
@@ -152,13 +152,12 @@ create_temp_dir (const char *prefix, const char *parentdir,
 
   struct tempdir * volatile *tmpdirp = NULL;
   struct tempdir *tmpdir;
-  size_t i;
   char *xtemplate;
   char *tmpdirname;
 
   /* See whether it can take the slot of an earlier temporary directory
      already cleaned up.  */
-  for (i = 0; i < dir_cleanup_list.tempdir_count; i++)
+  for (size_t i = 0; i < dir_cleanup_list.tempdir_count; i++)
     if (dir_cleanup_list.tempdir_list[i] == NULL)
       {
         tmpdirp = &dir_cleanup_list.tempdir_list[i];
@@ -188,9 +187,7 @@ create_temp_dir (const char *prefix, const char *parentdir,
               /* Don't use memcpy() here, because memcpy takes non-volatile
                  arguments and is therefore not guaranteed to complete all
                  memory stores before the next statement.  */
-              size_t k;
-
-              for (k = 0; k < old_allocated; k++)
+              for (size_t k = 0; k < old_allocated; k++)
                 new_array[k] = old_array[k];
             }
 
@@ -460,12 +457,11 @@ cleanup_temp_dir (struct temp_dir *dir)
 
   struct tempdir *tmpdir = (struct tempdir *)dir;
   int err = 0;
-  size_t i;
 
   err |= cleanup_temp_dir_contents (dir);
   err |= do_rmdir (tmpdir->dirname, dir->cleanup_verbose);
 
-  for (i = 0; i < dir_cleanup_list.tempdir_count; i++)
+  for (size_t i = 0; i < dir_cleanup_list.tempdir_count; i++)
     if (dir_cleanup_list.tempdir_list[i] == tmpdir)
       {
         /* Remove dir_cleanup_list.tempdir_list[i].  */
diff --git a/lib/count-leading-zeros.h b/lib/count-leading-zeros.h
index c28c52653d..a737e92d96 100644
--- a/lib/count-leading-zeros.h
+++ b/lib/count-leading-zeros.h
@@ -64,11 +64,10 @@ extern unsigned char _BitScanReverse64 (unsigned long *, unsigned long long);
 # define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE)                \
     do                                                                  \
       {                                                                 \
-        int count;                                                      \
         unsigned int leading_32;                                        \
         if (! x)                                                        \
           return CHAR_BIT * sizeof x;                                   \
-        for (count = 0;                                                 \
+        for (int count = 0;                                             \
              (leading_32 = ((x >> (sizeof (TYPE) * CHAR_BIT - 32))      \
                             & 0xffffffffU),                             \
               count < CHAR_BIT * sizeof x - 32 && !leading_32);         \
diff --git a/lib/count-one-bits.h b/lib/count-one-bits.h
index 43c10b3615..278ce66e59 100644
--- a/lib/count-one-bits.h
+++ b/lib/count-one-bits.h
@@ -65,8 +65,7 @@ count_one_bits_32 (unsigned int x)
     do                                                                  \
       {                                                                 \
         int count = 0;                                                  \
-        int bits;                                                       \
-        for (bits = 0; bits < sizeof (TYPE) * CHAR_BIT; bits += 32)     \
+        for (int bits = 0; bits < sizeof (TYPE) * CHAR_BIT; bits += 32) \
           {                                                             \
             count += count_one_bits_32 (x);                             \
             x = x >> 31 >> 1;                                           \
diff --git a/lib/count-trailing-zeros.h b/lib/count-trailing-zeros.h
index edcae66bfa..bc2001255b 100644
--- a/lib/count-trailing-zeros.h
+++ b/lib/count-trailing-zeros.h
@@ -62,10 +62,9 @@ extern unsigned char _BitScanForward64 (unsigned long *, unsigned long long);
 # define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE)               \
     do                                                                  \
       {                                                                 \
-        int count = 0;                                                  \
         if (! x)                                                        \
           return CHAR_BIT * sizeof x;                                   \
-        for (count = 0;                                                 \
+        for (int count = 0;                                             \
              (count < CHAR_BIT * sizeof x - 32                          \
               && ! (x & 0xffffffffU));                                  \
              count += 32)                                               \
diff --git a/lib/crc-generate-table.c b/lib/crc-generate-table.c
index 6c614374bf..84df10f491 100644
--- a/lib/crc-generate-table.c
+++ b/lib/crc-generate-table.c
@@ -45,11 +45,10 @@ make_crc_table (int bits)
 {
   unsigned long c;
 
-  int n, k;
-  for (n = 0; n < 256; n++)
+  for (int n = 0; n < 256; n++)
     {
       c = (unsigned long) n;
-      for (k = 0; k < bits; k++)
+      for (int k = 0; k < bits; k++)
         {
           if (c & 1)
             c = 0xedb88320L ^ (c >> 1);
diff --git a/lib/crc.c b/lib/crc.c
index 6847764d50..9551a3db82 100644
--- a/lib/crc.c
+++ b/lib/crc.c
@@ -93,7 +93,7 @@ crc32_update_no_xor_slice_by_n (uint32_t crc, const char *buf,
                                 size_t num_bytes)
 {
   uint64_t local_buf;
-  size_t i, shift_amount;
+  size_t shift_amount;
 
   memcpy (&local_buf, buf, num_bytes);
   local_buf = le64toh (local_buf) ^ crc;
@@ -103,7 +103,7 @@ crc32_update_no_xor_slice_by_n (uint32_t crc, const char *buf,
   else
     crc = crc >> (num_bytes * 8);
 
-  for (i = 0; i < num_bytes; i++)
+  for (size_t i = 0; i < num_bytes; i++)
     {
       shift_amount = ((num_bytes - i - 1) * 8);
       crc = crc ^ crc32_sliceby8_table[i][(local_buf >> shift_amount) & 0xFF];
@@ -196,8 +196,6 @@ static const uint32_t crc32_table[256] = {
 uint32_t
 crc32_update_no_xor (uint32_t crc, const char *buf, size_t len)
 {
-  size_t n;
-
 #ifdef GL_CRC_X86_64_PCLMUL
   if (!pclmul_checked)
     {
@@ -210,7 +208,7 @@ crc32_update_no_xor (uint32_t crc, const char *buf, size_t len)
     return crc32_update_no_xor_pclmul (crc, buf, len);
 #endif
 
-  for (n = 0; n < len; n++)
+  for (size_t n = 0; n < len; n++)
     crc = crc32_table[(crc ^ buf[n]) & 0xff] ^ (crc >> 8);
 
   return crc;
diff --git a/lib/csharpcomp.c b/lib/csharpcomp.c
index 50f8c80403..39954b72bb 100644
--- a/lib/csharpcomp.c
+++ b/lib/csharpcomp.c
@@ -154,7 +154,6 @@ compile_csharp_using_mono (const char * const *sources,
       size_t linelen[2];
       unsigned int l;
       int exitstatus;
-      unsigned int i;
 
       argc =
         1 + (output_is_library ? 1 : 0) + 1 + libdirs_count + libraries_count
@@ -171,14 +170,14 @@ compile_csharp_using_mono (const char * const *sources,
         strcpy (option + 5, output_file);
         *argp++ = option;
       }
-      for (i = 0; i < libdirs_count; i++)
+      for (unsigned int i = 0; i < libdirs_count; i++)
         {
           char *option = (char *) xmalloca (5 + strlen (libdirs[i]) + 1);
           memcpy (option, "-lib:", 5);
           strcpy (option + 5, libdirs[i]);
           *argp++ = option;
         }
-      for (i = 0; i < libraries_count; i++)
+      for (unsigned int i = 0; i < libraries_count; i++)
         {
           char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
           memcpy (option, "-reference:", 11);
@@ -188,7 +187,7 @@ compile_csharp_using_mono (const char * const *sources,
         }
       if (debug)
         *argp++ = "-debug";
-      for (i = 0; i < sources_count; i++)
+      for (unsigned int i = 0; i < sources_count; i++)
         {
           const char *source_file = sources[i];
           if (strlen (source_file) >= 10
@@ -251,12 +250,12 @@ compile_csharp_using_mono (const char * const *sources,
       exitstatus =
         wait_subprocess (child, "mcs", false, false, true, true, NULL);
 
-      for (i = 1 + (output_is_library ? 1 : 0);
+      for (unsigned int i = 1 + (output_is_library ? 1 : 0);
            i < 1 + (output_is_library ? 1 : 0)
                + 1 + libdirs_count + libraries_count;
            i++)
         freea ((char *) argv[i]);
-      for (i = 0; i < sources_count; i++)
+      for (unsigned int i = 0; i < sources_count; i++)
         if (argv[argc - sources_count + i] != sources[i])
           freea ((char *) argv[argc - sources_count + i]);
       freea (argv);
@@ -542,7 +541,6 @@ compile_csharp_using_dotnet (const char * const *sources,
       const char **argv;
       const char **argp;
       int exitstatus;
-      unsigned int i;
 
       /* Get a list of all *.dll files in dotnet_runtime_dir.  */
       num_dlls = scandir (dotnet_runtime_dir, &dlls, name_is_dll, alphasort);
@@ -585,7 +583,7 @@ compile_csharp_using_dotnet (const char * const *sources,
         strcpy (option + 5, output_file_converted);
         *argp++ = option;
       }
-      for (i = 0; i < libdirs_count; i++)
+      for (unsigned int i = 0; i < libdirs_count; i++)
         {
           const char *libdir = libdirs[i];
           char *libdir_converted = cygpath_w (libdir);
@@ -595,7 +593,7 @@ compile_csharp_using_dotnet (const char * const *sources,
           strcpy (option + 5, libdir_converted);
           *argp++ = option;
         }
-      for (i = 0; i < libraries_count; i++)
+      for (unsigned int i = 0; i < libraries_count; i++)
         {
           char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
           memcpy (option, "-reference:", 11);
@@ -607,7 +605,7 @@ compile_csharp_using_dotnet (const char * const *sources,
         *argp++ = "-optimize+";
       if (debug)
         *argp++ = "-debug+";
-      for (i = 0; i < sources_count; i++)
+      for (unsigned int i = 0; i < sources_count; i++)
         {
           const char *source_file = sources[i];
           char *source_file_converted = cygpath_w (source_file);
@@ -638,7 +636,7 @@ compile_csharp_using_dotnet (const char * const *sources,
         strcpy (option + 5, dotnet_runtime_dir_converted);
         *argp++ = option;
       }
-      for (i = 0; i < num_dlls; i++)
+      for (unsigned int i = 0; i < num_dlls; i++)
         {
           char *option = (char *) xmalloca (11 + strlen (dlls[i]->d_name) + 1);
           memcpy (option, "-reference:", 11);
@@ -661,9 +659,9 @@ compile_csharp_using_dotnet (const char * const *sources,
                             false, false, false, false,
                             true, true, NULL);
 
-      for (i = 4; i < 5 + libdirs_count + libraries_count; i++)
+      for (unsigned int i = 4; i < 5 + libdirs_count + libraries_count; i++)
         freea ((char *) argv[i]);
-      for (i = 0; i < 1 + num_dlls; i++)
+      for (unsigned int i = 0; i < 1 + num_dlls; i++)
         freea ((char *) argv[argc - (1 + num_dlls) + i]);
       while (mallocedp > malloced)
         free (*--mallocedp);
@@ -673,7 +671,7 @@ compile_csharp_using_dotnet (const char * const *sources,
       free (csc);
       free (roslyn_bin_dir);
       free (roslyn_dir);
-      for (i = 0; i < num_dlls; i++)
+      for (unsigned int i = 0; i < num_dlls; i++)
         free (dlls[i]);
       free (dlls);
 
@@ -750,7 +748,6 @@ compile_csharp_using_dotnet (const char * const *sources,
           const char **argv;
           const char **argp;
           int exitstatus;
-          unsigned int i;
 
           /* Here, we assume that 'csc' is a native Windows program, therefore
              we need to use cygpath_w.  */
@@ -776,7 +773,7 @@ compile_csharp_using_dotnet (const char * const *sources,
             strcpy (option + 5, output_file_converted);
             *argp++ = option;
           }
-          for (i = 0; i < libdirs_count; i++)
+          for (unsigned int i = 0; i < libdirs_count; i++)
             {
               const char *libdir = libdirs[i];
               char *libdir_converted = cygpath_w (libdir);
@@ -786,7 +783,7 @@ compile_csharp_using_dotnet (const char * const *sources,
               strcpy (option + 5, libdir_converted);
               *argp++ = option;
             }
-          for (i = 0; i < libraries_count; i++)
+          for (unsigned int i = 0; i < libraries_count; i++)
             {
               char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
               memcpy (option, "-reference:", 11);
@@ -798,7 +795,7 @@ compile_csharp_using_dotnet (const char * const *sources,
             *argp++ = "-optimize+";
           if (debug)
             *argp++ = "-debug+";
-          for (i = 0; i < sources_count; i++)
+          for (unsigned int i = 0; i < sources_count; i++)
             {
               const char *source_file = sources[i];
               char *source_file_converted = cygpath_w (source_file);
@@ -834,7 +831,7 @@ compile_csharp_using_dotnet (const char * const *sources,
                                 false, false, false, false,
                                 true, true, NULL);
 
-          for (i = 3; i < 4 + libdirs_count + libraries_count; i++)
+          for (unsigned int i = 3; i < 4 + libdirs_count + libraries_count; i++)
             freea ((char *) argv[i]);
           while (mallocedp > malloced)
             free (*--mallocedp);
@@ -921,7 +918,6 @@ compile_csharp_using_sscli (const char * const *sources,
       const char **argv;
       const char **argp;
       int exitstatus;
-      unsigned int i;
 
       /* Here, we assume that 'csc' is a native Windows program, therefore
          we need to use cygpath_w.  */
@@ -947,7 +943,7 @@ compile_csharp_using_sscli (const char * const *sources,
         strcpy (option + 5, output_file_converted);
         *argp++ = option;
       }
-      for (i = 0; i < libdirs_count; i++)
+      for (unsigned int i = 0; i < libdirs_count; i++)
         {
           const char *libdir = libdirs[i];
           char *libdir_converted = cygpath_w (libdir);
@@ -957,7 +953,7 @@ compile_csharp_using_sscli (const char * const *sources,
           strcpy (option + 5, libdir_converted);
           *argp++ = option;
         }
-      for (i = 0; i < libraries_count; i++)
+      for (unsigned int i = 0; i < libraries_count; i++)
         {
           char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
           memcpy (option, "-reference:", 11);
@@ -969,7 +965,7 @@ compile_csharp_using_sscli (const char * const *sources,
         *argp++ = "-optimize+";
       if (debug)
         *argp++ = "-debug+";
-      for (i = 0; i < sources_count; i++)
+      for (unsigned int i = 0; i < sources_count; i++)
         {
           const char *source_file = sources[i];
           char *source_file_converted = cygpath_w (source_file);
@@ -1005,7 +1001,7 @@ compile_csharp_using_sscli (const char * const *sources,
                             false, false, false, false,
                             true, true, NULL);
 
-      for (i = 3; i < 4 + libdirs_count + libraries_count; i++)
+      for (unsigned int i = 3; i < 4 + libdirs_count + libraries_count; i++)
         freea ((char *) argv[i]);
       while (mallocedp > malloced)
         free (*--mallocedp);
diff --git a/lib/csharpexec.c b/lib/csharpexec.c
index 8e3f7983f0..26e787c493 100644
--- a/lib/csharpexec.c
+++ b/lib/csharpexec.c
@@ -144,7 +144,6 @@ execute_csharp_using_mono (const char *assembly_path,
       char *old_monopath;
       const char **argv =
         (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
-      unsigned int i;
       bool err;
 
       /* Set MONO_PATH.  */
@@ -152,7 +151,7 @@ execute_csharp_using_mono (const char *assembly_path,
 
       argv[0] = "mono";
       argv[1] = assembly_path;
-      for (i = 0; i <= nargs; i++)
+      for (unsigned int i = 0; i <= nargs; i++)
         argv[2 + i] = args[i];
 
       if (verbose)
@@ -226,8 +225,7 @@ execute_csharp_using_dotnet (const char *assembly_path,
           /* Copy the DLLs.  */
           char *assembly_dir = dir_name (assembly_path);
 
-          unsigned int l;
-          for (l = 0; l < libdirs_count; l++)
+          for (unsigned int l = 0; l < libdirs_count; l++)
             {
               const char *libdir = libdirs[l];
 
@@ -244,8 +242,7 @@ execute_csharp_using_dotnet (const char *assembly_path,
                   num_dlls = 0;
                 }
 
-              int i;
-              for (i = 0; i < num_dlls; i++)
+              for (int i = 0; i < num_dlls; i++)
                 {
                   char *target_dll =
                     xconcatenated_filename (assembly_dir, dlls[i]->d_name,
@@ -292,8 +289,8 @@ execute_csharp_using_dotnet (const char *assembly_path,
                                      libdir_dll, absolute_target_dll);
                               free (libdir_dll);
                               free (target_dll);
-                              for (i = 0; i < num_dlls; i++)
-                                free (dlls[i]);
+                              for (int ii = 0; ii < num_dlls; ii++)
+                                free (dlls[ii]);
                               free (dlls);
                               free (assembly_dir);
                               while (tmpfiles_count > 0)
@@ -312,7 +309,7 @@ execute_csharp_using_dotnet (const char *assembly_path,
                   free (target_dll);
                 }
 
-              for (i = 0; i < num_dlls; i++)
+              for (int i = 0; i < num_dlls; i++)
                 free (dlls[i]);
               free (dlls);
             }
@@ -340,12 +337,11 @@ execute_csharp_using_dotnet (const char *assembly_path,
         {
           const char **argv =
             (const char **) xmalloca ((3 + nargs + 1) * sizeof (const char *));
-          unsigned int i;
 
           argv[0] = "dotnet";
           argv[1] = "exec";
           argv[2] = assembly_path_converted;
-          for (i = 0; i <= nargs; i++)
+          for (unsigned int i = 0; i <= nargs; i++)
             argv[3 + i] = args[i];
 
           if (verbose)
@@ -506,14 +502,13 @@ execute_csharp_using_dotnet (const char *assembly_path,
                           const char **argv =
                             (const char **)
                             xmalloca ((5 + nargs + 1) * sizeof (const char *));
-                          unsigned int i;
 
                           argv[0] = "dotnet";
                           argv[1] = "exec";
                           argv[2] = "--runtimeconfig";
                           argv[3] = runtimeconfig_converted;
                           argv[4] = assembly_path_converted;
-                          for (i = 0; i <= nargs; i++)
+                          for (unsigned int i = 0; i <= nargs; i++)
                             argv[5 + i] = args[i];
 
                           if (verbose)
@@ -587,7 +582,6 @@ execute_csharp_using_sscli (const char *assembly_path,
       char *old_clixpath;
       const char **argv =
         (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
-      unsigned int i;
       bool err;
 
       /* Set clix' PATH variable.  */
@@ -595,7 +589,7 @@ execute_csharp_using_sscli (const char *assembly_path,
 
       argv[0] = "clix";
       argv[1] = assembly_path_converted;
-      for (i = 0; i <= nargs; i++)
+      for (unsigned int i = 0; i <= nargs; i++)
         argv[2 + i] = args[i];
 
       if (verbose)
diff --git a/lib/cygpath.c b/lib/cygpath.c
index d8c984c330..5969018c43 100644
--- a/lib/cygpath.c
+++ b/lib/cygpath.c
@@ -47,12 +47,10 @@
 char *
 cygpath_w (const char *filename)
 {
-  int repeat;
-
   /* Try several times, since there is a small time window during which the
      size returned by the previous call may not be sufficient, namely when a
      directory gets renamed.  */
-  for (repeat = 3; repeat > 0; repeat--)
+  for (int repeat = 3; repeat > 0; repeat--)
     {
       ssize_t size = cygwin_conv_path (CCP_POSIX_TO_WIN_A | CCP_RELATIVE, filename, NULL, 0);
       if (size < 0)
diff --git a/lib/des.c b/lib/des.c
index 49d3821604..90d80628ca 100644
--- a/lib/des.c
+++ b/lib/des.c
@@ -320,10 +320,10 @@ bool
 gl_des_is_weak_key (const char * key)
 {
   char work[8];
-  int i, left, right, middle, cmp_result;
+  int left, right, middle, cmp_result;
 
   /* clear parity bits */
-  for (i = 0; i < 8; ++i)
+  for (int i = 0; i < 8; ++i)
     work[i] = ((unsigned char)key[i]) & 0xfe;
 
   /* binary search in the weak key table */
@@ -438,7 +438,6 @@ des_key_schedule (const char * _rawkey, uint32_t * subkey)
 {
   const unsigned char *rawkey = (const unsigned char *) _rawkey;
   uint32_t left, right, work;
-  int round;
 
   READ_64BIT_DATA (rawkey, left, right)
     DO_PERMUTATION (right, work, left, 4, 0x0f0f0f0f)
@@ -465,7 +464,7 @@ des_key_schedule (const char * _rawkey, uint32_t * subkey)
 
   right &= 0x0fffffff;
 
-  for (round = 0; round < 16; ++round)
+  for (int round = 0; round < 16; ++round)
     {
       left = ((left << encrypt_rotate_tab[round])
               | (left >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff;
@@ -523,11 +522,9 @@ des_key_schedule (const char * _rawkey, uint32_t * subkey)
 void
 gl_des_setkey (gl_des_ctx *ctx, const char * key)
 {
-  int i;
-
   des_key_schedule (key, ctx->encrypt_subkeys);
 
-  for (i = 0; i < 32; i += 2)
+  for (int i = 0; i < 32; i += 2)
     {
       ctx->decrypt_subkeys[i] = ctx->encrypt_subkeys[30 - i];
       ctx->decrypt_subkeys[i + 1] = ctx->encrypt_subkeys[31 - i];
@@ -572,12 +569,10 @@ gl_des_ecb_crypt (gl_des_ctx *ctx, const char * _from, char * _to, int mode)
 void
 gl_3des_set2keys (gl_3des_ctx *ctx, const char * key1, const char * key2)
 {
-  int i;
-
   des_key_schedule (key1, ctx->encrypt_subkeys);
   des_key_schedule (key2, &(ctx->decrypt_subkeys[32]));
 
-  for (i = 0; i < 32; i += 2)
+  for (int i = 0; i < 32; i += 2)
     {
       ctx->decrypt_subkeys[i] = ctx->encrypt_subkeys[30 - i];
       ctx->decrypt_subkeys[i + 1] = ctx->encrypt_subkeys[31 - i];
@@ -597,13 +592,11 @@ void
 gl_3des_set3keys (gl_3des_ctx *ctx, const char * key1,
                     const char * key2, const char * key3)
 {
-  int i;
-
   des_key_schedule (key1, ctx->encrypt_subkeys);
   des_key_schedule (key2, &(ctx->decrypt_subkeys[32]));
   des_key_schedule (key3, &(ctx->encrypt_subkeys[64]));
 
-  for (i = 0; i < 32; i += 2)
+  for (int i = 0; i < 32; i += 2)
     {
       ctx->decrypt_subkeys[i] = ctx->encrypt_subkeys[94 - i];
       ctx->decrypt_subkeys[i + 1] = ctx->encrypt_subkeys[95 - i];
diff --git a/lib/dfa.c b/lib/dfa.c
index 3720e6db94..34b7f8bf2d 100644
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -2254,15 +2254,15 @@ state_index (struct dfa *d, position_set const *s, int context)
 {
   size_t hash = 0;
   int constraint = 0;
-  state_num i;
 
-  for (i = 0; i < s->nelem; ++i)
+  for (state_num i = 0; i < s->nelem; ++i)
     {
       idx_t ind = s->elems[i].index;
       hash ^= ind + s->elems[i].constraint;
     }
 
   /* Try to find a state that exactly matches the proposed one.  */
+  state_num i;
   for (i = 0; i < d->sindex; ++i)
     {
       if (hash != d->states[i].hash || s->nelem != d->states[i].elems.nelem
@@ -3347,8 +3347,7 @@ transit_state (struct dfa *d, state_num s, unsigned char const **pp,
     {
       if (MAX_TRCOUNT <= d->mb_trcount)
         {
-          state_num s3;
-          for (s3 = -1; s3 < d->tralloc; s3++)
+          for (state_num s3 = -1; s3 < d->tralloc; s3++)
             {
               free (d->mb_trans[s3]);
               d->mb_trans[s3] = NULL;
@@ -3675,8 +3674,7 @@ free_mbdata (struct dfa *d)
 
   if (d->mb_trans)
     {
-      state_num s;
-      for (s = -1; s < d->tralloc; s++)
+      for (state_num s = -1; s < d->tralloc; s++)
         free (d->mb_trans[s]);
       free (d->mb_trans - 2);
     }
diff --git a/lib/di-set.c b/lib/di-set.c
index 429d173463..5ef5269edc 100644
--- a/lib/di-set.c
+++ b/lib/di-set.c
@@ -83,9 +83,8 @@ di_ent_hash (void const *x, size_t table_size)
      This avoids loss of info, without applying % to the wider type,
      which could be quite slow on some systems.  */
   size_t h = dev;
-  unsigned int i;
   unsigned int n_words = sizeof dev / sizeof h + (sizeof dev % sizeof h != 0);
-  for (i = 1; i < n_words; i++)
+  for (unsigned int i = 1; i < n_words; i++)
     h ^= dev >> CHAR_BIT * sizeof h * i;
 
   return h % table_size;
diff --git a/lib/diffseq.h b/lib/diffseq.h
index 914bc643bb..b2f24c82af 100644
--- a/lib/diffseq.h
+++ b/lib/diffseq.h
@@ -323,9 +323,7 @@ diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, bool find_minimal,
                       {
                         /* We have a good enough best diagonal; now insist
                            that it end with a significant snake.  */
-                        int k;
-
-                        for (k = 1; XREF_YREF_EQUAL (x - k, y - k); k++)
+                        for (int k = 1; XREF_YREF_EQUAL (x - k, y - k); k++)
                           if (k == SNAKE_LIMIT)
                             {
                               best = v;
@@ -362,9 +360,7 @@ diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, bool find_minimal,
                       {
                         /* We have a good enough best diagonal; now insist
                            that it end with a significant snake.  */
-                        int k;
-
-                        for (k = 0; XREF_YREF_EQUAL (x + k, y + k); k++)
+                        for (int k = 0; XREF_YREF_EQUAL (x + k, y + k); k++)
                           if (k == SNAKE_LIMIT - 1)
                             {
                               best = v;
diff --git a/lib/duplocale.c b/lib/duplocale.c
index 6be27459cd..ad93ae9834 100644
--- a/lib/duplocale.c
+++ b/lib/duplocale.c
@@ -71,7 +71,6 @@ duplocale (locale_t locale)
       char base_name[SETLOCALE_NULL_MAX];
       int err;
       locale_t base_copy;
-      unsigned int i;
 
       err = setlocale_null_r (LC_CTYPE, base_name, sizeof (base_name));
       if (err)
@@ -83,7 +82,7 @@ duplocale (locale_t locale)
       if (base_copy == NULL)
         return NULL;
 
-      for (i = 0; i < SIZEOF (categories); i++)
+      for (unsigned int i = 0; i < SIZEOF (categories); i++)
         {
           int category = categories[i].cat;
           int category_mask = categories[i].mask;
diff --git a/lib/execve.c b/lib/execve.c
index e1300e1ae4..5924c645c6 100644
--- a/lib/execve.c
+++ b/lib/execve.c
@@ -59,8 +59,7 @@ execve (const char *program, char * const *argv, char * const *env)
          can't do so since we have no way to enumerate them.  */
       {
         unsigned int fdmax = _getmaxstdio ();
-        unsigned int fd;
-        for (fd = 0; fd < fdmax; fd++)
+        for (unsigned int fd = 0; fd < fdmax; fd++)
           close (fd);
       }
 
diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c
index 3ca18634b8..fa6ee0807d 100644
--- a/lib/fatal-signal.c
+++ b/lib/fatal-signal.c
@@ -93,9 +93,7 @@ init_fatal_signals (void)
   static bool fatal_signals_initialized = false;
   if (!fatal_signals_initialized)
     {
-      size_t i;
-
-      for (i = 0; i < num_fatal_signals; i++)
+      for (size_t i = 0; i < num_fatal_signals; i++)
         {
           struct sigaction action;
 
@@ -139,9 +137,7 @@ static struct sigaction saved_sigactions[64];
 static _GL_ASYNC_SAFE void
 uninstall_handlers (void)
 {
-  size_t i;
-
-  for (i = 0; i < num_fatal_signals; i++)
+  for (size_t i = 0; i < num_fatal_signals; i++)
     if (fatal_signals[i] >= 0)
       {
         int sig = fatal_signals[i];
@@ -184,7 +180,6 @@ fatal_signal_handler (int sig)
 static void
 install_handlers (void)
 {
-  size_t i;
   struct sigaction action;
 
   action.sa_handler = &fatal_signal_handler;
@@ -193,7 +188,7 @@ install_handlers (void)
      SA_RESETHAND.  */
   action.sa_flags = SA_NODEFER;
   sigemptyset (&action.sa_mask);
-  for (i = 0; i < num_fatal_signals; i++)
+  for (size_t i = 0; i < num_fatal_signals; i++)
     if (fatal_signals[i] >= 0)
       {
         int sig = fatal_signals[i];
@@ -244,11 +239,10 @@ at_fatal_signal (action_t action)
           goto done;
         }
 
-      size_t k;
       /* Don't use memcpy() here, because memcpy takes non-volatile arguments
          and is therefore not guaranteed to complete all memory stores before
          the next statement.  */
-      for (k = 0; k < old_actions_allocated; k++)
+      for (size_t k = 0; k < old_actions_allocated; k++)
         new_actions[k] = old_actions[k];
       actions = new_actions;
       actions_allocated = new_actions_allocated;
@@ -285,12 +279,10 @@ static sigset_t fatal_signal_set;
 static void
 do_init_fatal_signal_set (void)
 {
-  size_t i;
-
   init_fatal_signals ();
 
   sigemptyset (&fatal_signal_set);
-  for (i = 0; i < num_fatal_signals; i++)
+  for (size_t i = 0; i < num_fatal_signals; i++)
     if (fatal_signals[i] >= 0)
       sigaddset (&fatal_signal_set, fatal_signals[i]);
 }
@@ -355,9 +347,8 @@ get_fatal_signals (int signals[64])
 
   {
     int *p = signals;
-    size_t i;
 
-    for (i = 0; i < num_fatal_signals; i++)
+    for (size_t i = 0; i < num_fatal_signals; i++)
       if (fatal_signals[i] >= 0)
         *p++ = fatal_signals[i];
     return p - signals;
diff --git a/lib/fcntl.c b/lib/fcntl.c
index f47ebde105..29cb4f9eb8 100644
--- a/lib/fcntl.c
+++ b/lib/fcntl.c
@@ -146,9 +146,8 @@ dupfd (int oldfd, int newfd, int flags)
   /* Close the previous fds that turned out to be too small.  */
   {
     int saved_errno = errno;
-    unsigned int duplicated_fd;
 
-    for (duplicated_fd = 0;
+    for (unsigned int duplicated_fd = 0;
          duplicated_fd < fds_to_close_bound * CHAR_BIT;
          duplicated_fd++)
       if ((fds_to_close[duplicated_fd / CHAR_BIT]
diff --git a/lib/ffs.c b/lib/ffs.c
index 2262062a12..aeb49d1c71 100644
--- a/lib/ffs.c
+++ b/lib/ffs.c
@@ -58,8 +58,7 @@ ffs (int i)
     }
   else
     {
-      unsigned int j;
-      for (j = 0; j < CHAR_BIT * sizeof i; j++)
+      for (unsigned int j = 0; j < CHAR_BIT * sizeof i; j++)
         if (i & (1U << j))
           return j + 1;
       return 0;
diff --git a/lib/ffsl.h b/lib/ffsl.h
index 9b2f72dd93..86f5850db2 100644
--- a/lib/ffsl.h
+++ b/lib/ffsl.h
@@ -71,8 +71,6 @@ FUNC (TYPE i)
 
   if (chunk_count > 1)
     {
-      size_t k;
-
       /* It is tempting to write  if (!j)  here, but if we do this,
          Solaris 10/x86 "cc -O" miscompiles the code.  */
       if (!i)
@@ -81,7 +79,7 @@ FUNC (TYPE i)
       if ((unsigned int) j)
         return ffs ((unsigned int) j);
       /* Generic loop.  */
-      for (k = 1; k < chunk_count - 1; k++)
+      for (size_t k = 1; k < chunk_count - 1; k++)
         if ((unsigned int) (j >> (k * chunk_bits)) != 0)
           return k * chunk_bits + ffs ((unsigned int) (j >> (k * chunk_bits)));
     }
diff --git a/lib/file-remote.c b/lib/file-remote.c
index 3a6d9263ec..33f69e2b65 100644
--- a/lib/file-remote.c
+++ b/lib/file-remote.c
@@ -268,27 +268,21 @@ file_is_remote (const char *file)
       return -1;
     }
   int result = 0;
-  {
-    struct mount_entry *me;
-    for (me = me_list; me != NULL; )
-      {
-        if (me->me_dev == device)
-          {
-            result = me->me_remote;
-            break;
-          }
-        me = me->me_next;
-      }
-  }
-  {
-    struct mount_entry *me;
-    for (me = me_list; me != NULL; )
-      {
-        struct mount_entry *next = me->me_next;
-        free_mount_entry (me);
-        me = next;
-      }
-  }
+  for (struct mount_entry *me = me_list; me != NULL; )
+    {
+      if (me->me_dev == device)
+        {
+          result = me->me_remote;
+          break;
+        }
+      me = me->me_next;
+    }
+  for (struct mount_entry *me = me_list; me != NULL; )
+    {
+      struct mount_entry *next = me->me_next;
+      free_mount_entry (me);
+      me = next;
+    }
   return result;
 # else
   /* Assume all file systems are local.  */
diff --git a/lib/findprog-in.c b/lib/findprog-in.c
index 6d6ade672d..cc86f1d16d 100644
--- a/lib/findprog-in.c
+++ b/lib/findprog-in.c
@@ -76,16 +76,12 @@ find_in_given_path (const char *progname, const char *path,
 {
   {
     bool has_slash = false;
-    {
-      const char *p;
-
-      for (p = progname; *p != '\0'; p++)
-        if (ISSLASH (*p))
-          {
-            has_slash = true;
-            break;
-          }
-    }
+    for (const char *p = progname; *p != '\0'; p++)
+      if (ISSLASH (*p))
+        {
+          has_slash = true;
+          break;
+        }
     if (has_slash)
       {
         /* If progname contains a slash, it is either absolute or relative to
@@ -99,7 +95,6 @@ find_in_given_path (const char *progname, const char *path,
             /* Try the various suffixes and see whether one of the files
                with such a suffix is actually executable.  */
             int failure_errno;
-            size_t i;
 
             const char *directory_as_prefix =
               (directory != NULL && IS_RELATIVE_FILE_NAME (progname)
@@ -109,21 +104,17 @@ find_in_given_path (const char *progname, const char *path,
             #if defined _WIN32 && !defined __CYGWIN__ /* Native Windows */
             const char *progbasename;
 
-            {
-              const char *p;
-
-              progbasename = progname;
-              for (p = progname; *p != '\0'; p++)
-                if (ISSLASH (*p))
-                  progbasename = p + 1;
-            }
+            progbasename = progname;
+            for (const char *p = progname; *p != '\0'; p++)
+              if (ISSLASH (*p))
+                progbasename = p + 1;
 
             bool progbasename_has_dot = (strchr (progbasename, '.') != NULL);
             #endif
 
             /* Try all platform-dependent suffixes.  */
             failure_errno = ENOENT;
-            for (i = 0; i < sizeof (suffixes) / sizeof (suffixes[0]); i++)
+            for (size_t i = 0; i < sizeof (suffixes) / sizeof (suffixes[0]); i++)
               {
                 const char *suffix = suffixes[i];
 
@@ -224,7 +215,6 @@ find_in_given_path (const char *progname, const char *path,
       return NULL; /* errno is set here */
 
     int failure_errno;
-    char *path_rest;
     char *cp;
 
     #if defined _WIN32 && !defined __CYGWIN__ /* Native Windows */
@@ -232,13 +222,12 @@ find_in_given_path (const char *progname, const char *path,
     #endif
 
     failure_errno = ENOENT;
-    for (path_rest = path_copy; ; path_rest = cp + 1)
+    for (char *path_rest = path_copy; ; path_rest = cp + 1)
       {
         const char *dir;
         bool last;
         char *dir_as_prefix_to_free;
         const char *dir_as_prefix;
-        size_t i;
 
         /* Extract next directory in PATH.  */
         dir = path_rest;
@@ -271,7 +260,7 @@ find_in_given_path (const char *progname, const char *path,
           }
 
         /* Try all platform-dependent suffixes.  */
-        for (i = 0; i < sizeof (suffixes) / sizeof (suffixes[0]); i++)
+        for (size_t i = 0; i < sizeof (suffixes) / sizeof (suffixes[0]); i++)
           {
             const char *suffix = suffixes[i];
 
diff --git a/lib/findprog.c b/lib/findprog.c
index bf67452d0a..e117ba3986 100644
--- a/lib/findprog.c
+++ b/lib/findprog.c
@@ -48,7 +48,6 @@ find_in_path (const char *progname)
 #else
   /* Unix */
   char *path;
-  char *path_rest;
   char *cp;
 
   if (strchr (progname, '/') != NULL)
@@ -71,7 +70,7 @@ find_in_path (const char *progname)
     /* Out of memory.  */
     return progname;
 # endif
-  for (path_rest = path; ; path_rest = cp + 1)
+  for (char *path_rest = path; ; path_rest = cp + 1)
     {
       const char *dir;
       bool last;
diff --git a/lib/fma.c b/lib/fma.c
index 63108d6fed..6175c448ad 100644
--- a/lib/fma.c
+++ b/lib/fma.c
@@ -280,8 +280,7 @@ decode (DOUBLE x, mp_limb_t limbs[NLIMBS1])
     {
       /* Here we still have MANT_BIT-4*31 bits to extract from x.  */
       /* Generic loop.  */
-      size_t k;
-      for (k = 4; k < chunk_count; k++)
+      for (size_t k = 4; k < chunk_count; k++)
         {
           size_t chunk_bits = MIN (31, MANT_BIT - k * 31); /* > 0, <= 31 */
           mp_limb_t d;
@@ -335,17 +334,16 @@ static void
 multiply (mp_limb_t xlimbs[NLIMBS1], mp_limb_t ylimbs[NLIMBS1],
           mp_limb_t prod_limbs[2 * NLIMBS1])
 {
-  size_t k, i, j;
   enum { len1 = NLIMBS1 };
   enum { len2 = NLIMBS1 };
 
-  for (k = len2; k > 0; )
+  for (size_t k = len2; k > 0; )
     prod_limbs[--k] = 0;
-  for (i = 0; i < len1; i++)
+  for (size_t i = 0; i < len1; i++)
     {
       mp_limb_t digit1 = xlimbs[i];
       mp_twolimb_t carry = 0;
-      for (j = 0; j < len2; j++)
+      for (size_t j = 0; j < len2; j++)
         {
           mp_limb_t digit2 = ylimbs[j];
           carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2;
@@ -472,8 +470,7 @@ FUNC (DOUBLE x, DOUBLE y, DOUBLE z)
                 if (e == xye - 2 * MANT_BIT)
                   {
                     /* Simply copy the limbs of xylimbs.  */
-                    size_t i;
-                    for (i = 0; i < 2 * NLIMBS1; i++)
+                    for (size_t i = 0; i < 2 * NLIMBS1; i++)
                       summand1[i] = xylimbs[i];
                     summand1_len = 2 * NLIMBS1;
                   }
@@ -483,13 +480,12 @@ FUNC (DOUBLE x, DOUBLE y, DOUBLE z)
                     /* Left shift the limbs of xylimbs by ediff bits.  */
                     size_t ldiff = ediff / GMP_LIMB_BITS;
                     size_t shift = ediff % GMP_LIMB_BITS;
-                    size_t i;
-                    for (i = 0; i < ldiff; i++)
+                    for (size_t i = 0; i < ldiff; i++)
                       summand1[i] = 0;
                     if (shift > 0)
                       {
                         mp_limb_t carry = 0;
-                        for (i = 0; i < 2 * NLIMBS1; i++)
+                        for (size_t i = 0; i < 2 * NLIMBS1; i++)
                           {
                             summand1[ldiff + i] = (xylimbs[i] << shift) | carry;
                             carry = xylimbs[i] >> (GMP_LIMB_BITS - shift);
@@ -499,7 +495,7 @@ FUNC (DOUBLE x, DOUBLE y, DOUBLE z)
                       }
                     else
                       {
-                        for (i = 0; i < 2 * NLIMBS1; i++)
+                        for (size_t i = 0; i < 2 * NLIMBS1; i++)
                           summand1[ldiff + i] = xylimbs[i];
                         summand1_len = ldiff + 2 * NLIMBS1;
                       }
@@ -517,8 +513,7 @@ FUNC (DOUBLE x, DOUBLE y, DOUBLE z)
                 if (e == ze - MANT_BIT)
                   {
                     /* Simply copy the limbs of zlimbs.  */
-                    size_t i;
-                    for (i = 0; i < NLIMBS1; i++)
+                    for (size_t i = 0; i < NLIMBS1; i++)
                       summand2[i] = zlimbs[i];
                     summand2_len = NLIMBS1;
                   }
@@ -528,13 +523,12 @@ FUNC (DOUBLE x, DOUBLE y, DOUBLE z)
                     /* Left shift the limbs of zlimbs by ediff bits.  */
                     size_t ldiff = ediff / GMP_LIMB_BITS;
                     size_t shift = ediff % GMP_LIMB_BITS;
-                    size_t i;
-                    for (i = 0; i < ldiff; i++)
+                    for (size_t i = 0; i < ldiff; i++)
                       summand2[i] = 0;
                     if (shift > 0)
                       {
                         mp_limb_t carry = 0;
-                        for (i = 0; i < NLIMBS1; i++)
+                        for (size_t i = 0; i < NLIMBS1; i++)
                           {
                             summand2[ldiff + i] = (zlimbs[i] << shift) | carry;
                             carry = zlimbs[i] >> (GMP_LIMB_BITS - shift);
@@ -544,7 +538,7 @@ FUNC (DOUBLE x, DOUBLE y, DOUBLE z)
                       }
                     else
                       {
-                        for (i = 0; i < NLIMBS1; i++)
+                        for (size_t i = 0; i < NLIMBS1; i++)
                           summand2[ldiff + i] = zlimbs[i];
                         summand2_len = ldiff + NLIMBS1;
                       }
@@ -755,15 +749,12 @@ FUNC (DOUBLE x, DOUBLE y, DOUBLE z)
                                 & (((mp_limb_t) 1 << ((roundoff_bits - 1) % GMP_LIMB_BITS)) - 1))
                                == 0);
                             if (halfway)
-                              {
-                                int i;
-                                for (i = (roundoff_bits - 1) / GMP_LIMB_BITS - 1; i >= 0; i--)
-                                  if (sum[i] != 0)
-                                    {
-                                      halfway = false;
-                                      break;
-                                    }
-                              }
+                              for (int i = (roundoff_bits - 1) / GMP_LIMB_BITS - 1; i >= 0; i--)
+                                if (sum[i] != 0)
+                                  {
+                                    halfway = false;
+                                    break;
+                                  }
                             if (halfway)
                               /* Round to even.  Test bit roundoff_bits.  */
                               round_up = ((sum[roundoff_bits / GMP_LIMB_BITS]
diff --git a/lib/freelocale.c b/lib/freelocale.c
index 9dd7cba02c..46fef6be4c 100644
--- a/lib/freelocale.c
+++ b/lib/freelocale.c
@@ -26,8 +26,7 @@
 void
 freelocale (locale_t locale)
 {
-  int i;
-  for (i = 6; --i >= 0; )
+  for (int i = 6; --i >= 0; )
     {
 #if HAVE_WINDOWS_LOCALE_T
       if (!(i == gl_log2_lcmask_to_index (gl_log2_lc_mask (LC_MESSAGES))
diff --git a/lib/fstrcmp.c b/lib/fstrcmp.c
index 7e446e290a..24c54e7069 100644
--- a/lib/fstrcmp.c
+++ b/lib/fstrcmp.c
@@ -104,7 +104,6 @@ fstrcmp_bounded (const char *string1, const char *string2, double lower_bound)
   size_t xvec_length = strlen (string1);
   size_t yvec_length = strlen (string2);
   size_t length_sum = xvec_length + yvec_length;
-  ptrdiff_t i;
 
   ptrdiff_t fdiag_len;
   ptrdiff_t *buffer;
@@ -172,14 +171,14 @@ fstrcmp_bounded (const char *string1, const char *string2, double lower_bound)
 
           /* Determine the occurrence counts in X.  */
           memset (occ_diff, 0, sizeof (occ_diff));
-          for (i = xvec_length - 1; i >= 0; i--)
+          for (ptrdiff_t i = xvec_length - 1; i >= 0; i--)
             occ_diff[(unsigned char) string1[i]]++;
           /* Subtract the occurrence counts in Y.  */
-          for (i = yvec_length - 1; i >= 0; i--)
+          for (ptrdiff_t i = yvec_length - 1; i >= 0; i--)
             occ_diff[(unsigned char) string2[i]]--;
           /* Sum up the absolute values.  */
           sum = 0;
-          for (i = 0; i <= UCHAR_MAX; i++)
+          for (ptrdiff_t i = 0; i <= UCHAR_MAX; i++)
             {
               ptrdiff_t d = occ_diff[i];
               sum += (d >= 0 ? d : -d);
@@ -202,7 +201,7 @@ fstrcmp_bounded (const char *string1, const char *string2, double lower_bound)
   /* Set TOO_EXPENSIVE to be approximate square root of input size,
      bounded below by 4096.  */
   ctxt.too_expensive = 1;
-  for (i = xvec_length + yvec_length; i != 0; i >>= 2)
+  for (ptrdiff_t i = xvec_length + yvec_length; i != 0; i >>= 2)
     ctxt.too_expensive <<= 1;
   if (ctxt.too_expensive < 4096)
     ctxt.too_expensive = 4096;
diff --git a/lib/ftoastr.c b/lib/ftoastr.c
index 2438ffe837..03252f83d3 100644
--- a/lib/ftoastr.c
+++ b/lib/ftoastr.c
@@ -124,7 +124,6 @@ FTOASTR (char *buf, size_t bufsize, int flags, int width, FLOAT x)
   PROMOTED_FLOAT promoted_x = x;
   char format[sizeof "%-+ 0*.*Lg"];
   FLOAT abs_x = x < 0 ? -x : x;
-  int prec;
 
   char *p = format;
   *p++ = '%';
@@ -142,7 +141,7 @@ FTOASTR (char *buf, size_t bufsize, int flags, int width, FLOAT x)
   *p++ = flags & FTOASTR_UPPER_E ? 'G' : 'g';
   *p = '\0';
 
-  for (prec = abs_x < FLOAT_MIN ? 1 : FLOAT_DIG; ; prec++)
+  for (int prec = abs_x < FLOAT_MIN ? 1 : FLOAT_DIG; ; prec++)
     {
       int n = snprintf (buf, bufsize, format, width, prec, promoted_x);
       if (n < 0
diff --git a/lib/fts.c b/lib/fts.c
index 6ddfb6f022..9e7c05b5d7 100644
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -1669,8 +1669,9 @@ getdevino (int fd)
 static void
 find_matching_ancestor (FTSENT const *e_curr, struct Active_dir const *ad)
 {
-  FTSENT const *ent;
-  for (ent = e_curr; ent->fts_level >= FTS_ROOTLEVEL; ent = ent->fts_parent)
+  for (FTSENT const *ent = e_curr;
+       ent->fts_level >= FTS_ROOTLEVEL;
+       ent = ent->fts_parent)
     {
       if (ad->ino == ent->fts_statp->st_ino
           && ad->dev == ent->fts_statp->st_dev)
@@ -1678,8 +1679,9 @@ find_matching_ancestor (FTSENT const *e_curr, struct Active_dir const *ad)
     }
   printf ("ERROR: tree dir, %s, not active\n", ad->fts_ent->fts_accpath);
   printf ("active dirs:\n");
-  for (ent = e_curr;
-       ent->fts_level >= FTS_ROOTLEVEL; ent = ent->fts_parent)
+  for (FTSENT const *ent = e_curr;
+       ent->fts_level >= FTS_ROOTLEVEL;
+       ent = ent->fts_parent)
     printf ("  %s(%"PRIuMAX"/%"PRIuMAX") to %s(%"PRIuMAX"/%"PRIuMAX")...\n",
             ad->fts_ent->fts_accpath,
             (uintmax_t) ad->dev,
@@ -1693,13 +1695,14 @@ void
 fts_cross_check (FTS const *sp)
 {
   FTSENT const *ent = sp->fts_cur;
-  FTSENT const *t;
   if ( ! ISSET (FTS_TIGHT_CYCLE_CHECK))
     return;
 
   Dprintf (("fts-cross-check cur=%s\n", ent->fts_path));
   /* Make sure every parent dir is in the tree.  */
-  for (t = ent->fts_parent; t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent)
+  for (FTSENT const *t = ent->fts_parent;
+       t->fts_level >= FTS_ROOTLEVEL;
+       t = t->fts_parent)
     {
       struct Active_dir ad;
       ad.ino = t->fts_statp->st_ino;
@@ -1713,14 +1716,12 @@ fts_cross_check (FTS const *sp)
   if (ent->fts_parent->fts_level >= FTS_ROOTLEVEL
       && (ent->fts_info == FTS_DP
           || ent->fts_info == FTS_D))
-    {
-      struct Active_dir *ad;
-      for (ad = hash_get_first (sp->fts_cycle.ht); ad != NULL;
-           ad = hash_get_next (sp->fts_cycle.ht, ad))
-        {
-          find_matching_ancestor (ent, ad);
-        }
-    }
+    for (struct Active_dir *ad = hash_get_first (sp->fts_cycle.ht);
+         ad != NULL;
+         ad = hash_get_next (sp->fts_cycle.ht, ad))
+      {
+        find_matching_ancestor (ent, ad);
+      }
 }
 
 static bool
diff --git a/lib/fwriteerror.c b/lib/fwriteerror.c
index f7d7dd97ca..c5c5e5c1a8 100644
--- a/lib/fwriteerror.c
+++ b/lib/fwriteerror.c
@@ -139,13 +139,12 @@ main ()
       8191, 8192, 8193
     };
   static char dummy[8193];
-  unsigned int i, j;
 
-  for (i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++)
+  for (unsigned int i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++)
     {
       size_t size = sizes[i];
 
-      for (j = 0; j < 2; j++)
+      for (unsigned int j = 0; j < 2; j++)
         {
           /* Run a test depending on i and j:
              Write size bytes and then calls fflush if j==1.  */
diff --git a/lib/gai_strerror.c b/lib/gai_strerror.c
index df9d7e6be8..a2aed96e0b 100644
--- a/lib/gai_strerror.c
+++ b/lib/gai_strerror.c
@@ -79,8 +79,7 @@ values[] =
 const char *
 gai_strerror (int code)
 {
-  size_t i;
-  for (i = 0; i < sizeof (values) / sizeof (values[0]); ++i)
+  for (size_t i = 0; i < sizeof (values) / sizeof (values[0]); ++i)
     if (values[i].code == code)
       return _(values[i].msg);
 
diff --git a/lib/gc-gnulib.c b/lib/gc-gnulib.c
index 9b53feb886..f91b439323 100644
--- a/lib/gc-gnulib.c
+++ b/lib/gc-gnulib.c
@@ -286,10 +286,9 @@ gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char *key)
     case GC_AES256:
       {
         rijndael_rc rc;
-        size_t i;
         char keyMaterial[RIJNDAEL_MAX_KEY_SIZE + 1];
 
-        for (i = 0; i < keylen; i++)
+        for (size_t i = 0; i < keylen; i++)
           sprintf (&keyMaterial[2 * i], "%02x", key[i] & 0xFFU);
 
         rc = rijndaelMakeKey (&ctx->aesEncKey, RIJNDAEL_DIR_ENCRYPT,
@@ -344,10 +343,9 @@ gc_cipher_setiv (gc_cipher_handle handle, size_t ivlen, const char *iv)
         case GC_CBC:
           {
             rijndael_rc rc;
-            size_t i;
             char ivMaterial[2 * RIJNDAEL_MAX_IV_SIZE + 1];
 
-            for (i = 0; i < ivlen; i++)
+            for (size_t i = 0; i < ivlen; i++)
               sprintf (&ivMaterial[2 * i], "%02x", iv[i] & 0xFFU);
 
             rc = rijndaelCipherInit (&ctx->aesContext, RIJNDAEL_MODE_CBC,
@@ -389,8 +387,7 @@ gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char *data)
           for (; len >= ARCTWO_BLOCK_SIZE; len -= ARCTWO_BLOCK_SIZE,
                data += ARCTWO_BLOCK_SIZE)
             {
-              size_t i;
-              for (i = 0; i < ARCTWO_BLOCK_SIZE; i++)
+              for (size_t i = 0; i < ARCTWO_BLOCK_SIZE; i++)
                 data[i] ^= ctx->arctwoIV[i];
               arctwo_encrypt (&ctx->arctwoContext, data, data,
                               ARCTWO_BLOCK_SIZE);
@@ -460,11 +457,10 @@ gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char *data)
                data += ARCTWO_BLOCK_SIZE)
             {
               char tmpIV[ARCTWO_BLOCK_SIZE];
-              size_t i;
               memcpy (tmpIV, data, ARCTWO_BLOCK_SIZE);
               arctwo_decrypt (&ctx->arctwoContext, data, data,
                               ARCTWO_BLOCK_SIZE);
-              for (i = 0; i < ARCTWO_BLOCK_SIZE; i++)
+              for (size_t i = 0; i < ARCTWO_BLOCK_SIZE; i++)
                 data[i] ^= ctx->arctwoIV[i];
               memcpy (ctx->arctwoIV, tmpIV, ARCTWO_BLOCK_SIZE);
             }
diff --git a/lib/gc-pbkdf2.c b/lib/gc-pbkdf2.c
index 0a43944bb3..33cd2181dd 100644
--- a/lib/gc-pbkdf2.c
+++ b/lib/gc-pbkdf2.c
@@ -35,11 +35,8 @@ gc_pbkdf2_prf (gc_prf_func prf, size_t hLen,
 {
   char U[GC_MAX_DIGEST_SIZE];
   char T[GC_MAX_DIGEST_SIZE];
-  unsigned int u;
   unsigned int l;
   unsigned int r;
-  unsigned int i;
-  unsigned int k;
   int rc;
   char *tmp;
   size_t tmplen = Slen + 4;
@@ -62,11 +59,11 @@ gc_pbkdf2_prf (gc_prf_func prf, size_t hLen,
 
   memcpy (tmp, S, Slen);
 
-  for (i = 1; i <= l; i++)
+  for (unsigned int i = 1; i <= l; i++)
     {
       memset (T, 0, hLen);
 
-      for (u = 1; u <= c; u++)
+      for (unsigned int u = 1; u <= c; u++)
         {
           if (u == 1)
             {
@@ -86,7 +83,7 @@ gc_pbkdf2_prf (gc_prf_func prf, size_t hLen,
               return rc;
             }
 
-          for (k = 0; k < hLen; k++)
+          for (unsigned int k = 0; k < hLen; k++)
             T[k] ^= U[k];
         }
 
diff --git a/lib/gen-uni-tables.c b/lib/gen-uni-tables.c
index 8a97ae81d9..67f9ec2016 100644
--- a/lib/gen-uni-tables.c
+++ b/lib/gen-uni-tables.c
@@ -189,7 +189,7 @@ getfield (FILE *stream, char *buffer, int delim)
 static void
 fill_attributes (const char *unicodedata_filename)
 {
-  unsigned int i, j;
+  unsigned int j;
   FILE *stream;
   char field0[FIELDLEN];
   char field1[FIELDLEN];
@@ -208,7 +208,7 @@ fill_attributes (const char *unicodedata_filename)
   char field14[FIELDLEN];
   int lineno = 0;
 
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     unicode_attributes[i].name = NULL;
 
   stream = fopen (unicodedata_filename, "r");
@@ -246,7 +246,7 @@ fill_attributes (const char *unicodedata_filename)
                    unicodedata_filename, lineno);
           exit (1);
         }
-      i = strtoul (field0, NULL, 16);
+      unsigned int i = strtoul (field0, NULL, 16);
       if (field1[0] == '<'
           && strlen (field1) >= 9
           && str_endswith (field1, ", First>"))
@@ -682,7 +682,6 @@ static void
 debug_output_predicate (const char *filename, bool (*predicate) (unsigned int))
 {
   FILE *stream;
-  unsigned int ch;
 
   stream = fopen (filename, "w");
   if (stream == NULL)
@@ -692,13 +691,13 @@ debug_output_predicate (const char *filename, bool (*predicate) (unsigned int))
     }
 
 #if 0 /* This yields huge text output.  */
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     if (predicate (ch))
       {
         fprintf (stream, "0x%04X\n", ch);
       }
 #else
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     if (predicate (ch))
       {
         unsigned int first = ch;
@@ -727,7 +726,6 @@ output_predicate_test (const char *filename, bool (*predicate) (unsigned int), c
 {
   FILE *stream;
   bool need_comma;
-  unsigned int ch;
 
   stream = fopen (filename, "w");
   if (stream == NULL)
@@ -746,7 +744,7 @@ output_predicate_test (const char *filename, bool (*predicate) (unsigned int), c
   fprintf (stream, "\n");
 
   need_comma = false;
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     if (predicate (ch))
       {
         unsigned int first = ch;
@@ -785,7 +783,6 @@ static void
 output_predicate (const char *filename, bool (*predicate) (unsigned int), const char *name, const char *comment, const char *version)
 {
   FILE *stream;
-  unsigned int ch, i;
   struct predicate_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
 
@@ -814,7 +811,7 @@ output_predicate (const char *filename, bool (*predicate) (unsigned int), const
   t.q = 7; /* or: 6 */
   predicate_table_init (&t);
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     if (predicate (ch))
       predicate_table_add (&t, ch);
 
@@ -831,7 +828,7 @@ output_predicate (const char *filename, bool (*predicate) (unsigned int), const
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     if (i != 1)
       fprintf (stream, "#define header_%d %d\n", i,
                ((uint32_t *) t.result)[i]);
@@ -850,7 +847,7 @@ output_predicate (const char *filename, bool (*predicate) (unsigned int), const
   fprintf (stream, "  {");
   if (t.level1_size > 1)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 1) == 0)
@@ -870,7 +867,7 @@ output_predicate (const char *filename, bool (*predicate) (unsigned int), const
   fprintf (stream, "  {");
   if (t.level2_size << t.q > 1)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 1) == 0)
@@ -890,7 +887,7 @@ output_predicate (const char *filename, bool (*predicate) (unsigned int), const
   fprintf (stream, "  {");
   if (t.level3_size << t.p > 4)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level3_size << t.p; i++)
+  for (unsigned int i = 0; i < t.level3_size << t.p; i++)
     {
       if (i > 0 && (i % 4) == 0)
         fprintf (stream, "\n   ");
@@ -1100,7 +1097,6 @@ static void
 output_category (const char *filename, const char *version)
 {
   FILE *stream;
-  unsigned int ch, i;
   struct category_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
   uint16_t *level3_packed;
@@ -1127,7 +1123,7 @@ output_category (const char *filename, const char *version)
   t.q = 9;
   category_table_init (&t);
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value;
       unsigned int log2_value;
@@ -1162,7 +1158,7 @@ output_category (const char *filename, const char *version)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream, "#define category_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream, "static const\n");
@@ -1178,7 +1174,7 @@ output_category (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level1_size > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -1198,7 +1194,7 @@ output_category (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -1222,7 +1218,7 @@ output_category (const char *filename, const char *version)
   level3_packed =
     (uint16_t *)
     calloc ((t.level3_size << t.p) * 5 / 16 + 1, sizeof (uint16_t));
-  for (i = 0; i < t.level3_size << t.p; i++)
+  for (unsigned int i = 0; i < t.level3_size << t.p; i++)
     {
       unsigned int j = (i * 5) / 16;
       unsigned int k = (i * 5) % 16;
@@ -1234,7 +1230,7 @@ output_category (const char *filename, const char *version)
   fprintf (stream, "  {");
   if ((t.level3_size << t.p) * 5 / 16 + 1 > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < (t.level3_size << t.p) * 5 / 16 + 1; i++)
+  for (unsigned int i = 0; i < (t.level3_size << t.p) * 5 / 16 + 1; i++)
     {
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
@@ -1274,7 +1270,6 @@ static void
 output_combclass (const char *filename, const char *version)
 {
   FILE *stream;
-  unsigned int ch, i;
   struct combclass_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
 
@@ -1300,7 +1295,7 @@ output_combclass (const char *filename, const char *version)
   t.q = 9;
   combclass_table_init (&t);
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     if (unicode_attributes[ch].name != NULL)
       {
         int value = atoi (unicode_attributes[ch].combining);
@@ -1321,7 +1316,7 @@ output_combclass (const char *filename, const char *version)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream, "#define combclass_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream, "static const\n");
@@ -1336,7 +1331,7 @@ output_combclass (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level1_size > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -1356,7 +1351,7 @@ output_combclass (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -1376,7 +1371,7 @@ output_combclass (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level3_size << t.p > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level3_size << t.p; i++)
+  for (unsigned int i = 0; i < t.level3_size << t.p; i++)
     {
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
@@ -1647,7 +1642,6 @@ static void
 output_bidi_category (const char *filename, const char *version)
 {
   FILE *stream;
-  unsigned int ch, i;
   struct bidi_category_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
   uint16_t *level3_packed;
@@ -1674,7 +1668,7 @@ output_bidi_category (const char *filename, const char *version)
   t.q = 9;
   bidi_category_table_init (&t);
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value = get_bidi_category (ch);
 
@@ -1696,7 +1690,7 @@ output_bidi_category (const char *filename, const char *version)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream, "#define bidi_category_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream, "static const\n");
@@ -1712,7 +1706,7 @@ output_bidi_category (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level1_size > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -1732,7 +1726,7 @@ output_bidi_category (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -1754,7 +1748,7 @@ output_bidi_category (const char *filename, const char *version)
   level3_packed =
     (uint16_t *)
     calloc ((t.level3_size << t.p) * 5 / 16 + 1, sizeof (uint16_t));
-  for (i = 0; i < t.level3_size << t.p; i++)
+  for (unsigned int i = 0; i < t.level3_size << t.p; i++)
     {
       unsigned int j = (i * 5) / 16;
       unsigned int k = (i * 5) % 16;
@@ -1766,7 +1760,7 @@ output_bidi_category (const char *filename, const char *version)
   fprintf (stream, "  {");
   if ((t.level3_size << t.p) * 5 / 16 + 1 > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < (t.level3_size << t.p) * 5 / 16 + 1; i++)
+  for (unsigned int i = 0; i < (t.level3_size << t.p) * 5 / 16 + 1; i++)
     {
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
@@ -1815,7 +1809,6 @@ output_decimal_digit_test (const char *filename, const char *version)
 {
   FILE *stream;
   bool need_comma;
-  unsigned int ch;
 
   stream = fopen (filename, "w");
   if (stream == NULL)
@@ -1836,7 +1829,7 @@ output_decimal_digit_test (const char *filename, const char *version)
   fprintf (stream, "\n");
 
   need_comma = false;
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value = get_decdigit_value (ch);
 
@@ -1865,7 +1858,6 @@ static void
 output_decimal_digit (const char *filename, const char *version)
 {
   FILE *stream;
-  unsigned int ch, i;
   struct decdigit_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
 
@@ -1891,7 +1883,7 @@ output_decimal_digit (const char *filename, const char *version)
   t.q = 9;
   decdigit_table_init (&t);
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value = 1 + get_decdigit_value (ch);
 
@@ -1913,7 +1905,7 @@ output_decimal_digit (const char *filename, const char *version)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream, "#define decdigit_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream, "static const\n");
@@ -1929,7 +1921,7 @@ output_decimal_digit (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level1_size > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -1949,7 +1941,7 @@ output_decimal_digit (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -1970,7 +1962,7 @@ output_decimal_digit (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level3_size << (t.p - 1) > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level3_size << (t.p - 1); i++)
+  for (unsigned int i = 0; i < t.level3_size << (t.p - 1); i++)
     {
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
@@ -2012,7 +2004,6 @@ output_digit_test (const char *filename, const char *version)
 {
   FILE *stream;
   bool need_comma;
-  unsigned int ch;
 
   stream = fopen (filename, "w");
   if (stream == NULL)
@@ -2033,7 +2024,7 @@ output_digit_test (const char *filename, const char *version)
   fprintf (stream, "\n");
 
   need_comma = false;
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value = get_digit_value (ch);
 
@@ -2062,7 +2053,6 @@ static void
 output_digit (const char *filename, const char *version)
 {
   FILE *stream;
-  unsigned int ch, i;
   struct decdigit_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
 
@@ -2088,7 +2078,7 @@ output_digit (const char *filename, const char *version)
   t.q = 9;
   decdigit_table_init (&t);
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value = 1 + get_digit_value (ch);
 
@@ -2110,7 +2100,7 @@ output_digit (const char *filename, const char *version)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream, "#define digit_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream, "static const\n");
@@ -2126,7 +2116,7 @@ output_digit (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level1_size > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -2146,7 +2136,7 @@ output_digit (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -2167,7 +2157,7 @@ output_digit (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level3_size << (t.p - 1) > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level3_size << (t.p - 1); i++)
+  for (unsigned int i = 0; i < t.level3_size << (t.p - 1); i++)
     {
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
@@ -2226,7 +2216,6 @@ output_numeric_test (const char *filename, const char *version)
 {
   FILE *stream;
   bool need_comma;
-  unsigned int ch;
 
   stream = fopen (filename, "w");
   if (stream == NULL)
@@ -2247,7 +2236,7 @@ output_numeric_test (const char *filename, const char *version)
   fprintf (stream, "\n");
 
   need_comma = false;
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       uc_fraction_t value = get_numeric_value (ch);
 
@@ -2285,7 +2274,6 @@ output_numeric (const char *filename, const char *version)
   FILE *stream;
   uc_fraction_t fractions[160];
   unsigned int nfractions;
-  unsigned int ch, i, j;
   struct numeric_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
   uint16_t *level3_packed;
@@ -2310,10 +2298,11 @@ output_numeric (const char *filename, const char *version)
 
   /* Create table of occurring fractions.  */
   nfractions = 0;
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       uc_fraction_t value = get_numeric_value (ch);
 
+      unsigned int i;
       for (i = 0; i < nfractions; i++)
         if (value.numerator == fractions[i].numerator
             && value.denominator == fractions[i].denominator)
@@ -2326,7 +2315,7 @@ output_numeric (const char *filename, const char *version)
                 || (value.denominator == fractions[i].denominator
                     && value.numerator < fractions[i].numerator))
               break;
-          for (j = nfractions; j > i; j--)
+          for (unsigned int j = nfractions; j > i; j--)
             fractions[j] = fractions[j - 1];
           fractions[i] = value;
           nfractions++;
@@ -2336,7 +2325,7 @@ output_numeric (const char *filename, const char *version)
   fprintf (stream, "static const uc_fraction_t u_numeric_values[%d] =\n",
            nfractions);
   fprintf (stream, "{\n");
-  for (i = 0; i < nfractions; i++)
+  for (unsigned int i = 0; i < nfractions; i++)
     {
       fprintf (stream, "  { %d, %d }", fractions[i].numerator,
                fractions[i].denominator);
@@ -2350,10 +2339,11 @@ output_numeric (const char *filename, const char *version)
   t.q = 9;
   numeric_table_init (&t);
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       uc_fraction_t value = get_numeric_value (ch);
 
+      unsigned int i;
       for (i = 0; i < nfractions; i++)
         if (value.numerator == fractions[i].numerator
             && value.denominator == fractions[i].denominator)
@@ -2376,7 +2366,7 @@ output_numeric (const char *filename, const char *version)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream, "#define numeric_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream, "static const\n");
@@ -2392,7 +2382,7 @@ output_numeric (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level1_size > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -2412,7 +2402,7 @@ output_numeric (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -2434,7 +2424,7 @@ output_numeric (const char *filename, const char *version)
   level3_packed =
     (uint16_t *)
     calloc ((t.level3_size << t.p) * 8 / 16 + 1, sizeof (uint16_t));
-  for (i = 0; i < t.level3_size << t.p; i++)
+  for (unsigned int i = 0; i < t.level3_size << t.p; i++)
     {
       unsigned int j = (i * 8) / 16;
       unsigned int k = (i * 8) % 16;
@@ -2446,7 +2436,7 @@ output_numeric (const char *filename, const char *version)
   fprintf (stream, "  {");
   if ((t.level3_size << t.p) * 8 / 16 + 1 > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < (t.level3_size << t.p) * 8 / 16 + 1; i++)
+  for (unsigned int i = 0; i < (t.level3_size << t.p) * 8 / 16 + 1; i++)
     {
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
@@ -2506,7 +2496,6 @@ fill_mirror (const char *bidimirroring_filename)
       int c;
       unsigned int uc1;
       unsigned int uc2;
-      unsigned int i;
 
       lineno++;
       c = getc (stream);
@@ -2559,7 +2548,7 @@ fill_mirror (const char *bidimirroring_filename)
           exit (1);
         }
       /* Have we seen uc1 or uc2 already?  */
-      for (i = 0; i < mirror_pairs_count; i++)
+      for (unsigned int i = 0; i < mirror_pairs_count; i++)
         {
           if (uc1 == mirror_pairs[i].uc[0])
             {
@@ -2574,43 +2563,46 @@ fill_mirror (const char *bidimirroring_filename)
               exit (1);
             }
         }
-      for (i = 0; i < mirror_pairs_count; i++)
-        if (uc1 == mirror_pairs[i].uc[1] || uc2 == mirror_pairs[i].uc[0])
-          break;
-      if (i < mirror_pairs_count)
-        {
-          if (uc1 != mirror_pairs[i].uc[1])
-            {
-              /* uc1 != mirror_pairs[i].uc[1], uc2 == mirror_pairs[i].uc[0] */
-              fprintf (stderr, "%s: mapping conflict for 0x%04X\n",
-                       bidimirroring_filename, uc2);
-              exit (1);
-            }
-          if (uc2 != mirror_pairs[i].uc[0])
-            {
-              /* uc1 == mirror_pairs[i].uc[1], uc2 != mirror_pairs[i].uc[0] */
-              fprintf (stderr, "%s: mapping conflict for 0x%04X\n",
-                       bidimirroring_filename, uc1);
-              exit (1);
-            }
-          /* uc1 == mirror_pairs[i].uc[1], uc2 == mirror_pairs[i].uc[0].
-             (uc1, uc2) is the reverse pair of a pair that we already had
-             encountered: (uc2, uc1).  */
-        }
-      else
-        {
-          /* A new pair.  */
-          if (mirror_pairs_count == SIZEOF (mirror_pairs))
-            {
-              fprintf (stderr, "%s contains more pairs than expected, "
-                       "increase mirror_pairs' size.\n",
-                       bidimirroring_filename);
-              exit (1);
-            }
-          mirror_pairs[mirror_pairs_count].uc[0] = uc1;
-          mirror_pairs[mirror_pairs_count].uc[1] = uc2;
-          mirror_pairs_count++;
-        }
+      {
+        unsigned int i;
+        for (i = 0; i < mirror_pairs_count; i++)
+          if (uc1 == mirror_pairs[i].uc[1] || uc2 == mirror_pairs[i].uc[0])
+            break;
+        if (i < mirror_pairs_count)
+          {
+            if (uc1 != mirror_pairs[i].uc[1])
+              {
+                /* uc1 != mirror_pairs[i].uc[1], uc2 == mirror_pairs[i].uc[0] */
+                fprintf (stderr, "%s: mapping conflict for 0x%04X\n",
+                         bidimirroring_filename, uc2);
+                exit (1);
+              }
+            if (uc2 != mirror_pairs[i].uc[0])
+              {
+                /* uc1 == mirror_pairs[i].uc[1], uc2 != mirror_pairs[i].uc[0] */
+                fprintf (stderr, "%s: mapping conflict for 0x%04X\n",
+                         bidimirroring_filename, uc1);
+                exit (1);
+              }
+            /* uc1 == mirror_pairs[i].uc[1], uc2 == mirror_pairs[i].uc[0].
+               (uc1, uc2) is the reverse pair of a pair that we already had
+               encountered: (uc2, uc1).  */
+          }
+        else
+          {
+            /* A new pair.  */
+            if (mirror_pairs_count == SIZEOF (mirror_pairs))
+              {
+                fprintf (stderr, "%s contains more pairs than expected, "
+                         "increase mirror_pairs' size.\n",
+                         bidimirroring_filename);
+                exit (1);
+              }
+            mirror_pairs[mirror_pairs_count].uc[0] = uc1;
+            mirror_pairs[mirror_pairs_count].uc[1] = uc2;
+            mirror_pairs_count++;
+          }
+      }
       /* Verify that uc1 and uc2 have the BidiMirrored property.  */
       if (!(unicode_attributes[uc1].name != NULL
             && unicode_attributes[uc1].mirrored))
@@ -2640,12 +2632,11 @@ get_mirror_value (unsigned int ch)
 {
   bool mirrored;
   unsigned int mirror_char;
-  unsigned int i;
 
   mirrored = (unicode_attributes[ch].name != NULL
               && unicode_attributes[ch].mirrored);
   mirror_char = 0xfffd;
-  for (i = 0; i < mirror_pairs_count; i++)
+  for (unsigned int i = 0; i < mirror_pairs_count; i++)
     if (ch == mirror_pairs[i].uc[0])
       {
         mirror_char = mirror_pairs[i].uc[1];
@@ -2678,7 +2669,6 @@ static void
 output_mirror (const char *filename, const char *version)
 {
   FILE *stream;
-  unsigned int ch, i;
   struct mirror_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
 
@@ -2704,7 +2694,7 @@ output_mirror (const char *filename, const char *version)
   t.q = 9;
   mirror_table_init (&t);
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value = get_mirror_value (ch);
 
@@ -2724,7 +2714,7 @@ output_mirror (const char *filename, const char *version)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream, "#define mirror_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream, "static const\n");
@@ -2739,7 +2729,7 @@ output_mirror (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level1_size > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -2759,7 +2749,7 @@ output_mirror (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -2779,7 +2769,7 @@ output_mirror (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level3_size << t.p > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level3_size << t.p; i++)
+  for (unsigned int i = 0; i < t.level3_size << t.p; i++)
     {
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
@@ -2906,9 +2896,7 @@ static uint8_t unicode_indic_conjunct_break[0x110000];
 static void
 clear_properties (void)
 {
-  unsigned int i;
-
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     unicode_properties[i] = 0;
 }
 
@@ -2917,7 +2905,6 @@ clear_properties (void)
 static void
 fill_properties (const char *proplist_filename)
 {
-  unsigned int i;
   FILE *stream;
 
   stream = fopen (proplist_filename, "r");
@@ -3048,7 +3035,7 @@ fill_properties (const char *proplist_filename)
             }
 
           assert (i1 <= i2 && i2 < 0x110000);
-          for (i = i1; i <= i2; i++)
+          for (unsigned int i = i1; i <= i2; i++)
             unicode_indic_conjunct_break[i] = valuecode;
 
           goto done_line;
@@ -3061,7 +3048,7 @@ fill_properties (const char *proplist_filename)
         }
 
       assert (i1 <= i2 && i2 < 0x110000);
-      for (i = i1; i <= i2; i++)
+      for (unsigned int i = i1; i <= i2; i++)
         unicode_properties[i] |= 1ULL << propcode;
 
      done_line: ;
@@ -3079,11 +3066,10 @@ fill_properties (const char *proplist_filename)
 static void
 fill_property30 (char array[0x110000], const char *proplist_filename, const char *property_name)
 {
-  unsigned int i;
   FILE *stream;
   char buf[100+1];
 
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     array[i] = 0;
 
   stream = fopen (proplist_filename, "r");
@@ -3138,7 +3124,7 @@ fill_property30 (char array[0x110000], const char *proplist_filename, const char
           exit (1);
         }
       assert (i1 <= i2 && i2 < 0x110000);
-      for (i = i1; i <= i2; i++)
+      for (unsigned int i = i1; i <= i2; i++)
         array[i] = 1;
     }
 
@@ -4138,7 +4124,6 @@ output_indic_conjunct_break_test (const char *filename, const char *version)
 {
   FILE *stream;
   bool need_comma;
-  unsigned int ch;
 
   stream = fopen (filename, "w");
   if (stream == NULL)
@@ -4159,7 +4144,7 @@ output_indic_conjunct_break_test (const char *filename, const char *version)
   fprintf (stream, "\n");
 
   need_comma = false;
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value = unicode_indic_conjunct_break[ch];
 
@@ -4193,7 +4178,6 @@ static void
 output_indic_conjunct_break (const char *filename, const char *version)
 {
   FILE *stream;
-  unsigned int ch, i;
   struct indic_conjunct_break_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
 
@@ -4219,7 +4203,7 @@ output_indic_conjunct_break (const char *filename, const char *version)
   t.q = 4; /* or 5 */
   indic_conjunct_break_table_init (&t);
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       uint8_t value = unicode_indic_conjunct_break[ch];
 
@@ -4242,7 +4226,7 @@ output_indic_conjunct_break (const char *filename, const char *version)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream, "#define indic_conjunct_break_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream, "static const\n");
@@ -4258,7 +4242,7 @@ output_indic_conjunct_break (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level1_size > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -4278,7 +4262,7 @@ output_indic_conjunct_break (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -4299,7 +4283,7 @@ output_indic_conjunct_break (const char *filename, const char *version)
   fprintf (stream, "  {");
   if ((t.level3_size << t.p) * 2 / 16 > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < (t.level3_size << t.p) * 2 / 16; i++)
+  for (unsigned int i = 0; i < (t.level3_size << t.p) * 2 / 16; i++)
     {
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
@@ -4459,7 +4443,6 @@ static void
 fill_arabicshaping (const char *arabicshaping_filename)
 {
   FILE *stream;
-  unsigned int i;
   int lineno;
 
   stream = fopen (arabicshaping_filename, "r");
@@ -4469,7 +4452,7 @@ fill_arabicshaping (const char *arabicshaping_filename)
       exit (1);
     }
 
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     {
       unicode_joining_type[i] = (uint8_t)~(uint8_t)0;
       unicode_joining_group[i] = UC_JOINING_GROUP_NONE;
@@ -4495,6 +4478,7 @@ fill_arabicshaping (const char *arabicshaping_filename)
       if (buf[0] == '\0' || buf[0] == '#')
         continue;
 
+      unsigned int i;
       if (sscanf (buf, "%X%[; ]%[^;]%[; ]%[^;]%[; ]%100[^\n]",
                   &i, separator1, schematic_name, separator2, joining_type_name,
                   separator3, joining_group_name) != 7)
@@ -4673,7 +4657,6 @@ output_joining_type_test (const char *filename, const char *version)
 {
   FILE *stream;
   bool need_comma;
-  unsigned int ch;
 
   stream = fopen (filename, "w");
   if (stream == NULL)
@@ -4694,7 +4677,7 @@ output_joining_type_test (const char *filename, const char *version)
   fprintf (stream, "\n");
 
   need_comma = false;
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value = unicode_joining_type[ch];
 
@@ -4728,7 +4711,6 @@ static void
 output_joining_type (const char *filename, const char *version)
 {
   FILE *stream;
-  unsigned int ch, i;
   struct joining_type_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
   uint8_t *level3_packed;
@@ -4755,7 +4737,7 @@ output_joining_type (const char *filename, const char *version)
   t.q = 9;
   joining_type_table_init (&t);
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       uint8_t value = unicode_joining_type[ch];
 
@@ -4777,7 +4759,7 @@ output_joining_type (const char *filename, const char *version)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream, "#define joining_type_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream, "static const\n");
@@ -4793,7 +4775,7 @@ output_joining_type (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level1_size > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -4813,7 +4795,7 @@ output_joining_type (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -4833,7 +4815,7 @@ output_joining_type (const char *filename, const char *version)
   /* Pack the level3 array.  Each entry needs 4 bits only.  */
   level3_packed =
     (uint8_t *) calloc ((t.level3_size << t.p) * 4 / 8, sizeof (uint8_t));
-  for (i = 0; i < t.level3_size << t.p; i++)
+  for (unsigned int i = 0; i < t.level3_size << t.p; i++)
     {
       unsigned int j = (i * 4) / 8;
       unsigned int k = (i * 4) % 8;
@@ -4843,7 +4825,7 @@ output_joining_type (const char *filename, const char *version)
   fprintf (stream, "  {");
   if ((t.level3_size << t.p) * 4 / 8 > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < (t.level3_size << t.p) * 4 / 8; i++)
+  for (unsigned int i = 0; i < (t.level3_size << t.p) * 4 / 8; i++)
     {
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
@@ -4984,7 +4966,6 @@ output_joining_group_test (const char *filename, const char *version)
 {
   FILE *stream;
   bool need_comma;
-  unsigned int ch;
 
   stream = fopen (filename, "w");
   if (stream == NULL)
@@ -5005,7 +4986,7 @@ output_joining_group_test (const char *filename, const char *version)
   fprintf (stream, "\n");
 
   need_comma = false;
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value = unicode_joining_group[ch];
 
@@ -5039,7 +5020,6 @@ static void
 output_joining_group (const char *filename, const char *version)
 {
   FILE *stream;
-  unsigned int ch, i;
   struct joining_group_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
   uint16_t *level3_packed;
@@ -5066,7 +5046,7 @@ output_joining_group (const char *filename, const char *version)
   t.q = 9;
   joining_group_table_init (&t);
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       uint8_t value = unicode_joining_group[ch];
 
@@ -5088,7 +5068,7 @@ output_joining_group (const char *filename, const char *version)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream, "#define joining_group_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream, "static const\n");
@@ -5104,7 +5084,7 @@ output_joining_group (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level1_size > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -5124,7 +5104,7 @@ output_joining_group (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -5146,7 +5126,7 @@ output_joining_group (const char *filename, const char *version)
   level3_packed =
     (uint16_t *)
     calloc ((t.level3_size << t.p) * 7 / 16 + 1, sizeof (uint16_t));
-  for (i = 0; i < t.level3_size << t.p; i++)
+  for (unsigned int i = 0; i < t.level3_size << t.p; i++)
     {
       unsigned int j = (i * 7) / 16;
       unsigned int k = (i * 7) % 16;
@@ -5158,7 +5138,7 @@ output_joining_group (const char *filename, const char *version)
   fprintf (stream, "  {");
   if ((t.level3_size << t.p) * 7 / 16 + 1 > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < (t.level3_size << t.p) * 7 / 16 + 1; i++)
+  for (unsigned int i = 0; i < (t.level3_size << t.p) * 7 / 16 + 1; i++)
     {
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
@@ -5192,7 +5172,6 @@ static void
 fill_scripts (const char *scripts_filename)
 {
   FILE *stream;
-  unsigned int i;
 
   stream = fopen (scripts_filename, "r");
   if (stream == NULL)
@@ -5203,7 +5182,7 @@ fill_scripts (const char *scripts_filename)
 
   numscripts = 0;
 
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     unicode_scripts[i] = (uint8_t)~(uint8_t)0;
 
   for (;;)
@@ -5243,7 +5222,7 @@ fill_scripts (const char *scripts_filename)
           assert (numscripts != 256);
         }
 
-      for (i = i1; i <= i2; i++)
+      for (unsigned int i = i1; i <= i2; i++)
         {
           if (unicode_scripts[i] != (uint8_t)~(uint8_t)0)
             fprintf (stderr, "0x%04X belongs to multiple scripts\n", i);
@@ -5271,7 +5250,6 @@ output_scripts (const char *version)
 {
   const char *filename = "unictype/scripts.h";
   FILE *stream;
-  unsigned int ch, s, i;
   struct script_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
 
@@ -5300,25 +5278,24 @@ output_scripts (const char *version)
   output_library_license (stream, true);
   fprintf (stream, "\n");
 
-  for (s = 0; s < numscripts; s++)
+  for (unsigned int s = 0; s < numscripts; s++)
     {
       char *lcp = strdup (scripts[s]);
-      char *cp;
 
-      for (cp = lcp; *cp != '\0'; cp++)
+      for (char *cp = lcp; *cp != '\0'; cp++)
         if (*cp >= 'A' && *cp <= 'Z')
           *cp += 'a' - 'A';
 
       scriptinfo[s].lowercase_name = lcp;
     }
 
-  for (s = 0; s < numscripts; s++)
+  for (unsigned int s = 0; s < numscripts; s++)
     {
       fprintf (stream, "static const uc_interval_t script_%s_intervals[] =\n",
                scriptinfo[s].lowercase_name);
       fprintf (stream, "{\n");
-      i = 0;
-      for (ch = 0; ch < 0x110000; ch++)
+      unsigned int i = 0;
+      for (unsigned int ch = 0; ch < 0x110000; ch++)
         if (unicode_scripts[ch] == s)
           {
             unsigned int start;
@@ -5344,7 +5321,7 @@ output_scripts (const char *version)
 
   fprintf (stream, "static const uc_script_t scripts[%d] =\n", numscripts);
   fprintf (stream, "{\n");
-  for (s = 0; s < numscripts; s++)
+  for (unsigned int s = 0; s < numscripts; s++)
     {
       fprintf (stream, "  {\n");
       fprintf (stream, "    sizeof (script_%s_intervals) / sizeof (uc_interval_t),\n",
@@ -5363,7 +5340,7 @@ output_scripts (const char *version)
   t.q = 9;
   script_table_init (&t);
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       unsigned int s = unicode_scripts[ch];
       if (s != (uint8_t)~(uint8_t)0)
@@ -5383,7 +5360,7 @@ output_scripts (const char *version)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream, "#define script_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream, "static const\n");
@@ -5398,7 +5375,7 @@ output_scripts (const char *version)
   fprintf (stream, "  {");
   if (t.level1_size > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -5418,7 +5395,7 @@ output_scripts (const char *version)
   fprintf (stream, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -5440,7 +5417,7 @@ output_scripts (const char *version)
   fprintf (stream, "  {");
   if (t.level3_size << t.p > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level3_size << t.p; i++)
+  for (unsigned int i = 0; i < t.level3_size << t.p; i++)
     {
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
@@ -5465,7 +5442,6 @@ output_scripts_byname (const char *version)
 {
   const char *filename = "unictype/scripts_byname.gperf";
   FILE *stream;
-  unsigned int s;
 
   stream = fopen (filename, "w");
   if (stream == NULL)
@@ -5496,7 +5472,7 @@ output_scripts_byname (const char *version)
   fprintf (stream, "%%pic\n");
   fprintf (stream, "%%define string-pool-name script_stringpool\n");
   fprintf (stream, "%%%%\n");
-  for (s = 0; s < numscripts; s++)
+  for (unsigned int s = 0; s < numscripts; s++)
     fprintf (stream, "%s, %u\n", scripts[s], s);
 
   if (ferror (stream) || fclose (stream))
@@ -5611,8 +5587,6 @@ output_blocks (const char *version)
   const unsigned int shift = 8; /* bits to shift away for array access */
   const unsigned int threshold = 0x28000; /* cut-off table here to save space */
   FILE *stream;
-  unsigned int i;
-  unsigned int i1;
 
   stream = fopen (filename, "w");
   if (stream == NULL)
@@ -5634,7 +5608,7 @@ output_blocks (const char *version)
 
   fprintf (stream, "static const uc_block_t blocks[] =\n");
   fprintf (stream, "{\n");
-  for (i = 0; i < numblocks; i++)
+  for (unsigned int i = 0; i < numblocks; i++)
     {
       fprintf (stream, "  { 0x%04X, 0x%04X, \"%s\" }", blocks[i].start,
                blocks[i].end, blocks[i].name);
@@ -5648,7 +5622,7 @@ output_blocks (const char *version)
   fprintf (stream, "static const uint16_t blocks_level1[%d * 2] =\n",
            threshold >> shift);
   fprintf (stream, "{\n");
-  for (i1 = 0; i1 < (threshold >> shift); i1++)
+  for (unsigned int i1 = 0; i1 < (threshold >> shift); i1++)
     {
       unsigned int first_index = block_first_index (i1 << shift);
       unsigned int last_index = block_last_index (((i1 + 1) << shift) - 1);
@@ -6033,7 +6007,6 @@ static void
 output_ident_category (const char *filename, int (*predicate) (unsigned int), const char *name, const char *version)
 {
   FILE *stream;
-  unsigned int ch, i;
   struct identsyntax_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
 
@@ -6059,7 +6032,7 @@ output_ident_category (const char *filename, int (*predicate) (unsigned int), co
   t.q = 5; /* or 4 */
   identsyntax_table_init (&t);
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int syntaxcode = predicate (ch);
 
@@ -6082,7 +6055,7 @@ output_ident_category (const char *filename, int (*predicate) (unsigned int), co
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream, "#define identsyntax_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream, "static const\n");
@@ -6098,7 +6071,7 @@ output_ident_category (const char *filename, int (*predicate) (unsigned int), co
   fprintf (stream, "  {");
   if (t.level1_size > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -6118,7 +6091,7 @@ output_ident_category (const char *filename, int (*predicate) (unsigned int), co
   fprintf (stream, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -6139,7 +6112,7 @@ output_ident_category (const char *filename, int (*predicate) (unsigned int), co
   fprintf (stream, "  {");
   if ((t.level3_size << t.p) * 2 / 16 > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < (t.level3_size << t.p) * 2 / 16; i++)
+  for (unsigned int i = 0; i < (t.level3_size << t.p) * 2 / 16; i++)
     {
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
@@ -6470,18 +6443,17 @@ output_charclass (FILE *stream, const char *classname,
                   bool (*func) (unsigned int))
 {
   char table[0x110000];
-  unsigned int i;
   bool need_semicolon;
   const int max_column = 75;
   int column;
 
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     table[i] = (int) func (i);
 
   fprintf (stream, "%s ", classname);
   need_semicolon = false;
   column = 1000;
-  for (i = 0; i < 0x110000; )
+  for (unsigned int i = 0; i < 0x110000; )
     {
       if (!table[i])
         i++;
@@ -6528,18 +6500,17 @@ output_charmap (FILE *stream, const char *mapname,
                 unsigned int (*func) (unsigned int))
 {
   char table[0x110000];
-  unsigned int i;
   bool need_semicolon;
   const int max_column = 75;
   int column;
 
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     table[i] = (func (i) != i);
 
   fprintf (stream, "%s ", mapname);
   need_semicolon = false;
   column = 1000;
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     if (table[i])
       {
         char buf[25+1];
@@ -6582,7 +6553,6 @@ static void
 output_tables (const char *filename, const char *version)
 {
   FILE *stream;
-  unsigned int ch;
 
   stream = fopen (filename, "w");
   if (stream == NULL)
@@ -6621,7 +6591,7 @@ output_tables (const char *filename, const char *version)
   fprintf (stream, "\n");
 
   /* Verification. */
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       /* toupper restriction: "Only characters specified for the keywords
          lower and upper shall be specified.  */
@@ -6746,14 +6716,13 @@ const char * unicode_width[0x110000];
 static void
 fill_width (const char *width_filename)
 {
-  unsigned int i, j;
   FILE *stream;
   char field0[FIELDLEN];
   char field1[FIELDLEN];
   char field2[FIELDLEN];
   int lineno = 0;
 
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     unicode_width[i] = (unicode_attributes[i].name != NULL ? "N" : NULL);
 
   stream = fopen (width_filename, "r");
@@ -6798,11 +6767,11 @@ fill_width (const char *width_filename)
       /* Remove trailing spaces from field1.  */
       while (strlen (field1) > 0 && field1[strlen (field1) - 1] == ' ')
         field1[strlen (field1) - 1] = '\0';
-      i = strtoul (field0, NULL, 16);
+      unsigned int i = strtoul (field0, NULL, 16);
       if (strstr (field0, "..") != NULL)
         {
           /* Deal with a range.  */
-          j = strtoul (strstr (field0, "..") + 2, NULL, 16);
+          unsigned int j = strtoul (strstr (field0, "..") + 2, NULL, 16);
           for (; i <= j; i++)
             unicode_width[i] = strdup (field1);
         }
@@ -6872,7 +6841,6 @@ output_nonspacing_property (const char *filename, const char *version)
 {
   FILE *stream;
   int ind[0x110000 / 0x200];
-  unsigned int i;
   unsigned int i_max;
   int next_ind;
 
@@ -6895,13 +6863,12 @@ output_nonspacing_property (const char *filename, const char *version)
   fprintf (stream, "\n");
 
   next_ind = 0;
-  for (i = 0; i < 0x110000 / 0x200; i++)
+  for (unsigned int i = 0; i < 0x110000 / 0x200; i++)
     {
       bool nontrivial = false;
-      unsigned int ch;
 
       if (i != 0xe0000 / 0x200) /* The 0xe0000 block is handled by code.  */
-        for (ch = i * 0x200; ch < (i + 1) * 0x200; ch++)
+        for (unsigned int ch = i * 0x200; ch < (i + 1) * 0x200; ch++)
           if (is_nonspacing (ch))
             {
               nontrivial = true;
@@ -6916,26 +6883,21 @@ output_nonspacing_property (const char *filename, const char *version)
   fprintf (stream, "static const unsigned char nonspacing_table_data[%d*64] = {\n",
            next_ind);
   i_max = 0;
-  for (i = 0; i < 0x110000 / 0x200; i++)
+  for (unsigned int i = 0; i < 0x110000 / 0x200; i++)
     {
       bool nontrivial = (ind[i] >= 0);
 
       if (nontrivial)
         {
-          unsigned int j;
-
           fprintf (stream, "  /* 0x%04x-0x%04x */\n", i * 0x200, (i + 1) * 0x200 - 1);
-          for (j = 0; j < 8; j++)
+          for (unsigned int j = 0; j < 8; j++)
             {
-              unsigned int k;
-
               fprintf (stream, " ");
-              for (k = 0; k < 8; k++)
+              for (unsigned int k = 0; k < 8; k++)
                 {
-                  unsigned int l;
                   unsigned char bits = 0;
 
-                  for (l = 0; l < 8; l++)
+                  for (unsigned int l = 0; l < 8; l++)
                     {
                       unsigned int ch = i * 0x200 + j * 0x40 + k * 8 + l;
 
@@ -6956,24 +6918,18 @@ output_nonspacing_property (const char *filename, const char *version)
   i_max = ((i_max + 8 - 1) / 8) * 8;
   fprintf (stream, "static const signed char nonspacing_table_ind[%u] = {\n",
            i_max);
-  {
-    unsigned int j;
-
-    for (j = 0; j < i_max / 8; j++)
-      {
-        unsigned int k;
-
-        fprintf (stream, " ");
-        for (k = 0; k < 8; k++)
-          {
-            i = j * 8 + k;
-            fprintf (stream, " %2d%c", ind[i],
-                     j == i_max / 8 - 1 && k == 8 - 1 ? ' ' : ',');
-          }
-        fprintf (stream, " /* 0x%04x-0x%04x */\n",
-                 j * 8 * 0x200, (j + 1) * 8 * 0x200 - 1);
-      }
-  }
+  for (unsigned int j = 0; j < i_max / 8; j++)
+    {
+      fprintf (stream, " ");
+      for (unsigned int k = 0; k < 8; k++)
+        {
+          unsigned int i = j * 8 + k;
+          fprintf (stream, " %2d%c", ind[i],
+                   j == i_max / 8 - 1 && k == 8 - 1 ? ' ' : ',');
+        }
+      fprintf (stream, " /* 0x%04x-0x%04x */\n",
+               j * 8 * 0x200, (j + 1) * 8 * 0x200 - 1);
+    }
   fprintf (stream, "};\n");
 
   if (ferror (stream) || fclose (stream))
@@ -7148,7 +7104,7 @@ static void
 output_width_property_test (const char *filename)
 {
   FILE *stream;
-  unsigned int interval_start, interval_end, ch;
+  unsigned int interval_start, interval_end;
   char interval_value;
 
   stream = fopen (filename, "w");
@@ -7160,7 +7116,7 @@ output_width_property_test (const char *filename)
 
   interval_value = 0;
   interval_start = interval_end = 0; /* avoid GCC warning */
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       char value = symbolic_width (ch);
       if (value != 0) /* skip Cc control characters and unassigned characters */
@@ -8686,9 +8642,7 @@ get_lbp (unsigned int ch)
 static void
 debug_output_lbp (FILE *stream)
 {
-  unsigned int i;
-
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     {
       int64_t attr = get_lbp (i);
       if (attr != (int64_t) 1 << LBP_XX)
@@ -8787,7 +8741,6 @@ int unicode_org_lbp[0x110000];
 static void
 fill_org_lbp (const char *linebreak_filename)
 {
-  unsigned int i, j;
   FILE *stream;
   char field0[FIELDLEN];
   char field1[FIELDLEN];
@@ -8805,7 +8758,7 @@ fill_org_lbp (const char *linebreak_filename)
      Extended_Pictographic characters to LBP_EBF, and ensure that they
      behave like LBP_EB.  */
 
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     unicode_org_lbp[i] =
       (is_property_extended_pictographic (i) ? LBP_EBF : LBP_XX);
 
@@ -8919,11 +8872,11 @@ fill_org_lbp (const char *linebreak_filename)
                    field2, linebreak_filename, lineno);
           exit (1);
         }
-      i = strtoul (field0, NULL, 16);
+      unsigned int i = strtoul (field0, NULL, 16);
       if (strstr (field0, "..") != NULL)
         {
           /* Deal with a range.  */
-          j = strtoul (strstr (field0, "..") + 2, NULL, 16);
+          unsigned int j = strtoul (strstr (field0, "..") + 2, NULL, 16);
           for (; i <= j; i++)
             unicode_org_lbp[i] =
               (unassigned1 && is_property_extended_pictographic (i) ? LBP_EBF : value);
@@ -8947,9 +8900,7 @@ fill_org_lbp (const char *linebreak_filename)
 static void
 debug_output_org_lbp (FILE *stream)
 {
-  unsigned int i;
-
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     {
       int attr = unicode_org_lbp[i];
       if (attr != LBP_XX)
@@ -9110,7 +9061,6 @@ lbp_value_to_string (unsigned int value)
 static void
 output_lbpea (FILE *stream1, FILE *stream2)
 {
-  unsigned int i;
   struct lbpea_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
 
@@ -9118,7 +9068,7 @@ output_lbpea (FILE *stream1, FILE *stream2)
   t.q = 9;
   lbpea_table_init (&t);
 
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     {
       int64_t attr = get_lbp (i);
       int ea = get_lbea (i);
@@ -9147,7 +9097,7 @@ output_lbpea (FILE *stream1, FILE *stream2)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream1, "#define lbrkprop_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream1, "\n");
@@ -9165,7 +9115,7 @@ output_lbpea (FILE *stream1, FILE *stream2)
   fprintf (stream2, "  {");
   if (t.level1_size > 8)
     fprintf (stream2, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -9185,7 +9135,7 @@ output_lbpea (FILE *stream1, FILE *stream2)
   fprintf (stream2, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream2, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -9205,7 +9155,7 @@ output_lbpea (FILE *stream1, FILE *stream2)
   fprintf (stream2, "  {");
   if (t.level3_size << t.p > 8)
     fprintf (stream2, "\n   ");
-  for (i = 0; i < t.level3_size << t.p; i++)
+  for (unsigned int i = 0; i < t.level3_size << t.p; i++)
     {
       unsigned char value = ((unsigned char *) (t.result + level3_offset))[i];
       if (i > 0 && (i % 4) == 0)
@@ -9225,12 +9175,11 @@ output_lbrk_tables (const char *filename1, const char *filename2, const char *ve
 {
   const char *filenames[2];
   FILE *streams[2];
-  size_t i;
 
   filenames[0] = filename1;
   filenames[1] = filename2;
 
-  for (i = 0; i < 2; i++)
+  for (size_t i = 0; i < 2; i++)
     {
       streams[i] = fopen (filenames[i], "w");
       if (streams[i] == NULL)
@@ -9240,7 +9189,7 @@ output_lbrk_tables (const char *filename1, const char *filename2, const char *ve
         }
     }
 
-  for (i = 0; i < 2; i++)
+  for (size_t i = 0; i < 2; i++)
     {
       FILE *stream = streams[i];
 
@@ -9258,7 +9207,7 @@ output_lbrk_tables (const char *filename1, const char *filename2, const char *ve
 
   output_lbpea (streams[0], streams[1]);
 
-  for (i = 0; i < 2; i++)
+  for (size_t i = 0; i < 2; i++)
     {
       if (ferror (streams[i]) || fclose (streams[i]))
         {
@@ -9821,9 +9770,7 @@ get_wbp (unsigned int ch)
 static void
 debug_output_wbp (FILE *stream)
 {
-  unsigned int i;
-
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     {
       int attr = get_wbp (i);
       if (attr != 1 << WBP_OTHER)
@@ -9899,10 +9846,9 @@ int unicode_org_wbp[0x110000];
 static void
 fill_org_wbp (const char *wordbreakproperty_filename)
 {
-  unsigned int i;
   FILE *stream;
 
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     unicode_org_wbp[i] = WBP_OTHER;
 
   stream = fopen (wordbreakproperty_filename, "r");
@@ -9964,7 +9910,7 @@ fill_org_wbp (const char *wordbreakproperty_filename)
         }
       assert (i1 <= i2 && i2 < 0x110000);
 
-      for (i = i1; i <= i2; i++)
+      for (unsigned int i = i1; i <= i2; i++)
         unicode_org_wbp[i] = propvalue;
     }
 
@@ -9979,9 +9925,7 @@ fill_org_wbp (const char *wordbreakproperty_filename)
 static void
 debug_output_org_wbp (FILE *stream)
 {
-  unsigned int i;
-
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     {
       int propvalue = unicode_org_wbp[i];
       if (propvalue != WBP_OTHER)
@@ -10046,7 +9990,6 @@ debug_output_org_wbrk_tables (const char *filename)
 static void
 output_wbp (FILE *stream)
 {
-  unsigned int i;
   struct wbp_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
 
@@ -10054,7 +9997,7 @@ output_wbp (FILE *stream)
   t.q = 9;
   wbp_table_init (&t);
 
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     {
       int attr = get_wbp (i);
 
@@ -10082,7 +10025,7 @@ output_wbp (FILE *stream)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream, "#define wbrkprop_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream, "\n");
@@ -10098,7 +10041,7 @@ output_wbp (FILE *stream)
   fprintf (stream, "  {");
   if (t.level1_size > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -10118,7 +10061,7 @@ output_wbp (FILE *stream)
   fprintf (stream, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -10138,7 +10081,7 @@ output_wbp (FILE *stream)
   fprintf (stream, "  {");
   if (t.level3_size << t.p > 4)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level3_size << t.p; i++)
+  for (unsigned int i = 0; i < t.level3_size << t.p; i++)
     {
       unsigned char value = ((unsigned char *) (t.result + level3_offset))[i];
       const char *value_string;
@@ -10256,7 +10199,6 @@ output_gbp_test (const char *filename)
 {
   FILE *stream;
   bool need_comma;
-  unsigned int ch;
 
   stream = fopen (filename, "w");
   if (stream == NULL)
@@ -10273,7 +10215,7 @@ output_gbp_test (const char *filename)
   fprintf (stream, "\n");
 
   need_comma = false;
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int gbp = unicode_org_gbp[ch];
       const char *gbp_string;
@@ -10327,7 +10269,6 @@ static void
 output_gbp_table (const char *filename, const char *version)
 {
   FILE *stream;
-  unsigned int ch, i;
   struct gbp_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
 
@@ -10353,7 +10294,7 @@ output_gbp_table (const char *filename, const char *version)
   t.q = 9;
   gbp_table_init (&t);
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     gbp_table_add (&t, ch, unicode_org_gbp[ch]);
 
   gbp_table_finalize (&t);
@@ -10369,7 +10310,7 @@ output_gbp_table (const char *filename, const char *version)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream, "#define gbrkprop_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream, "static const\n");
@@ -10385,7 +10326,7 @@ output_gbp_table (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level1_size > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -10405,7 +10346,7 @@ output_gbp_table (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -10425,7 +10366,7 @@ output_gbp_table (const char *filename, const char *version)
   fprintf (stream, "  {");
   if (t.level3_size << t.p > 4)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level3_size << t.p; i++)
+  for (unsigned int i = 0; i < t.level3_size << t.p; i++)
     {
       unsigned char value = ((unsigned char *) (t.result + level3_offset))[i];
       const char *value_string;
@@ -10476,11 +10417,10 @@ output_gbp_table (const char *filename, const char *version)
 static void
 fill_org_gbp (const char *graphemebreakproperty_filename)
 {
-  unsigned int i;
   FILE *stream;
   int lineno = 0;
 
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     unicode_org_gbp[i] = GBP_OTHER;
 
   stream = fopen (graphemebreakproperty_filename, "r");
@@ -10543,7 +10483,7 @@ fill_org_gbp (const char *graphemebreakproperty_filename)
         }
       assert (i1 <= i2 && i2 < 0x110000);
 
-      for (i = i1; i <= i2; i++)
+      for (unsigned int i = i1; i <= i2; i++)
         unicode_org_gbp[i] = propvalue;
     }
 
@@ -10668,9 +10608,6 @@ output_decomposition (FILE *stream1, FILE *stream2)
 {
   struct decomp_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
-  unsigned int offset;
-  unsigned int ch;
-  unsigned int i;
 
   t.p = 5;
   t.q = 5;
@@ -10679,39 +10616,40 @@ output_decomposition (FILE *stream1, FILE *stream2)
   fprintf (stream1, "extern const unsigned char gl_uninorm_decomp_chars_table[];\n");
   fprintf (stream1, "\n");
   fprintf (stream2, "const unsigned char gl_uninorm_decomp_chars_table[] =\n{");
-  offset = 0;
-
-  for (ch = 0; ch < 0x110000; ch++)
-    {
-      unsigned int length;
-      unsigned int decomposed[MAX_DECOMP_LENGTH];
-      int type = get_decomposition (ch, &length, decomposed);
+  {
+    unsigned int offset = 0;
+    for (unsigned int ch = 0; ch < 0x110000; ch++)
+      {
+        unsigned int length;
+        unsigned int decomposed[MAX_DECOMP_LENGTH];
+        int type = get_decomposition (ch, &length, decomposed);
 
-      if (type >= 0)
-        {
-          assert (offset < (1 << 15));
-          decomp_table_add (&t, ch, ((type == UC_DECOMP_CANONICAL ? 0 : 1) << 15) | offset);
+        if (type >= 0)
+          {
+            assert (offset < (1 << 15));
+            decomp_table_add (&t, ch, ((type == UC_DECOMP_CANONICAL ? 0 : 1) << 15) | offset);
 
-          /* Produce length 3-bytes entries.  */
-          /* We would need a special representation of zero-length entries.  */
-          assert (length != 0);
-          for (i = 0; i < length; i++)
-            {
-              if (offset > 0)
-                fprintf (stream2, ",");
-              if ((offset % 4) == 0)
-                fprintf (stream2, "\n ");
-              assert (decomposed[i] < (1 << 18));
-              fprintf (stream2, " 0x%02X, 0x%02X, 0x%02X",
-                       (((i+1 < length ? (1 << 23) : 0)
-                         | (i == 0 ? (type << 18) : 0)
-                         | decomposed[i]) >> 16) & 0xff,
-                       (decomposed[i] >> 8) & 0xff,
-                       decomposed[i] & 0xff);
-              offset++;
-            }
-        }
-    }
+            /* Produce length 3-bytes entries.  */
+            /* We would need a special representation of zero-length entries.  */
+            assert (length != 0);
+            for (unsigned int i = 0; i < length; i++)
+              {
+                if (offset > 0)
+                  fprintf (stream2, ",");
+                if ((offset % 4) == 0)
+                  fprintf (stream2, "\n ");
+                assert (decomposed[i] < (1 << 18));
+                fprintf (stream2, " 0x%02X, 0x%02X, 0x%02X",
+                         (((i+1 < length ? (1 << 23) : 0)
+                           | (i == 0 ? (type << 18) : 0)
+                           | decomposed[i]) >> 16) & 0xff,
+                         (decomposed[i] >> 8) & 0xff,
+                         decomposed[i] & 0xff);
+                offset++;
+              }
+          }
+      }
+  }
 
   fprintf (stream2, "\n};\n");
   fprintf (stream2, "\n");
@@ -10728,7 +10666,7 @@ output_decomposition (FILE *stream1, FILE *stream2)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream1, "#define decomp_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream1, "\n");
@@ -10745,7 +10683,7 @@ output_decomposition (FILE *stream1, FILE *stream2)
   fprintf (stream2, "  {");
   if (t.level1_size > 8)
     fprintf (stream2, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -10765,7 +10703,7 @@ output_decomposition (FILE *stream1, FILE *stream2)
   fprintf (stream2, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream2, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -10785,7 +10723,7 @@ output_decomposition (FILE *stream1, FILE *stream2)
   fprintf (stream2, "  {");
   if (t.level3_size << t.p > 8)
     fprintf (stream2, "\n   ");
-  for (i = 0; i < t.level3_size << t.p; i++)
+  for (unsigned int i = 0; i < t.level3_size << t.p; i++)
     {
       uint16_t value = ((uint16_t *) (t.result + level3_offset))[i];
       if (i > 0 && (i % 8) == 0)
@@ -10805,12 +10743,11 @@ output_decomposition_tables (const char *filename1, const char *filename2, const
 {
   const char *filenames[2];
   FILE *streams[2];
-  size_t i;
 
   filenames[0] = filename1;
   filenames[1] = filename2;
 
-  for (i = 0; i < 2; i++)
+  for (size_t i = 0; i < 2; i++)
     {
       streams[i] = fopen (filenames[i], "w");
       if (streams[i] == NULL)
@@ -10820,7 +10757,7 @@ output_decomposition_tables (const char *filename1, const char *filename2, const
         }
     }
 
-  for (i = 0; i < 2; i++)
+  for (size_t i = 0; i < 2; i++)
     {
       FILE *stream = streams[i];
 
@@ -10838,7 +10775,7 @@ output_decomposition_tables (const char *filename1, const char *filename2, const
 
   output_decomposition (streams[0], streams[1]);
 
-  for (i = 0; i < 2; i++)
+  for (size_t i = 0; i < 2; i++)
     {
       if (ferror (streams[i]) || fclose (streams[i]))
         {
@@ -10855,7 +10792,6 @@ static void
 fill_composition_exclusions (const char *compositionexclusions_filename)
 {
   FILE *stream;
-  unsigned int i;
 
   stream = fopen (compositionexclusions_filename, "r");
   if (stream == NULL)
@@ -10864,7 +10800,7 @@ fill_composition_exclusions (const char *compositionexclusions_filename)
       exit (1);
     }
 
-  for (i = 0; i < 0x110000; i++)
+  for (unsigned int i = 0; i < 0x110000; i++)
     unicode_composition_exclusions[i] = 0;
 
   for (;;)
@@ -10899,7 +10835,6 @@ static void
 debug_output_composition_tables (const char *filename)
 {
   FILE *stream;
-  unsigned int ch;
 
   stream = fopen (filename, "w");
   if (stream == NULL)
@@ -10908,7 +10843,7 @@ debug_output_composition_tables (const char *filename)
       exit (1);
     }
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       unsigned int length;
       unsigned int decomposed[MAX_DECOMP_LENGTH];
@@ -10956,7 +10891,6 @@ output_composition_tables (const char *filename, const char *filename2,
   unsigned int max_code1;
   unsigned int max_code2;
   FILE *stream;
-  unsigned int ch;
 
   max_code1 = 0;
   max_code2 = 0;
@@ -11010,7 +10944,7 @@ output_composition_tables (const char *filename, const char *filename2,
   fprintf (stream, "%%omit-struct-type\n");
   fprintf (stream, "%%%%\n");
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       unsigned int length;
       unsigned int decomposed[MAX_DECOMP_LENGTH];
@@ -11098,7 +11032,6 @@ output_simple_mapping_test (const char *filename,
 {
   FILE *stream;
   bool need_comma;
-  unsigned int ch;
 
   stream = fopen (filename, "w");
   if (stream == NULL)
@@ -11120,7 +11053,7 @@ output_simple_mapping_test (const char *filename,
   fprintf (stream, "\n");
 
   need_comma = false;
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       unsigned int value = func (ch);
 
@@ -11162,7 +11095,6 @@ output_simple_mapping (const char *filename,
                        const char *version)
 {
   FILE *stream;
-  unsigned int ch, i;
   struct mapping_table t;
   unsigned int level1_offset, level2_offset, level3_offset;
 
@@ -11190,7 +11122,7 @@ output_simple_mapping (const char *filename,
   t.q = 9;
   mapping_table_init (&t);
 
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value = (int) func (ch) - (int) ch;
 
@@ -11210,7 +11142,7 @@ output_simple_mapping (const char *filename,
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
 
-  for (i = 0; i < 5; i++)
+  for (unsigned int i = 0; i < 5; i++)
     fprintf (stream, "#define mapping_header_%d %d\n", i,
              ((uint32_t *) t.result)[i]);
   fprintf (stream, "static const\n");
@@ -11225,7 +11157,7 @@ output_simple_mapping (const char *filename,
   fprintf (stream, "  {");
   if (t.level1_size > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level1_size; i++)
+  for (unsigned int i = 0; i < t.level1_size; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -11245,7 +11177,7 @@ output_simple_mapping (const char *filename,
   fprintf (stream, "  {");
   if (t.level2_size << t.q > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level2_size << t.q; i++)
+  for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
       uint32_t offset;
       if (i > 0 && (i % 8) == 0)
@@ -11265,7 +11197,7 @@ output_simple_mapping (const char *filename,
   fprintf (stream, "  {");
   if (t.level3_size << t.p > 8)
     fprintf (stream, "\n   ");
-  for (i = 0; i < t.level3_size << t.p; i++)
+  for (unsigned int i = 0; i < t.level3_size << t.p; i++)
     {
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
@@ -11354,7 +11286,6 @@ fill_casing_rules (const char *specialcasing_filename)
       char buf[200+1];
       char *scanptr;
       char *endptr;
-      int i;
 
       unsigned int code;
       unsigned int lower_mapping[3];
@@ -11386,9 +11317,9 @@ fill_casing_rules (const char *specialcasing_filename)
       scanptr++;
 
       /* Scan lower mapping.  */
-      for (i = 0; i < 3; i++)
+      for (int i = 0; i < 3; i++)
         lower_mapping[i] = 0;
-      for (i = 0; i < 3; i++)
+      for (int i = 0; i < 3; i++)
         {
           while (*scanptr == ' ')
             scanptr++;
@@ -11410,9 +11341,9 @@ fill_casing_rules (const char *specialcasing_filename)
       scanptr++;
 
       /* Scan title mapping.  */
-      for (i = 0; i < 3; i++)
+      for (int i = 0; i < 3; i++)
         title_mapping[i] = 0;
-      for (i = 0; i < 3; i++)
+      for (int i = 0; i < 3; i++)
         {
           while (*scanptr == ' ')
             scanptr++;
@@ -11434,9 +11365,9 @@ fill_casing_rules (const char *specialcasing_filename)
       scanptr++;
 
       /* Scan upper mapping.  */
-      for (i = 0; i < 3; i++)
+      for (int i = 0; i < 3; i++)
         upper_mapping[i] = 0;
-      for (i = 0; i < 3; i++)
+      for (int i = 0; i < 3; i++)
         {
           while (*scanptr == ' ')
             scanptr++;
@@ -11583,7 +11514,6 @@ fill_casefolding_rules (const char *casefolding_filename)
       char buf[200+1];
       char *scanptr;
       char *endptr;
-      int i;
 
       unsigned int code;
       char type;
@@ -11633,9 +11563,9 @@ fill_casefolding_rules (const char *casefolding_filename)
       scanptr++;
 
       /* Scan casefold mapping.  */
-      for (i = 0; i < 3; i++)
+      for (int i = 0; i < 3; i++)
         mapping[i] = 0;
-      for (i = 0; i < 3; i++)
+      for (int i = 0; i < 3; i++)
         {
           while (*scanptr == ' ')
             scanptr++;
@@ -11677,7 +11607,7 @@ fill_casefolding_rules (const char *casefolding_filename)
               languages_count = 1;
             }
 
-          for (i = 0; i < languages_count; i++)
+          for (int i = 0; i < languages_count; i++)
             {
               /* Store a new rule.  */
               struct casefold_rule *new_rule =
@@ -11724,18 +11654,16 @@ to_casefold (unsigned int ch)
 static void
 redistribute_casefolding_rules (void)
 {
-  unsigned int ch, i, j;
-
   /* Fill unicode_casefold[].  */
-  for (ch = 0; ch < 0x110000; ch++)
+  for (unsigned int ch = 0; ch < 0x110000; ch++)
     unicode_casefold[ch] = ch;
-  for (i = 0; i < num_casefolding_rules; i++)
+  for (unsigned int i = 0; i < num_casefolding_rules; i++)
     {
       struct casefold_rule *cfrule = casefolding_rules[i];
 
       if (cfrule->language == NULL && cfrule->mapping[1] == 0)
         {
-          ch = cfrule->code;
+          unsigned int ch = cfrule->code;
           assert (ch < 0x110000);
           unicode_casefold[ch] = cfrule->mapping[0];
         }
@@ -11743,18 +11671,17 @@ redistribute_casefolding_rules (void)
 
   /* Extend the special casing rules by filling in their casefold_mapping[]
      field.  */
-  for (j = 0; j < num_casing_rules; j++)
+  for (unsigned int j = 0; j < num_casing_rules; j++)
     {
       struct special_casing_rule *rule = casing_rules[j];
-      unsigned int k;
 
       rule->casefold_mapping[0] = to_casefold (rule->code);
-      for (k = 1; k < 3; k++)
+      for (unsigned int k = 1; k < 3; k++)
         rule->casefold_mapping[k] = 0;
     }
 
   /* Now merge the other casefolding rules into casing_rules.  */
-  for (i = 0; i < num_casefolding_rules; i++)
+  for (unsigned int i = 0; i < num_casefolding_rules; i++)
     {
       struct casefold_rule *cfrule = casefolding_rules[i];
 
@@ -11765,7 +11692,7 @@ redistribute_casefolding_rules (void)
              have the same code and same or more specific language.  */
           struct special_casing_rule *found_rule = NULL;
 
-          for (j = 0; j < num_casing_rules; j++)
+          for (unsigned int j = 0; j < num_casing_rules; j++)
             {
               struct special_casing_rule *rule = casing_rules[j];
 
@@ -11797,7 +11724,7 @@ redistribute_casefolding_rules (void)
 
               /* Try to find a rule that applies to the same code, no language
                  restriction, and with context SCC_ALWAYS.  */
-              for (j = 0; j < num_casing_rules; j++)
+              for (unsigned int j = 0; j < num_casing_rules; j++)
                 {
                   struct special_casing_rule *rule = casing_rules[j];
 
@@ -11825,16 +11752,14 @@ redistribute_casefolding_rules (void)
                 }
               else
                 {
-                  unsigned int k;
-
                   new_rule->lower_mapping[0] = to_lower (cfrule->code);
-                  for (k = 1; k < 3; k++)
+                  for (unsigned int k = 1; k < 3; k++)
                     new_rule->lower_mapping[k] = 0;
                   new_rule->title_mapping[0] = to_title (cfrule->code);
-                  for (k = 1; k < 3; k++)
+                  for (unsigned int k = 1; k < 3; k++)
                     new_rule->title_mapping[k] = 0;
                   new_rule->upper_mapping[0] = to_upper (cfrule->code);
-                  for (k = 1; k < 3; k++)
+                  for (unsigned int k = 1; k < 3; k++)
                     new_rule->upper_mapping[k] = 0;
                 }
               memcpy (new_rule->casefold_mapping, cfrule->mapping,
@@ -11878,7 +11803,6 @@ static void
 output_casing_rules (const char *filename, const char *version)
 {
   FILE *stream;
-  unsigned int i, j;
   unsigned int minor;
 
   stream = fopen (filename, "w");
@@ -11912,7 +11836,7 @@ output_casing_rules (const char *filename, const char *version)
   fprintf (stream, "%%%%\n");
 
   minor = 0;
-  for (i = 0; i < num_casing_rules; i++)
+  for (unsigned int i = 0; i < num_casing_rules; i++)
     {
       struct special_casing_rule *rule = casing_rules[i];
       int context;
@@ -11976,7 +11900,7 @@ output_casing_rules (const char *filename, const char *version)
         fprintf (stream, "{ '\\0', '\\0' }, ");
 
       fprintf (stream, "{ ");
-      for (j = 0; j < 3; j++)
+      for (unsigned int j = 0; j < 3; j++)
         {
           if (j > 0)
             fprintf (stream, ", ");
@@ -11991,7 +11915,7 @@ output_casing_rules (const char *filename, const char *version)
             fprintf (stream, "     0");
         }
       fprintf (stream, " }, { ");
-      for (j = 0; j < 3; j++)
+      for (unsigned int j = 0; j < 3; j++)
         {
           if (j > 0)
             fprintf (stream, ", ");
@@ -12006,7 +11930,7 @@ output_casing_rules (const char *filename, const char *version)
             fprintf (stream, "     0");
         }
       fprintf (stream, " }, { ");
-      for (j = 0; j < 3; j++)
+      for (unsigned int j = 0; j < 3; j++)
         {
           if (j > 0)
             fprintf (stream, ", ");
@@ -12021,7 +11945,7 @@ output_casing_rules (const char *filename, const char *version)
             fprintf (stream, "     0");
         }
       fprintf (stream, " }, { ");
-      for (j = 0; j < 3; j++)
+      for (unsigned int j = 0; j < 3; j++)
         {
           if (j > 0)
             fprintf (stream, ", ");
diff --git a/lib/get_ppid_of.c b/lib/get_ppid_of.c
index 83df0065e6..87e77fc9f8 100644
--- a/lib/get_ppid_of.c
+++ b/lib/get_ppid_of.c
@@ -89,13 +89,12 @@ get_ppid_of (pid_t pid)
       if (nread >= 0)
         {
           char *bufend = buf + nread;
-          char *p;
 
           /* NUL-terminate the buffer.  */
           *bufend = '\0';
 
           /* Search for a line that starts with "PPid:".  */
-          for (p = buf;;)
+          for (char *p = buf;;)
             {
               if (bufend - p >= 5 && memeq (p, "PPid:", 5))
                 {
diff --git a/lib/getdtablesize.c b/lib/getdtablesize.c
index b98fbb70ad..396993821c 100644
--- a/lib/getdtablesize.c
+++ b/lib/getdtablesize.c
@@ -61,13 +61,10 @@ getdtablesize (void)
     {
       /* We are looking for the number N such that the valid file descriptors
          are 0..N-1.  It can be obtained through a loop as follows:
-           {
-             int fd;
-             for (fd = 3; fd < 65536; fd++)
-               if (dup2 (0, fd) == -1)
-                 break;
-             return fd;
-           }
+           for (int fd = 3; fd < 65536; fd++)
+             if (dup2 (0, fd) == -1)
+               break;
+           return fd;
          On Windows XP, the result is 2048.
          The drawback of this loop is that it allocates memory for a libc
          internal array that is never freed.
diff --git a/lib/getloadavg.c b/lib/getloadavg.c
index 1e3e215360..f9ed97b04b 100644
--- a/lib/getloadavg.c
+++ b/lib/getloadavg.c
@@ -623,11 +623,11 @@ getloadavg (double loadavg[], int nelem)
   struct proc_summary proc_sum_data;
   struct stat_descr proc_info;
   double load;
-  register unsigned int i, j;
+  register unsigned int j;
 
   if (cpus == 0)
     {
-      register unsigned int c, i;
+      register unsigned int c;
       struct cpu_config conf;
       struct stat_descr desc;
 
@@ -641,7 +641,7 @@ getloadavg (double loadavg[], int nelem)
         return -1;
 
       c = 0;
-      for (i = 0; i < conf.config_maxclass; ++i)
+      for (unsigned int i = 0; i < conf.config_maxclass; ++i)
         {
           struct class_stats stats;
           memset (&stats, 0, sizeof stats);
@@ -672,7 +672,7 @@ getloadavg (double loadavg[], int nelem)
 
   load = proc_sum_data.ps_nrunnable;
   j = 0;
-  for (i = samples - 1; i > 0; --i)
+  for (unsigned int i = samples - 1; i > 0; --i)
     {
       load += proc_sum_data.ps_nrun[j];
       if (j++ == PS_NRUNSIZE)
diff --git a/lib/getlocalename_l-unsafe.c b/lib/getlocalename_l-unsafe.c
index e27388294c..27cc5f38e6 100644
--- a/lib/getlocalename_l-unsafe.c
+++ b/lib/getlocalename_l-unsafe.c
@@ -97,10 +97,9 @@ get_locale_t_name_unsafe (int category, locale_t locale)
          happen if the application uses the original newlocale()/duplocale()
          functions instead of the overridden ones.  */
       const char *name = "";
-      struct locale_hash_node *p;
       /* Lock while looking up the hash node.  */
       gl_rwlock_rdlock (locale_lock);
-      for (p = locale_hash_table[slot]; p != NULL; p = p->next)
+      for (struct locale_hash_node *p = locale_hash_table[slot]; p != NULL; p = p->next)
         if (p->locale == locale)
           {
             name = p->names.category_name[category - LCMIN];
@@ -147,10 +146,8 @@ newlocale (int category_mask, const char *name, locale_t base)
        & ~category_mask) == 0)
     {
       /* Use name, ignore base.  */
-      int i;
-
       name = struniq (name);
-      for (i = 0; i < 6; i++)
+      for (int i = 0; i < 6; i++)
         names.category_name[i] = name;
     }
   else
@@ -158,9 +155,7 @@ newlocale (int category_mask, const char *name, locale_t base)
       /* Use base, possibly also name.  */
       if (base == NULL)
         {
-          int i;
-
-          for (i = 0; i < 6; i++)
+          for (int i = 0; i < 6; i++)
             {
               int category = i + LCMIN;
               int mask;
@@ -194,9 +189,7 @@ newlocale (int category_mask, const char *name, locale_t base)
         }
       else if (base == LC_GLOBAL_LOCALE)
         {
-          int i;
-
-          for (i = 0; i < 6; i++)
+          for (int i = 0; i < 6; i++)
             {
               int category = i + LCMIN;
               int mask;
@@ -244,8 +237,7 @@ newlocale (int category_mask, const char *name, locale_t base)
             if (p->locale == base)
               break;
 
-          int i;
-          for (i = 0; i < 6; i++)
+          for (int i = 0; i < 6; i++)
             {
               int category = i + LCMIN;
               int mask;
@@ -358,9 +350,7 @@ duplocale (locale_t locale)
   node->locale = result;
   if (locale == LC_GLOBAL_LOCALE)
     {
-      int i;
-
-      for (i = 0; i < 6; i++)
+      for (int i = 0; i < 6; i++)
         {
           int category = i + LCMIN;
           node->names.category_name[i] =
@@ -389,9 +379,7 @@ duplocale (locale_t locale)
           /* This can happen if the application uses the original
              newlocale()/duplocale() functions instead of the overridden
              ones.  */
-          int i;
-
-          for (i = 0; i < 6; i++)
+          for (int i = 0; i < 6; i++)
             node->names.category_name[i] = "";
         }
     }
@@ -438,12 +426,11 @@ freelocale (locale_t locale)
     size_t hashcode = locale_hash_function (locale);
     size_t slot = hashcode % LOCALE_HASH_TABLE_SIZE;
     struct locale_hash_node *found;
-    struct locale_hash_node **p;
 
     found = NULL;
     /* Lock while removing the hash node.  */
     gl_rwlock_wrlock (locale_lock);
-    for (p = &locale_hash_table[slot]; *p != NULL; p = &(*p)->next)
+    for (struct locale_hash_node **p = &locale_hash_table[slot]; *p != NULL; p = &(*p)->next)
       if ((*p)->locale == locale)
         {
           found = *p;
diff --git a/lib/getlogin.c b/lib/getlogin.c
index 36965f1db5..3005179708 100644
--- a/lib/getlogin.c
+++ b/lib/getlogin.c
@@ -92,8 +92,7 @@ getlogin (void)
             if (read_utmp (UTMP_FILE, &n, &entries, READ_UTMP_USER_PROCESS)
                 == 0)
               {
-                idx_t i;
-                for (i = 0; i < n; i++)
+                for (idx_t i = 0; i < n; i++)
                   if (streq (entries[i].ut_line, tty + 5))
                     {
                       if (strlen (entries[i].ut_user) < 64)
diff --git a/lib/getprogname.c b/lib/getprogname.c
index 4da2159fe3..4e424bc236 100644
--- a/lib/getprogname.c
+++ b/lib/getprogname.c
@@ -188,7 +188,6 @@ getprogname (void)
   if (first)
     {
       pid_t pid = getpid ();
-      int token;
       W_PSPROC buf;
       first = 0;
       memset (&buf, 0, sizeof(buf));
@@ -197,7 +196,8 @@ getprogname (void)
       buf.ps_pathptr   = (char *) malloc (buf.ps_pathlen   = PS_PATHBLEN);
       if (buf.ps_cmdptr && buf.ps_conttyptr && buf.ps_pathptr)
         {
-          for (token = 0; token >= 0;
+          for (int token = 0;
+               token >= 0;
                token = w_getpsent (token, &buf, sizeof(buf)))
             {
               if (token > 0 && buf.ps_pid == pid)
diff --git a/lib/getugroups.c b/lib/getugroups.c
index 5f48d56ec4..e4a8c8d6c6 100644
--- a/lib/getugroups.c
+++ b/lib/getugroups.c
@@ -71,7 +71,6 @@ getugroups (int maxcount, gid_t *grouplist, char const *username,
   setgrent ();
   while (1)
     {
-      char **cp;
       struct group *grp;
 
       errno = 0;
@@ -79,7 +78,7 @@ getugroups (int maxcount, gid_t *grouplist, char const *username,
       if (grp == NULL)
         break;
 
-      for (cp = grp->gr_mem; *cp; ++cp)
+      for (char **cp = grp->gr_mem; *cp; ++cp)
         {
           int n;
 
diff --git a/lib/gl_anyavltree_list2.h b/lib/gl_anyavltree_list2.h
index 526f6127f8..e283828afe 100644
--- a/lib/gl_anyavltree_list2.h
+++ b/lib/gl_anyavltree_list2.h
@@ -429,12 +429,8 @@ gl_tree_remove_node_from_tree (gl_list_t list, gl_list_node_t node)
             parent->right = child;
 
           /* Update branch_size fields of the parent nodes.  */
-          {
-            gl_list_node_t p;
-
-            for (p = parent; p != NULL; p = p->parent)
-              p->branch_size--;
-          }
+          for (gl_list_node_t p = parent; p != NULL; p = p->parent)
+            p->branch_size--;
 
           rebalance (list, child, -1, parent);
         }
@@ -457,12 +453,8 @@ gl_tree_remove_node_from_tree (gl_list_t list, gl_list_node_t node)
             parent->right = child;
 
           /* Update branch_size fields of the parent nodes.  */
-          {
-            gl_list_node_t p;
-
-            for (p = parent; p != NULL; p = p->parent)
-              p->branch_size--;
-          }
+          for (gl_list_node_t p = parent; p != NULL; p = p->parent)
+            p->branch_size--;
 
           rebalance (list, child, -1, parent);
         }
@@ -500,12 +492,8 @@ gl_tree_remove_node_from_tree (gl_list_t list, gl_list_node_t node)
         }
 
       /* Update branch_size fields of the parent nodes.  */
-      {
-        gl_list_node_t p;
-
-        for (p = subst_parent; p != NULL; p = p->parent)
-          p->branch_size--;
-      }
+      for (gl_list_node_t p = subst_parent; p != NULL; p = p->parent)
+        p->branch_size--;
 
       /* Copy subst into node's position.
          (This is safer than to copy subst's value into node, keep node in
@@ -574,12 +562,8 @@ gl_tree_nx_add_first (gl_list_t list, const void *elt)
       node->balance--;
 
       /* Update branch_size fields of the parent nodes.  */
-      {
-        gl_list_node_t p;
-
-        for (p = node; p != NULL; p = p->parent)
-          p->branch_size++;
-      }
+      for (gl_list_node_t p = node; p != NULL; p = p->parent)
+        p->branch_size++;
 
       /* Rebalance.  */
       if (node->right == NULL && node->parent != NULL)
@@ -642,12 +626,8 @@ gl_tree_nx_add_last (gl_list_t list, const void *elt)
       node->balance++;
 
       /* Update branch_size fields of the parent nodes.  */
-      {
-        gl_list_node_t p;
-
-        for (p = node; p != NULL; p = p->parent)
-          p->branch_size++;
-      }
+      for (gl_list_node_t p = node; p != NULL; p = p->parent)
+        p->branch_size++;
 
       /* Rebalance.  */
       if (node->left == NULL && node->parent != NULL)
@@ -712,12 +692,8 @@ gl_tree_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
   new_node->parent = node;
 
   /* Update branch_size fields of the parent nodes.  */
-  {
-    gl_list_node_t p;
-
-    for (p = node; p != NULL; p = p->parent)
-      p->branch_size++;
-  }
+  for (gl_list_node_t p = node; p != NULL; p = p->parent)
+    p->branch_size++;
 
   /* Rebalance.  */
   if (height_inc && node->parent != NULL)
@@ -781,12 +757,8 @@ gl_tree_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
   new_node->parent = node;
 
   /* Update branch_size fields of the parent nodes.  */
-  {
-    gl_list_node_t p;
-
-    for (p = node; p != NULL; p = p->parent)
-      p->branch_size++;
-  }
+  for (gl_list_node_t p = node; p != NULL; p = p->parent)
+    p->branch_size++;
 
   /* Rebalance.  */
   if (height_inc && node->parent != NULL)
diff --git a/lib/gl_anyhash2.h b/lib/gl_anyhash2.h
index 8dac30f259..6dcb57f125 100644
--- a/lib/gl_anyhash2.h
+++ b/lib/gl_anyhash2.h
@@ -33,7 +33,6 @@ hash_resize (CONTAINER_T container, size_t estimate)
       gl_hash_entry_t *old_table = container->table;
       /* Allocate the new table.  */
       gl_hash_entry_t *new_table;
-      size_t i;
 
       if (size_overflow_p (xtimes (new_size, sizeof (gl_hash_entry_t))))
         goto fail;
@@ -43,7 +42,7 @@ hash_resize (CONTAINER_T container, size_t estimate)
         goto fail;
 
       /* Iterate through the entries of the old table.  */
-      for (i = container->table_size; i > 0; )
+      for (size_t i = container->table_size; i > 0; )
         {
           gl_hash_entry_t node = old_table[--i];
 
diff --git a/lib/gl_anyhash_primes.h b/lib/gl_anyhash_primes.h
index 7539f05591..23955c0e66 100644
--- a/lib/gl_anyhash_primes.h
+++ b/lib/gl_anyhash_primes.h
@@ -78,9 +78,7 @@ static const size_t primes[] =
 static size_t
 next_prime (size_t estimate)
 {
-  size_t i;
-
-  for (i = 0; i < sizeof (primes) / sizeof (primes[0]); i++)
+  for (size_t i = 0; i < sizeof (primes) / sizeof (primes[0]); i++)
     if (primes[i] >= estimate)
       return primes[i];
   return SIZE_MAX; /* not a prime, but better than nothing */
diff --git a/lib/gl_anylinked_list2.h b/lib/gl_anylinked_list2.h
index 4d38a49e27..4b7a42f64c 100644
--- a/lib/gl_anylinked_list2.h
+++ b/lib/gl_anylinked_list2.h
@@ -144,17 +144,13 @@ gl_linked_nx_create (gl_list_implementation_t implementation,
   return list;
 
  fail2:
-  {
-    gl_list_node_t node;
-
-    for (node = tail; node != &list->root; )
-      {
-        gl_list_node_t prev = node->prev;
+  for (gl_list_node_t node = tail; node != &list->root; )
+    {
+      gl_list_node_t prev = node->prev;
 
-        free (node);
-        node = prev;
-      }
-  }
+      free (node);
+      node = prev;
+    }
 #if WITH_HASHTABLE
   free (list->table);
  fail1:
@@ -354,9 +350,8 @@ gl_linked_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
       {
         /* Look for the first match in the hash bucket.  */
         gl_list_node_t found = NULL;
-        gl_list_node_t node;
 
-        for (node = (gl_list_node_t) list->table[bucket];
+        for (gl_list_node_t node = (gl_list_node_t) list->table[bucket];
              node != NULL;
              node = (gl_list_node_t) node->h.hash_next)
           if (node->h.hashcode == hashcode
@@ -369,7 +364,7 @@ gl_linked_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
             }
         if (start_index > 0)
           /* Look whether found's index is < start_index.  */
-          for (node = list->root.next; ; node = node->next)
+          for (gl_list_node_t node = list->root.next; ; node = node->next)
             {
               if (node == found)
                 return NULL;
@@ -380,7 +375,7 @@ gl_linked_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
           /* Look whether found's index is >= end_index.  */
           {
             end_index = count - end_index;
-            for (node = list->root.prev; ; node = node->prev)
+            for (gl_list_node_t node = list->root.prev; ; node = node->prev)
               {
                 if (node == found)
                   return NULL;
@@ -395,9 +390,8 @@ gl_linked_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
         /* Look whether there is more than one match in the hash bucket.  */
         bool multiple_matches = false;
         gl_list_node_t first_match = NULL;
-        gl_list_node_t node;
 
-        for (node = (gl_list_node_t) list->table[bucket];
+        for (gl_list_node_t node = (gl_list_node_t) list->table[bucket];
              node != NULL;
              node = (gl_list_node_t) node->h.hash_next)
           if (node->h.hashcode == hashcode
@@ -418,7 +412,7 @@ gl_linked_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
             /* We need the match with the smallest index.  But we don't have
                a fast mapping node -> index.  So we have to walk the list.  */
             end_index -= start_index;
-            node = list->root.next;
+            gl_list_node_t node = list->root.next;
             for (; start_index > 0; start_index--)
               node = node->next;
 
@@ -438,7 +432,7 @@ gl_linked_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
           {
             if (start_index > 0)
               /* Look whether first_match's index is < start_index.  */
-              for (node = list->root.next; node != &list->root; node = node->next)
+              for (gl_list_node_t node = list->root.next; node != &list->root; node = node->next)
                 {
                   if (node == first_match)
                     return NULL;
@@ -449,7 +443,7 @@ gl_linked_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
               /* Look whether first_match's index is >= end_index.  */
               {
                 end_index = list->count - end_index;
-                for (node = list->root.prev; ; node = node->prev)
+                for (gl_list_node_t node = list->root.prev; ; node = node->prev)
                   {
                     if (node == first_match)
                       return NULL;
@@ -916,9 +910,8 @@ static void
 gl_linked_list_free (gl_list_t list)
 {
   gl_listelement_dispose_fn dispose = list->base.dispose_fn;
-  gl_list_node_t node;
 
-  for (node = list->root.next; node != &list->root; )
+  for (gl_list_node_t node = list->root.next; node != &list->root; )
     {
       gl_list_node_t next = node->next;
       if (dispose != NULL)
@@ -973,13 +966,12 @@ gl_linked_iterator_from_to (gl_list_t list,
     {
       /* n1 is the maximum, use n2 and n3.  */
       gl_list_node_t node;
-      size_t i;
 
       node = &list->root;
-      for (i = n3; i > 0; i--)
+      for (size_t i = n3; i > 0; i--)
         node = node->prev;
       result.q = node;
-      for (i = n2; i > 0; i--)
+      for (size_t i = n2; i > 0; i--)
         node = node->prev;
       result.p = node;
     }
@@ -987,15 +979,14 @@ gl_linked_iterator_from_to (gl_list_t list,
     {
       /* n2 is the maximum, use n1 and n3.  */
       gl_list_node_t node;
-      size_t i;
 
       node = list->root.next;
-      for (i = n1; i > 0; i--)
+      for (size_t i = n1; i > 0; i--)
         node = node->next;
       result.p = node;
 
       node = &list->root;
-      for (i = n3; i > 0; i--)
+      for (size_t i = n3; i > 0; i--)
         node = node->prev;
       result.q = node;
     }
@@ -1003,13 +994,12 @@ gl_linked_iterator_from_to (gl_list_t list,
     {
       /* n3 is the maximum, use n1 and n2.  */
       gl_list_node_t node;
-      size_t i;
 
       node = list->root.next;
-      for (i = n1; i > 0; i--)
+      for (size_t i = n1; i > 0; i--)
         node = node->next;
       result.p = node;
-      for (i = n2; i > 0; i--)
+      for (size_t i = n2; i > 0; i--)
         node = node->next;
       result.q = node;
     }
@@ -1051,9 +1041,7 @@ static gl_list_node_t _GL_ATTRIBUTE_PURE
 gl_linked_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar,
                              const void *elt)
 {
-  gl_list_node_t node;
-
-  for (node = list->root.next; node != &list->root; node = node->next)
+  for (gl_list_node_t node = list->root.next; node != &list->root; node = node->next)
     {
       int cmp = compar (node->value, elt);
 
@@ -1188,9 +1176,7 @@ static gl_list_node_t
 gl_linked_sortedlist_nx_add (gl_list_t list, gl_listelement_compar_fn compar,
                              const void *elt)
 {
-  gl_list_node_t node;
-
-  for (node = list->root.next; node != &list->root; node = node->next)
+  for (gl_list_node_t node = list->root.next; node != &list->root; node = node->next)
     if (compar (node->value, elt) >= 0)
       return gl_linked_nx_add_before (list, node, elt);
   return gl_linked_nx_add_last (list, elt);
@@ -1200,9 +1186,7 @@ static bool
 gl_linked_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar,
                              const void *elt)
 {
-  gl_list_node_t node;
-
-  for (node = list->root.next; node != &list->root; node = node->next)
+  for (gl_list_node_t node = list->root.next; node != &list->root; node = node->next)
     {
       int cmp = compar (node->value, elt);
 
diff --git a/lib/gl_anyrbtree_list2.h b/lib/gl_anyrbtree_list2.h
index e1c8479761..4272606a5d 100644
--- a/lib/gl_anyrbtree_list2.h
+++ b/lib/gl_anyrbtree_list2.h
@@ -659,12 +659,8 @@ gl_tree_remove_node_from_tree (gl_list_t list, gl_list_node_t node)
             parent->right = child;
 
           /* Update branch_size fields of the parent nodes.  */
-          {
-            gl_list_node_t p;
-
-            for (p = parent; p != NULL; p = p->parent)
-              p->branch_size--;
-          }
+          for (gl_list_node_t p = parent; p != NULL; p = p->parent)
+            p->branch_size--;
 
           if (child == NULL && node->color == BLACK)
             rebalance_after_remove (list, child, parent);
@@ -691,12 +687,8 @@ gl_tree_remove_node_from_tree (gl_list_t list, gl_list_node_t node)
             parent->right = child;
 
           /* Update branch_size fields of the parent nodes.  */
-          {
-            gl_list_node_t p;
-
-            for (p = parent; p != NULL; p = p->parent)
-              p->branch_size--;
-          }
+          for (gl_list_node_t p = parent; p != NULL; p = p->parent)
+            p->branch_size--;
         }
     }
   else
@@ -735,12 +727,8 @@ gl_tree_remove_node_from_tree (gl_list_t list, gl_list_node_t node)
         }
 
       /* Update branch_size fields of the parent nodes.  */
-      {
-        gl_list_node_t p;
-
-        for (p = subst_parent; p != NULL; p = p->parent)
-          p->branch_size--;
-      }
+      for (gl_list_node_t p = subst_parent; p != NULL; p = p->parent)
+        p->branch_size--;
 
       /* Copy subst into node's position.
          (This is safer than to copy subst's value into node, keep node in
@@ -816,12 +804,8 @@ gl_tree_nx_add_first (gl_list_t list, const void *elt)
       new_node->parent = node;
 
       /* Update branch_size fields of the parent nodes.  */
-      {
-        gl_list_node_t p;
-
-        for (p = node; p != NULL; p = p->parent)
-          p->branch_size++;
-      }
+      for (gl_list_node_t p = node; p != NULL; p = p->parent)
+        p->branch_size++;
 
       /* Color and rebalance.  */
       rebalance_after_add (list, new_node, node);
@@ -882,12 +866,8 @@ gl_tree_nx_add_last (gl_list_t list, const void *elt)
       new_node->parent = node;
 
       /* Update branch_size fields of the parent nodes.  */
-      {
-        gl_list_node_t p;
-
-        for (p = node; p != NULL; p = p->parent)
-          p->branch_size++;
-      }
+      for (gl_list_node_t p = node; p != NULL; p = p->parent)
+        p->branch_size++;
 
       /* Color and rebalance.  */
       rebalance_after_add (list, new_node, node);
@@ -942,12 +922,8 @@ gl_tree_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
   new_node->parent = node;
 
   /* Update branch_size fields of the parent nodes.  */
-  {
-    gl_list_node_t p;
-
-    for (p = node; p != NULL; p = p->parent)
-      p->branch_size++;
-  }
+  for (gl_list_node_t p = node; p != NULL; p = p->parent)
+    p->branch_size++;
 
   /* Color and rebalance.  */
   rebalance_after_add (list, new_node, node);
@@ -1001,12 +977,8 @@ gl_tree_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
   new_node->parent = node;
 
   /* Update branch_size fields of the parent nodes.  */
-  {
-    gl_list_node_t p;
-
-    for (p = node; p != NULL; p = p->parent)
-      p->branch_size++;
-  }
+  for (gl_list_node_t p = node; p != NULL; p = p->parent)
+    p->branch_size++;
 
   /* Color and rebalance.  */
   rebalance_after_add (list, new_node, node);
diff --git a/lib/gl_anytree_list2.h b/lib/gl_anytree_list2.h
index 90a41dec4d..6f2d157f81 100644
--- a/lib/gl_anytree_list2.h
+++ b/lib/gl_anytree_list2.h
@@ -668,9 +668,7 @@ static gl_list_node_t _GL_ATTRIBUTE_PURE
 gl_tree_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar,
                            const void *elt)
 {
-  gl_list_node_t node;
-
-  for (node = list->root; node != NULL; )
+  for (gl_list_node_t node = list->root; node != NULL; )
     {
       int cmp = compar (node->value, elt);
 
@@ -711,14 +709,12 @@ gl_tree_sortedlist_search_from_to (gl_list_t list,
                                    size_t low, size_t high,
                                    const void *elt)
 {
-  gl_list_node_t node;
-
   if (!(low <= high
         && high <= (list->root != NULL ? list->root->branch_size : 0)))
     /* Invalid arguments.  */
     abort ();
 
-  for (node = list->root; node != NULL; )
+  for (gl_list_node_t node = list->root; node != NULL; )
     {
       size_t left_branch_size =
         (node->left != NULL ? node->left->branch_size : 0);
diff --git a/lib/gl_anytree_omap.h b/lib/gl_anytree_omap.h
index 2b2b870e44..9660d87b17 100644
--- a/lib/gl_anytree_omap.h
+++ b/lib/gl_anytree_omap.h
@@ -59,9 +59,8 @@ static bool
 gl_tree_search (gl_omap_t map, const void *key, const void **valuep)
 {
   gl_mapkey_compar_fn compar = map->base.compar_fn;
-  gl_omap_node_t node;
 
-  for (node = map->root; node != NULL; )
+  for (gl_omap_node_t node = map->root; node != NULL; )
     {
       int cmp = (compar != NULL
                  ? compar (node->key, key)
@@ -88,9 +87,7 @@ gl_tree_search_atleast (gl_omap_t map,
                         const void *threshold,
                         const void **keyp, const void **valuep)
 {
-  gl_omap_node_t node;
-
-  for (node = map->root; node != NULL; )
+  for (gl_omap_node_t node = map->root; node != NULL; )
     {
       if (! threshold_fn (node->key, threshold))
         node = node->right;
@@ -174,9 +171,8 @@ static bool
 gl_tree_getremove (gl_omap_t map, const void *key, const void **oldvaluep)
 {
   gl_mapkey_compar_fn compar = map->base.compar_fn;
-  gl_omap_node_t node;
 
-  for (node = map->root; node != NULL; )
+  for (gl_omap_node_t node = map->root; node != NULL; )
     {
       int cmp = (compar != NULL
                  ? compar (node->key, key)
diff --git a/lib/gl_anytree_oset.h b/lib/gl_anytree_oset.h
index f49d32e33f..d0717913d0 100644
--- a/lib/gl_anytree_oset.h
+++ b/lib/gl_anytree_oset.h
@@ -95,9 +95,8 @@ static bool
 gl_tree_search (gl_oset_t set, const void *elt)
 {
   gl_setelement_compar_fn compar = set->base.compar_fn;
-  gl_oset_node_t node;
 
-  for (node = set->root; node != NULL; )
+  for (gl_oset_node_t node = set->root; node != NULL; )
     {
       int cmp = (compar != NULL
                  ? compar (node->value, elt)
@@ -121,9 +120,7 @@ gl_tree_search_atleast (gl_oset_t set,
                         const void *threshold,
                         const void **eltp)
 {
-  gl_oset_node_t node;
-
-  for (node = set->root; node != NULL; )
+  for (gl_oset_node_t node = set->root; node != NULL; )
     {
       if (! threshold_fn (node->value, threshold))
         node = node->right;
@@ -154,9 +151,8 @@ static gl_oset_node_t
 gl_tree_search_node (gl_oset_t set, const void *elt)
 {
   gl_setelement_compar_fn compar = set->base.compar_fn;
-  gl_oset_node_t node;
 
-  for (node = set->root; node != NULL; )
+  for (gl_oset_node_t node = set->root; node != NULL; )
     {
       int cmp = (compar != NULL
                  ? compar (node->value, elt)
@@ -381,7 +377,6 @@ gl_tree_iterator_atleast (gl_oset_t set,
                           const void *threshold)
 {
   gl_oset_iterator_t result;
-  gl_oset_node_t node;
 
   result.vtable = set->base.vtable;
   result.set = set;
@@ -393,7 +388,7 @@ gl_tree_iterator_atleast (gl_oset_t set,
   result.count = 0;
 #endif
 
-  for (node = set->root; node != NULL; )
+  for (gl_oset_node_t node = set->root; node != NULL; )
     {
       if (! threshold_fn (node->value, threshold))
         node = node->right;
diff --git a/lib/gl_anytreehash_list1.h b/lib/gl_anytreehash_list1.h
index ccbb88aac5..9ec2109399 100644
--- a/lib/gl_anytreehash_list1.h
+++ b/lib/gl_anytreehash_list1.h
@@ -107,9 +107,10 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node)
       size_t hashcode = new_node->h.hashcode;
       const void *value = new_node->value;
       gl_listelement_equals_fn equals = list->base.equals_fn;
-      gl_hash_entry_t *entryp;
 
-      for (entryp = &list->table[bucket]; *entryp != NULL; entryp = &(*entryp)->hash_next)
+      for (gl_hash_entry_t *entryp = &list->table[bucket];
+           *entryp != NULL;
+           entryp = &(*entryp)->hash_next)
         {
           gl_hash_entry_t entry = *entryp;
 
@@ -194,9 +195,8 @@ remove_from_bucket (gl_list_t list, gl_list_node_t old_node)
       size_t hashcode = old_node->h.hashcode;
       const void *value = old_node->value;
       gl_listelement_equals_fn equals = list->base.equals_fn;
-      gl_hash_entry_t *entryp;
 
-      for (entryp = &list->table[bucket]; ; entryp = &(*entryp)->hash_next)
+      for (gl_hash_entry_t *entryp = &list->table[bucket]; ; entryp = &(*entryp)->hash_next)
         {
           gl_hash_entry_t entry = *entryp;
 
@@ -240,9 +240,7 @@ remove_from_bucket (gl_list_t list, gl_list_node_t old_node)
   else
     {
       /* If no duplicates are allowed, multiple nodes are not needed.  */
-      gl_hash_entry_t *entryp;
-
-      for (entryp = &list->table[bucket]; ; entryp = &(*entryp)->hash_next)
+      for (gl_hash_entry_t *entryp = &list->table[bucket]; ; entryp = &(*entryp)->hash_next)
         {
           if (*entryp == &old_node->h)
             {
diff --git a/lib/gl_anytreehash_list2.h b/lib/gl_anytreehash_list2.h
index 2b96a22f38..7915f411a1 100644
--- a/lib/gl_anytreehash_list2.h
+++ b/lib/gl_anytreehash_list2.h
@@ -32,11 +32,10 @@ gl_tree_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
        : (size_t)(uintptr_t) elt);
     size_t bucket = hashcode % list->table_size;
     gl_listelement_equals_fn equals = list->base.equals_fn;
-    gl_hash_entry_t entry;
 
     if (list->base.allow_duplicates)
       {
-        for (entry = list->table[bucket]; entry != NULL; entry = entry->hash_next)
+        for (gl_hash_entry_t entry = list->table[bucket]; entry != NULL; entry = entry->hash_next)
           if (entry->hashcode == hashcode)
             {
               if (((struct gl_multiple_nodes *) entry)->magic == MULTIPLE_NODES_MAGIC)
@@ -101,7 +100,7 @@ gl_tree_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
     else
       {
         /* If no duplicates are allowed, multiple nodes are not needed.  */
-        for (entry = list->table[bucket]; entry != NULL; entry = entry->hash_next)
+        for (gl_hash_entry_t entry = list->table[bucket]; entry != NULL; entry = entry->hash_next)
           if (entry->hashcode == hashcode)
             {
               gl_list_node_t node = (struct gl_list_node_impl *) entry;
@@ -146,9 +145,7 @@ gl_tree_list_free (gl_list_t list)
   if (list->base.allow_duplicates)
     {
       /* Free the ordered sets in the hash buckets.  */
-      size_t i;
-
-      for (i = list->table_size; i > 0; )
+      for (size_t i = list->table_size; i > 0; )
         {
           gl_hash_entry_t entry = list->table[--i];
 
diff --git a/lib/gl_array_list.c b/lib/gl_array_list.c
index 8592cc77c2..592f0862af 100644
--- a/lib/gl_array_list.c
+++ b/lib/gl_array_list.c
@@ -222,9 +222,7 @@ gl_array_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index,
       gl_listelement_equals_fn equals = list->base.equals_fn;
       if (equals != NULL)
         {
-          size_t i;
-
-          for (i = start_index;;)
+          for (size_t i = start_index;;)
             {
               if (equals (elt, list->elements[i]))
                 return i;
@@ -235,9 +233,7 @@ gl_array_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index,
         }
       else
         {
-          size_t i;
-
-          for (i = start_index;;)
+          for (size_t i = start_index;;)
             {
               if (elt == list->elements[i])
                 return i;
@@ -287,13 +283,12 @@ gl_array_nx_add_first (gl_list_t list, const void *elt)
 {
   size_t count = list->count;
   const void **elements;
-  size_t i;
 
   if (count == list->allocated)
     if (grow (list) < 0)
       return NULL;
   elements = list->elements;
-  for (i = count; i > 0; i--)
+  for (size_t i = count; i > 0; i--)
     elements[i] = elements[i - 1];
   elements[0] = elt;
   list->count = count + 1;
@@ -320,7 +315,6 @@ gl_array_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
   uintptr_t index = NODE_TO_INDEX (node);
   size_t position;
   const void **elements;
-  size_t i;
 
   if (!(index < count))
     /* Invalid argument.  */
@@ -330,7 +324,7 @@ gl_array_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
     if (grow (list) < 0)
       return NULL;
   elements = list->elements;
-  for (i = count; i > position; i--)
+  for (size_t i = count; i > position; i--)
     elements[i] = elements[i - 1];
   elements[position] = elt;
   list->count = count + 1;
@@ -344,7 +338,6 @@ gl_array_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
   uintptr_t index = NODE_TO_INDEX (node);
   size_t position;
   const void **elements;
-  size_t i;
 
   if (!(index < count))
     /* Invalid argument.  */
@@ -354,7 +347,7 @@ gl_array_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
     if (grow (list) < 0)
       return NULL;
   elements = list->elements;
-  for (i = count; i > position; i--)
+  for (size_t i = count; i > position; i--)
     elements[i] = elements[i - 1];
   elements[position] = elt;
   list->count = count + 1;
@@ -366,7 +359,6 @@ gl_array_nx_add_at (gl_list_t list, size_t position, const void *elt)
 {
   size_t count = list->count;
   const void **elements;
-  size_t i;
 
   if (!(position <= count))
     /* Invalid argument.  */
@@ -375,7 +367,7 @@ gl_array_nx_add_at (gl_list_t list, size_t position, const void *elt)
     if (grow (list) < 0)
       return NULL;
   elements = list->elements;
-  for (i = count; i > position; i--)
+  for (size_t i = count; i > position; i--)
     elements[i] = elements[i - 1];
   elements[position] = elt;
   list->count = count + 1;
@@ -389,7 +381,6 @@ gl_array_remove_node (gl_list_t list, gl_list_node_t node)
   uintptr_t index = NODE_TO_INDEX (node);
   size_t position;
   const void **elements;
-  size_t i;
 
   if (!(index < count))
     /* Invalid argument.  */
@@ -398,7 +389,7 @@ gl_array_remove_node (gl_list_t list, gl_list_node_t node)
   elements = list->elements;
   if (list->base.dispose_fn != NULL)
     list->base.dispose_fn (elements[position]);
-  for (i = position + 1; i < count; i++)
+  for (size_t i = position + 1; i < count; i++)
     elements[i - 1] = elements[i];
   list->count = count - 1;
   return true;
@@ -409,7 +400,6 @@ gl_array_remove_at (gl_list_t list, size_t position)
 {
   size_t count = list->count;
   const void **elements;
-  size_t i;
 
   if (!(position < count))
     /* Invalid argument.  */
@@ -417,7 +407,7 @@ gl_array_remove_at (gl_list_t list, size_t position)
   elements = list->elements;
   if (list->base.dispose_fn != NULL)
     list->base.dispose_fn (elements[position]);
-  for (i = position + 1; i < count; i++)
+  for (size_t i = position + 1; i < count; i++)
     elements[i - 1] = elements[i];
   list->count = count - 1;
   return true;
diff --git a/lib/gl_array_map.c b/lib/gl_array_map.c
index fcbc553097..35ac174b61 100644
--- a/lib/gl_array_map.c
+++ b/lib/gl_array_map.c
@@ -85,17 +85,13 @@ gl_array_indexof (gl_map_t map, const void *key)
       gl_mapkey_equals_fn equals = map->base.equals_fn;
       if (equals != NULL)
         {
-          size_t i;
-
-          for (i = 0; i < count; i++)
+          for (size_t i = 0; i < count; i++)
             if (equals (map->pairs[i].key, key))
               return i;
         }
       else
         {
-          size_t i;
-
-          for (i = 0; i < count; i++)
+          for (size_t i = 0; i < count; i++)
             if (map->pairs[i].key == key)
               return i;
         }
@@ -174,12 +170,11 @@ gl_array_remove_at (gl_map_t map, size_t position)
 {
   size_t count = map->count;
   struct pair *pairs;
-  size_t i;
 
   pairs = map->pairs;
   if (map->base.kdispose_fn != NULL)
     map->base.kdispose_fn (pairs[position].key);
-  for (i = position + 1; i < count; i++)
+  for (size_t i = position + 1; i < count; i++)
     pairs[i - 1] = pairs[i];
   map->count = count - 1;
 }
diff --git a/lib/gl_array_omap.c b/lib/gl_array_omap.c
index 1e1eb2854c..83cd007850 100644
--- a/lib/gl_array_omap.c
+++ b/lib/gl_array_omap.c
@@ -206,13 +206,12 @@ gl_array_nx_add_at (gl_omap_t map, size_t position,
 {
   size_t count = map->count;
   struct pair *pairs;
-  size_t i;
 
   if (count == map->allocated)
     if (grow (map) < 0)
       return -1;
   pairs = map->pairs;
-  for (i = count; i > position; i--)
+  for (size_t i = count; i > position; i--)
     pairs[i] = pairs[i - 1];
   pairs[position].key = key;
   pairs[position].value = value;
@@ -267,12 +266,11 @@ gl_array_remove_at (gl_omap_t map, size_t position)
 {
   size_t count = map->count;
   struct pair *pairs;
-  size_t i;
 
   pairs = map->pairs;
   if (map->base.kdispose_fn != NULL)
     map->base.kdispose_fn (pairs[position].key);
-  for (i = position + 1; i < count; i++)
+  for (size_t i = position + 1; i < count; i++)
     pairs[i - 1] = pairs[i];
   map->count = count - 1;
 }
diff --git a/lib/gl_array_oset.c b/lib/gl_array_oset.c
index e06eb49015..eeb8aede83 100644
--- a/lib/gl_array_oset.c
+++ b/lib/gl_array_oset.c
@@ -209,13 +209,12 @@ gl_array_nx_add_at (gl_oset_t set, size_t position, const void *elt)
 {
   size_t count = set->count;
   const void **elements;
-  size_t i;
 
   if (count == set->allocated)
     if (grow (set) < 0)
       return -1;
   elements = set->elements;
-  for (i = count; i > position; i--)
+  for (size_t i = count; i > position; i--)
     elements[i] = elements[i - 1];
   elements[position] = elt;
   set->count = count + 1;
@@ -229,12 +228,11 @@ gl_array_remove_at (gl_oset_t set, size_t position)
 {
   size_t count = set->count;
   const void **elements;
-  size_t i;
 
   elements = set->elements;
   if (set->base.dispose_fn != NULL)
     set->base.dispose_fn (elements[position]);
-  for (i = position + 1; i < count; i++)
+  for (size_t i = position + 1; i < count; i++)
     elements[i - 1] = elements[i];
   set->count = count - 1;
 }
@@ -368,9 +366,8 @@ gl_array_update (gl_oset_t set, const void *elt,
               /* Move the element from old_index to low.  */
               size_t new_index = low;
               const void **elements = set->elements;
-              size_t i;
 
-              for (i = old_index; i > new_index; i--)
+              for (size_t i = old_index; i > new_index; i--)
                 elements[i] = elements[i - 1];
               elements[new_index] = elt;
               return true;
@@ -384,9 +381,8 @@ gl_array_update (gl_oset_t set, const void *elt,
               if (new_index > old_index)
                 {
                   const void **elements = set->elements;
-                  size_t i;
 
-                  for (i = old_index; i < new_index; i++)
+                  for (size_t i = old_index; i < new_index; i++)
                     elements[i] = elements[i + 1];
                   elements[new_index] = elt;
                   return true;
diff --git a/lib/gl_array_set.c b/lib/gl_array_set.c
index c65861d938..d162623602 100644
--- a/lib/gl_array_set.c
+++ b/lib/gl_array_set.c
@@ -78,17 +78,13 @@ gl_array_search (gl_set_t set, const void *elt)
       const void **elements = set->elements;
       if (equals != NULL)
         {
-          size_t i;
-
-          for (i = 0; i < count; i++)
+          for (size_t i = 0; i < count; i++)
             if (equals (elements[i], elt))
               return true;
         }
       else
         {
-          size_t i;
-
-          for (i = 0; i < count; i++)
+          for (size_t i = 0; i < count; i++)
             if (elements[i] == elt)
               return true;
         }
@@ -145,11 +141,10 @@ gl_array_remove_at (gl_set_t set, size_t position)
 {
   size_t count = set->count;
   const void **elements = set->elements;
-  size_t i;
 
   if (set->base.dispose_fn != NULL)
     set->base.dispose_fn (elements[position]);
-  for (i = position + 1; i < count; i++)
+  for (size_t i = position + 1; i < count; i++)
     elements[i - 1] = elements[i];
   set->count = count - 1;
 }
@@ -166,9 +161,7 @@ gl_array_remove (gl_set_t set, const void *elt)
 
       if (equals != NULL)
         {
-          size_t i;
-
-          for (i = 0; i < count; i++)
+          for (size_t i = 0; i < count; i++)
             if (equals (elements[i], elt))
               {
                 gl_array_remove_at (set, i);
@@ -177,9 +170,7 @@ gl_array_remove (gl_set_t set, const void *elt)
         }
       else
         {
-          size_t i;
-
-          for (i = 0; i < count; i++)
+          for (size_t i = 0; i < count; i++)
             if (elements[i] == elt)
               {
                 gl_array_remove_at (set, i);
diff --git a/lib/gl_carray_list.c b/lib/gl_carray_list.c
index ae2e589466..ffcf0efcdd 100644
--- a/lib/gl_carray_list.c
+++ b/lib/gl_carray_list.c
@@ -396,7 +396,7 @@ gl_carray_nx_add_at (gl_list_t list, size_t position, const void *elt)
   if (position <= (count / 2))
     {
       /* Shift at most count/2 elements to the left.  */
-      size_t i2, i;
+      size_t i2;
 
       list->offset = (list->offset == 0 ? list->allocated : list->offset) - 1;
 
@@ -406,15 +406,15 @@ gl_carray_nx_add_at (gl_list_t list, size_t position, const void *elt)
           /* Here we must have list->offset > 0, hence list->allocated > 0.  */
           size_t i1 = list->allocated - 1;
           i2 -= list->allocated;
-          for (i = list->offset; i < i1; i++)
+          for (size_t i = list->offset; i < i1; i++)
             elements[i] = elements[i + 1];
           elements[i1] = elements[0];
-          for (i = 0; i < i2; i++)
+          for (size_t i = 0; i < i2; i++)
             elements[i] = elements[i + 1];
         }
       else
         {
-          for (i = list->offset; i < i2; i++)
+          for (size_t i = list->offset; i < i2; i++)
             elements[i] = elements[i + 1];
         }
       elements[i2] = elt;
@@ -422,7 +422,7 @@ gl_carray_nx_add_at (gl_list_t list, size_t position, const void *elt)
   else
     {
       /* Shift at most (count+1)/2 elements to the right.  */
-      size_t i1, i3, i;
+      size_t i1, i3;
 
       i1 = list->offset + position;
       i3 = list->offset + count;
@@ -430,7 +430,7 @@ gl_carray_nx_add_at (gl_list_t list, size_t position, const void *elt)
         {
           i1 -= list->allocated;
           i3 -= list->allocated;
-          for (i = i3; i > i1; i--)
+          for (size_t i = i3; i > i1; i--)
             elements[i] = elements[i - 1];
         }
       else if (i3 >= list->allocated)
@@ -438,15 +438,15 @@ gl_carray_nx_add_at (gl_list_t list, size_t position, const void *elt)
           /* Here we must have list->offset > 0, hence list->allocated > 0.  */
           size_t i2 = list->allocated - 1;
           i3 -= list->allocated;
-          for (i = i3; i > 0; i--)
+          for (size_t i = i3; i > 0; i--)
             elements[i] = elements[i - 1];
           elements[0] = elements[i2];
-          for (i = i2; i > i1; i--)
+          for (size_t i = i2; i > i1; i--)
             elements[i] = elements[i - 1];
         }
       else
         {
-          for (i = i3; i > i1; i--)
+          for (size_t i = i3; i > i1; i--)
             elements[i] = elements[i - 1];
         }
       elements[i1] = elt;
@@ -493,7 +493,7 @@ gl_carray_remove_at (gl_list_t list, size_t position)
   if (position <= ((count - 1) / 2))
     {
       /* Shift at most (count-1)/2 elements to the right.  */
-      size_t i0, i2, i;
+      size_t i0, i2;
 
       i0 = list->offset;
       i2 = list->offset + position;
@@ -504,17 +504,17 @@ gl_carray_remove_at (gl_list_t list, size_t position)
           i2 -= list->allocated;
           if (list->base.dispose_fn != NULL)
             list->base.dispose_fn (elements[i2]);
-          for (i = i2; i > 0; i--)
+          for (size_t i = i2; i > 0; i--)
             elements[i] = elements[i - 1];
           elements[0] = elements[i1];
-          for (i = i1; i > i0; i--)
+          for (size_t i = i1; i > i0; i--)
             elements[i] = elements[i - 1];
         }
       else
         {
           if (list->base.dispose_fn != NULL)
             list->base.dispose_fn (elements[i2]);
-          for (i = i2; i > i0; i--)
+          for (size_t i = i2; i > i0; i--)
             elements[i] = elements[i - 1];
         }
 
@@ -524,7 +524,7 @@ gl_carray_remove_at (gl_list_t list, size_t position)
   else
     {
       /* Shift at most count/2 elements to the left.  */
-      size_t i1, i3, i;
+      size_t i1, i3;
 
       i1 = list->offset + position;
       i3 = list->offset + count - 1;
@@ -534,7 +534,7 @@ gl_carray_remove_at (gl_list_t list, size_t position)
           i3 -= list->allocated;
           if (list->base.dispose_fn != NULL)
             list->base.dispose_fn (elements[i1]);
-          for (i = i1; i < i3; i++)
+          for (size_t i = i1; i < i3; i++)
             elements[i] = elements[i + 1];
         }
       else if (i3 >= list->allocated)
@@ -544,17 +544,17 @@ gl_carray_remove_at (gl_list_t list, size_t position)
           i3 -= list->allocated;
           if (list->base.dispose_fn != NULL)
             list->base.dispose_fn (elements[i1]);
-          for (i = i1; i < i2; i++)
+          for (size_t i = i1; i < i2; i++)
             elements[i] = elements[i + 1];
           elements[i2] = elements[0];
-          for (i = 0; i < i3; i++)
+          for (size_t i = 0; i < i3; i++)
             elements[i] = elements[i + 1];
         }
       else
         {
           if (list->base.dispose_fn != NULL)
             list->base.dispose_fn (elements[i1]);
-          for (i = i1; i < i3; i++)
+          for (size_t i = i1; i < i3; i++)
             elements[i] = elements[i + 1];
         }
     }
@@ -605,19 +605,16 @@ gl_carray_list_free (gl_list_t list)
                   /* Here we must have list->offset > 0, hence
                      list->allocated > 0.  */
                   size_t i2 = list->allocated - 1;
-                  size_t i;
 
                   i3 -= list->allocated;
-                  for (i = i1; i <= i2; i++)
+                  for (size_t i = i1; i <= i2; i++)
                     dispose (elements[i]);
-                  for (i = 0; i <= i3; i++)
+                  for (size_t i = 0; i <= i3; i++)
                     dispose (elements[i]);
                 }
               else
                 {
-                  size_t i;
-
-                  for (i = i1; i <= i3; i++)
+                  for (size_t i = i1; i <= i3; i++)
                     dispose (elements[i]);
                 }
             }
diff --git a/lib/gl_hash_map.c b/lib/gl_hash_map.c
index e3cdd9c365..4b4beab3bd 100644
--- a/lib/gl_hash_map.c
+++ b/lib/gl_hash_map.c
@@ -105,9 +105,7 @@ gl_hash_search (gl_map_t map, const void *key, const void **valuep)
   gl_mapkey_equals_fn equals = map->base.equals_fn;
 
   /* Look for a match in the hash bucket.  */
-  gl_list_node_t node;
-
-  for (node = (gl_list_node_t) map->table[bucket];
+  for (gl_list_node_t node = (gl_list_node_t) map->table[bucket];
        node != NULL;
        node = (gl_list_node_t) node->h.hash_next)
     if (node->h.hashcode == hashcode
@@ -133,22 +131,18 @@ gl_hash_nx_getput (gl_map_t map, const void *key, const void *value,
   gl_mapkey_equals_fn equals = map->base.equals_fn;
 
   /* Look for a match in the hash bucket.  */
-  {
-    gl_list_node_t node;
-
-    for (node = (gl_list_node_t) map->table[bucket];
-         node != NULL;
-         node = (gl_list_node_t) node->h.hash_next)
-      if (node->h.hashcode == hashcode
-          && (equals != NULL
-              ? equals (key, node->key)
-              : key == node->key))
-        {
-          *oldvaluep = node->value;
-          node->value = value;
-          return 0;
-        }
-  }
+  for (gl_list_node_t node = (gl_list_node_t) map->table[bucket];
+       node != NULL;
+       node = (gl_list_node_t) node->h.hash_next)
+    if (node->h.hashcode == hashcode
+        && (equals != NULL
+            ? equals (key, node->key)
+            : key == node->key))
+      {
+        *oldvaluep = node->value;
+        node->value = value;
+        return 0;
+      }
 
   /* Allocate a new node.  */
   gl_list_node_t node =
@@ -184,9 +178,7 @@ gl_hash_getremove (gl_map_t map, const void *key, const void **oldvaluep)
   gl_mapkey_equals_fn equals = map->base.equals_fn;
 
   /* Look for the first match in the hash bucket.  */
-  gl_list_node_t *nodep;
-
-  for (nodep = (gl_list_node_t *) &map->table[bucket];
+  for (gl_list_node_t *nodep = (gl_list_node_t *) &map->table[bucket];
        *nodep != NULL;
        nodep = (gl_list_node_t *) &(*nodep)->h.hash_next)
     {
@@ -222,9 +214,8 @@ gl_hash_free (gl_map_t map)
       gl_mapkey_dispose_fn kdispose = map->base.kdispose_fn;
       gl_mapvalue_dispose_fn vdispose = map->base.vdispose_fn;
       struct gl_hash_entry **table = map->table;
-      size_t i;
 
-      for (i = map->table_size; i > 0; )
+      for (size_t i = map->table_size; i > 0; )
         {
           gl_hash_entry_t node = table[--i];
 
diff --git a/lib/gl_hash_set.c b/lib/gl_hash_set.c
index 1713df8c7c..9b1512ae2f 100644
--- a/lib/gl_hash_set.c
+++ b/lib/gl_hash_set.c
@@ -102,9 +102,7 @@ gl_hash_search (gl_set_t set, const void *elt)
   gl_setelement_equals_fn equals = set->base.equals_fn;
 
   /* Look for a match in the hash bucket.  */
-  gl_list_node_t node;
-
-  for (node = (gl_list_node_t) set->table[bucket];
+  for (gl_list_node_t node = (gl_list_node_t) set->table[bucket];
        node != NULL;
        node = (gl_list_node_t) node->h.hash_next)
     if (node->h.hashcode == hashcode
@@ -126,18 +124,14 @@ gl_hash_nx_add (gl_set_t set, const void *elt)
   gl_setelement_equals_fn equals = set->base.equals_fn;
 
   /* Look for a match in the hash bucket.  */
-  {
-    gl_list_node_t node;
-
-    for (node = (gl_list_node_t) set->table[bucket];
-         node != NULL;
-         node = (gl_list_node_t) node->h.hash_next)
-      if (node->h.hashcode == hashcode
-          && (equals != NULL
-              ? equals (elt, node->value)
-              : elt == node->value))
-        return 0;
-  }
+  for (gl_list_node_t node = (gl_list_node_t) set->table[bucket];
+       node != NULL;
+       node = (gl_list_node_t) node->h.hash_next)
+    if (node->h.hashcode == hashcode
+        && (equals != NULL
+            ? equals (elt, node->value)
+            : elt == node->value))
+      return 0;
 
   /* Allocate a new node.  */
   gl_list_node_t node =
@@ -172,9 +166,7 @@ gl_hash_remove (gl_set_t set, const void *elt)
   gl_setelement_equals_fn equals = set->base.equals_fn;
 
   /* Look for the first match in the hash bucket.  */
-  gl_list_node_t *nodep;
-
-  for (nodep = (gl_list_node_t *) &set->table[bucket];
+  for (gl_list_node_t *nodep = (gl_list_node_t *) &set->table[bucket];
        *nodep != NULL;
        nodep = (gl_list_node_t *) &(*nodep)->h.hash_next)
     {
@@ -207,9 +199,8 @@ gl_hash_free (gl_set_t set)
     {
       gl_setelement_dispose_fn dispose = set->base.dispose_fn;
       struct gl_hash_entry **table = set->table;
-      size_t i;
 
-      for (i = set->table_size; i > 0; )
+      for (size_t i = set->table_size; i > 0; )
         {
           gl_hash_entry_t node = table[--i];
 
diff --git a/lib/gl_linkedhash_list.c b/lib/gl_linkedhash_list.c
index c6199b2229..42526dc7d9 100644
--- a/lib/gl_linkedhash_list.c
+++ b/lib/gl_linkedhash_list.c
@@ -57,9 +57,8 @@ static void
 remove_from_bucket (gl_list_t list, gl_list_node_t node)
 {
   size_t bucket = node->h.hashcode % list->table_size;
-  gl_hash_entry_t *p;
 
-  for (p = &list->table[bucket]; ; p = &(*p)->hash_next)
+  for (gl_hash_entry_t *p = &list->table[bucket]; ; p = &(*p)->hash_next)
     {
       if (*p == &node->h)
         {
diff --git a/lib/gl_linkedhash_map.c b/lib/gl_linkedhash_map.c
index 20061dff96..67deecb2b7 100644
--- a/lib/gl_linkedhash_map.c
+++ b/lib/gl_linkedhash_map.c
@@ -130,9 +130,7 @@ gl_linkedhash_search (gl_map_t map, const void *key, const void **valuep)
   gl_mapkey_equals_fn equals = map->base.equals_fn;
 
   /* Look for a match in the hash bucket.  */
-  gl_list_node_t node;
-
-  for (node = (gl_list_node_t) map->table[bucket];
+  for (gl_list_node_t node = (gl_list_node_t) map->table[bucket];
        node != NULL;
        node = (gl_list_node_t) node->h.hash_next)
     if (node->h.hashcode == hashcode
@@ -158,22 +156,18 @@ gl_linkedhash_nx_getput (gl_map_t map, const void *key, const void *value,
   gl_mapkey_equals_fn equals = map->base.equals_fn;
 
   /* Look for a match in the hash bucket.  */
-  {
-    gl_list_node_t node;
-
-    for (node = (gl_list_node_t) map->table[bucket];
-         node != NULL;
-         node = (gl_list_node_t) node->h.hash_next)
-      if (node->h.hashcode == hashcode
-          && (equals != NULL
-              ? equals (key, node->key)
-              : key == node->key))
-        {
-          *oldvaluep = node->value;
-          node->value = value;
-          return 0;
-        }
-  }
+  for (gl_list_node_t node = (gl_list_node_t) map->table[bucket];
+       node != NULL;
+       node = (gl_list_node_t) node->h.hash_next)
+    if (node->h.hashcode == hashcode
+        && (equals != NULL
+            ? equals (key, node->key)
+            : key == node->key))
+      {
+        *oldvaluep = node->value;
+        node->value = value;
+        return 0;
+      }
 
   /* Allocate a new node.  */
   gl_list_node_t node =
@@ -213,9 +207,7 @@ gl_linkedhash_getremove (gl_map_t map, const void *key, const void **oldvaluep)
   gl_mapkey_equals_fn equals = map->base.equals_fn;
 
   /* Look for the first match in the hash bucket.  */
-  gl_list_node_t *nodep;
-
-  for (nodep = (gl_list_node_t *) &map->table[bucket];
+  for (gl_list_node_t *nodep = (gl_list_node_t *) &map->table[bucket];
        *nodep != NULL;
        nodep = (gl_list_node_t *) &(*nodep)->h.hash_next)
     {
@@ -255,9 +247,8 @@ gl_linkedhash_free (gl_map_t map)
 {
   gl_mapkey_dispose_fn kdispose = map->base.kdispose_fn;
   gl_mapvalue_dispose_fn vdispose = map->base.vdispose_fn;
-  gl_list_node_t node;
 
-  for (node = map->root.next; node != &map->root; )
+  for (gl_list_node_t node = map->root.next; node != &map->root; )
     {
       gl_list_node_t next = node->next;
       if (vdispose != NULL)
diff --git a/lib/gl_linkedhash_set.c b/lib/gl_linkedhash_set.c
index 1f685a87da..2fe2edda36 100644
--- a/lib/gl_linkedhash_set.c
+++ b/lib/gl_linkedhash_set.c
@@ -127,9 +127,7 @@ gl_linkedhash_search (gl_set_t set, const void *elt)
   gl_setelement_equals_fn equals = set->base.equals_fn;
 
   /* Look for a match in the hash bucket.  */
-  gl_list_node_t node;
-
-  for (node = (gl_list_node_t) set->table[bucket];
+  for (gl_list_node_t node = (gl_list_node_t) set->table[bucket];
        node != NULL;
        node = (gl_list_node_t) node->h.hash_next)
     if (node->h.hashcode == hashcode
@@ -151,18 +149,14 @@ gl_linkedhash_nx_add (gl_set_t set, const void *elt)
   gl_setelement_equals_fn equals = set->base.equals_fn;
 
   /* Look for a match in the hash bucket.  */
-  {
-    gl_list_node_t node;
-
-    for (node = (gl_list_node_t) set->table[bucket];
-         node != NULL;
-         node = (gl_list_node_t) node->h.hash_next)
-      if (node->h.hashcode == hashcode
-          && (equals != NULL
-              ? equals (elt, node->value)
-              : elt == node->value))
-        return 0;
-  }
+  for (gl_list_node_t node = (gl_list_node_t) set->table[bucket];
+       node != NULL;
+       node = (gl_list_node_t) node->h.hash_next)
+    if (node->h.hashcode == hashcode
+        && (equals != NULL
+            ? equals (elt, node->value)
+            : elt == node->value))
+      return 0;
 
   /* Allocate a new node.  */
   gl_list_node_t node =
@@ -201,9 +195,7 @@ gl_linkedhash_remove (gl_set_t set, const void *elt)
   gl_setelement_equals_fn equals = set->base.equals_fn;
 
   /* Look for the first match in the hash bucket.  */
-  gl_list_node_t *nodep;
-
-  for (nodep = (gl_list_node_t *) &set->table[bucket];
+  for (gl_list_node_t *nodep = (gl_list_node_t *) &set->table[bucket];
        *nodep != NULL;
        nodep = (gl_list_node_t *) &(*nodep)->h.hash_next)
     {
@@ -240,9 +232,8 @@ static void
 gl_linkedhash_free (gl_set_t set)
 {
   gl_setelement_dispose_fn dispose = set->base.dispose_fn;
-  gl_list_node_t node;
 
-  for (node = set->root.next; node != &set->root; )
+  for (gl_list_node_t node = set->root.next; node != &set->root; )
     {
       gl_list_node_t next = node->next;
       if (dispose != NULL)
diff --git a/lib/group-member.c b/lib/group-member.c
index a26eebe37d..34938a1b05 100644
--- a/lib/group-member.c
+++ b/lib/group-member.c
@@ -73,14 +73,13 @@ get_group_info (struct group_info *gi)
 int
 group_member (gid_t gid)
 {
-  int i;
   int found;
   struct group_info gi;
   int n_groups = get_group_info (&gi);
 
   /* Search through the list looking for GID. */
   found = 0;
-  for (i = 0; i < n_groups; i++)
+  for (int i = 0; i < n_groups; i++)
     {
       if (gid == gi.group[i])
         {
@@ -99,9 +98,7 @@ group_member (gid_t gid)
 int
 main (int argc, char **argv)
 {
-  int i;
-
-  for (i = 1; i < argc; i++)
+  for (int i = 1; i < argc; i++)
     {
       gid_t gid;
 
diff --git a/lib/hash.c b/lib/hash.c
index 4d07c8b2b0..61c7b5889d 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -163,10 +163,11 @@ hash_get_n_entries (const Hash_table *table)
 size_t
 hash_get_max_bucket_length (const Hash_table *table)
 {
-  struct hash_entry const *bucket;
   size_t max_bucket_length = 0;
 
-  for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+  for (struct hash_entry const *bucket = table->bucket;
+       bucket < table->bucket_limit;
+       bucket++)
     {
       if (bucket->data)
         {
@@ -187,11 +188,12 @@ hash_get_max_bucket_length (const Hash_table *table)
 bool
 hash_table_ok (const Hash_table *table)
 {
-  struct hash_entry const *bucket;
   size_t n_buckets_used = 0;
   size_t n_entries = 0;
 
-  for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+  for (struct hash_entry const *bucket = table->bucket;
+       bucket < table->bucket_limit;
+       bucket++)
     {
       if (bucket->data)
         {
@@ -245,12 +247,11 @@ void *
 hash_lookup (const Hash_table *table, const void *entry)
 {
   struct hash_entry const *bucket = safe_hasher (table, entry);
-  struct hash_entry const *cursor;
 
   if (bucket->data == NULL)
     return NULL;
 
-  for (cursor = bucket; cursor; cursor = cursor->next)
+  for (struct hash_entry const *cursor = bucket; cursor; cursor = cursor->next)
     if (entry == cursor->data || table->comparator (entry, cursor->data))
       return cursor->data;
 
@@ -262,12 +263,10 @@ hash_lookup (const Hash_table *table, const void *entry)
 void *
 hash_get_first (const Hash_table *table)
 {
-  struct hash_entry const *bucket;
-
   if (table->n_entries == 0)
     return NULL;
 
-  for (bucket = table->bucket; ; bucket++)
+  for (struct hash_entry const *bucket = table->bucket; ; bucket++)
     if (! (bucket < table->bucket_limit))
       abort ();
     else if (bucket->data)
@@ -304,14 +303,14 @@ hash_get_entries (const Hash_table *table, void **buffer,
                   size_t buffer_size)
 {
   size_t counter = 0;
-  struct hash_entry const *bucket;
-  struct hash_entry const *cursor;
 
-  for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+  for (struct hash_entry const *bucket = table->bucket;
+       bucket < table->bucket_limit;
+       bucket++)
     {
       if (bucket->data)
         {
-          for (cursor = bucket; cursor; cursor = cursor->next)
+          for (struct hash_entry const *cursor = bucket; cursor; cursor = cursor->next)
             {
               if (counter >= buffer_size)
                 return counter;
@@ -328,14 +327,14 @@ hash_do_for_each (const Hash_table *table, Hash_processor processor,
                   void *processor_data)
 {
   size_t counter = 0;
-  struct hash_entry const *bucket;
-  struct hash_entry const *cursor;
 
-  for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+  for (struct hash_entry const *bucket = table->bucket;
+       bucket < table->bucket_limit;
+       bucket++)
     {
       if (bucket->data)
         {
-          for (cursor = bucket; cursor; cursor = cursor->next)
+          for (struct hash_entry const *cursor = bucket; cursor; cursor = cursor->next)
             {
               if (! processor (cursor->data, processor_data))
                 return counter;
@@ -494,17 +493,16 @@ hash_initialize (size_t candidate, const Hash_tuning *tuning,
 void
 hash_clear (Hash_table *table)
 {
-  struct hash_entry *bucket;
-
-  for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+  for (struct hash_entry *bucket = table->bucket;
+       bucket < table->bucket_limit;
+       bucket++)
     {
       if (bucket->data)
         {
-          struct hash_entry *cursor;
           struct hash_entry *next;
 
           /* Free the bucket overflow.  */
-          for (cursor = bucket->next; cursor; cursor = next)
+          for (struct hash_entry *cursor = bucket->next; cursor; cursor = next)
             {
               if (table->data_freer)
                 table->data_freer (cursor->data);
@@ -532,19 +530,19 @@ hash_clear (Hash_table *table)
 void
 hash_free (Hash_table *table)
 {
-  struct hash_entry *bucket;
-  struct hash_entry *cursor;
   struct hash_entry *next;
   int err = errno;
 
   /* Call the user data_freer function.  */
   if (table->data_freer && table->n_entries)
     {
-      for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+      for (struct hash_entry *bucket = table->bucket;
+           bucket < table->bucket_limit;
+           bucket++)
         {
           if (bucket->data)
             {
-              for (cursor = bucket; cursor; cursor = cursor->next)
+              for (struct hash_entry *cursor = bucket; cursor; cursor = cursor->next)
                 table->data_freer (cursor->data);
             }
         }
@@ -557,9 +555,11 @@ hash_free (Hash_table *table)
 #else
 
   /* Free all bucket overflowed entries.  */
-  for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+  for (struct hash_entry *bucket = table->bucket;
+       bucket < table->bucket_limit;
+       bucket++)
     {
-      for (cursor = bucket->next; cursor; cursor = next)
+      for (struct hash_entry *cursor = bucket->next; cursor; cursor = next)
         {
           next = cursor->next;
           free (cursor);
@@ -567,7 +567,7 @@ hash_free (Hash_table *table)
     }
 
   /* Also reclaim the internal list of previously freed entries.  */
-  for (cursor = table->free_entry_list; cursor; cursor = next)
+  for (struct hash_entry *cursor = table->free_entry_list; cursor; cursor = next)
     {
       next = cursor->next;
       free (cursor);
@@ -631,7 +631,6 @@ find_entry (Hash_table *table, const void *entry,
             struct hash_entry **bucket_head, bool delete)
 {
   struct hash_entry *bucket = safe_hasher (table, entry);
-  struct hash_entry *cursor;
 
   *bucket_head = bucket;
 
@@ -665,7 +664,7 @@ find_entry (Hash_table *table, const void *entry,
     }
 
   /* Scan the bucket overflow.  */
-  for (cursor = bucket; cursor->next; cursor = cursor->next)
+  for (struct hash_entry *cursor = bucket; cursor->next; cursor = cursor->next)
     {
       if (entry == cursor->next->data
           || table->comparator (entry, cursor->next->data))
@@ -699,10 +698,9 @@ find_entry (Hash_table *table, const void *entry,
 static bool
 transfer_entries (Hash_table *dst, Hash_table *src, bool safe)
 {
-  struct hash_entry *bucket;
-  struct hash_entry *cursor;
   struct hash_entry *next;
-  for (bucket = src->bucket; bucket < src->bucket_limit; bucket++)
+
+  for (struct hash_entry *bucket = src->bucket; bucket < src->bucket_limit; bucket++)
     if (bucket->data)
       {
         void *data;
@@ -714,7 +712,7 @@ transfer_entries (Hash_table *dst, Hash_table *src, bool safe)
            bucket head, but moving overflow entries first may create
            free entries that can be recycled by the time we finally
            get to the bucket head.  */
-        for (cursor = bucket->next; cursor; cursor = next)
+        for (struct hash_entry *cursor = bucket->next; cursor; cursor = next)
           {
             data = cursor->data;
             new_bucket = safe_hasher (dst, data);
@@ -1018,12 +1016,10 @@ hash_print (const Hash_table *table)
 
   for ( ; bucket < table->bucket_limit; bucket++)
     {
-      struct hash_entry *cursor;
-
       if (bucket)
         printf ("%lu:\n", (unsigned long int) (bucket - table->bucket));
 
-      for (cursor = bucket; cursor; cursor = cursor->next)
+      for (struct hash_entry *cursor = bucket; cursor; cursor = cursor->next)
         {
           char const *s = cursor->data;
           /* FIXME */
diff --git a/lib/hashcode-mem.c b/lib/hashcode-mem.c
index cf086b0b16..3b3b316394 100644
--- a/lib/hashcode-mem.c
+++ b/lib/hashcode-mem.c
@@ -34,9 +34,8 @@ hash_pjw_bare (const void *x, size_t n)
 {
   const unsigned char *s = x;
   size_t h = 0;
-  unsigned i;
 
-  for (i = 0; i < n; i++)
+  for (unsigned int i = 0; i < n; i++)
     h = s[i] + ((h << 9) | (h >> (SIZE_BITS - 9)));
 
   return h;
diff --git a/lib/hashcode-string2.c b/lib/hashcode-string2.c
index 5a44762723..567192590a 100644
--- a/lib/hashcode-string2.c
+++ b/lib/hashcode-string2.c
@@ -31,10 +31,9 @@
 size_t
 hash_pjw (const void *x, size_t tablesize)
 {
-  const char *s;
   size_t h = 0;
 
-  for (s = x; *s; s++)
+  for (const char *s = x; *s; s++)
     h = *s + ((h << 9) | (h >> (SIZE_BITS - 9)));
 
   return h % tablesize;
diff --git a/lib/human.c b/lib/human.c
index 96e7aadab4..f065547d2f 100644
--- a/lib/human.c
+++ b/lib/human.c
@@ -362,9 +362,8 @@ human_readable (uintmax_t n, char *buf, int opts,
     {
       if (exponent < 0)
         {
-          uintmax_t power;
           exponent = 0;
-          for (power = 1; power < to_block_size; power *= base)
+          for (uintmax_t power = 1; power < to_block_size; power *= base)
             if (++exponent == exponent_max)
               break;
         }
diff --git a/lib/i-ring.c b/lib/i-ring.c
index 2accac0740..afac835bcf 100644
--- a/lib/i-ring.c
+++ b/lib/i-ring.c
@@ -24,11 +24,10 @@
 void
 i_ring_init (I_ring *ir, int default_val)
 {
-  int i;
   ir->ir_empty = true;
   ir->ir_front = 0;
   ir->ir_back = 0;
-  for (i = 0; i < I_RING_SIZE; i++)
+  for (int i = 0; i < I_RING_SIZE; i++)
     ir->ir_data[i] = default_val;
   ir->ir_default_val = default_val;
 }
diff --git a/lib/idcache.c b/lib/idcache.c
index 5907838be4..04bf23d484 100644
--- a/lib/idcache.c
+++ b/lib/idcache.c
@@ -68,10 +68,9 @@ static struct userid *nogroup_alist;
 char *
 getuser (uid_t uid)
 {
-  struct userid *tail;
   struct userid *match = NULL;
 
-  for (tail = user_alist; tail; tail = tail->next)
+  for (struct userid *tail = user_alist; tail; tail = tail->next)
     {
       if (tail->id.u == uid)
         {
@@ -104,15 +103,14 @@ getuser (uid_t uid)
 uid_t *
 getuidbyname (const char *user)
 {
-  struct userid *tail;
   struct passwd *pwent;
 
-  for (tail = user_alist; tail; tail = tail->next)
+  for (struct userid *tail = user_alist; tail; tail = tail->next)
     /* Avoid a function call for the most common case.  */
     if (*tail->name == *user && streq (tail->name, user))
       return &tail->id.u;
 
-  for (tail = nouser_alist; tail; tail = tail->next)
+  for (struct userid *tail = nouser_alist; tail; tail = tail->next)
     /* Avoid a function call for the most common case.  */
     if (*tail->name == *user && streq (tail->name, user))
       return NULL;
@@ -128,7 +126,8 @@ getuidbyname (const char *user)
     }
 #endif
 
-  tail = xmalloc (FLEXSIZEOF (struct userid, name, strlen (user) + 1));
+  struct userid *tail =
+    xmalloc (FLEXSIZEOF (struct userid, name, strlen (user) + 1));
   strcpy (tail->name, user);
 
   /* Add to the head of the list, so most recently used is first.  */
@@ -150,10 +149,9 @@ getuidbyname (const char *user)
 char *
 getgroup (gid_t gid)
 {
-  struct userid *tail;
   struct userid *match = NULL;
 
-  for (tail = group_alist; tail; tail = tail->next)
+  for (struct userid *tail = group_alist; tail; tail = tail->next)
     {
       if (tail->id.g == gid)
         {
@@ -186,15 +184,14 @@ getgroup (gid_t gid)
 gid_t *
 getgidbyname (const char *group)
 {
-  struct userid *tail;
   struct group *grent;
 
-  for (tail = group_alist; tail; tail = tail->next)
+  for (struct userid *tail = group_alist; tail; tail = tail->next)
     /* Avoid a function call for the most common case.  */
     if (*tail->name == *group && streq (tail->name, group))
       return &tail->id.g;
 
-  for (tail = nogroup_alist; tail; tail = tail->next)
+  for (struct userid *tail = nogroup_alist; tail; tail = tail->next)
     /* Avoid a function call for the most common case.  */
     if (*tail->name == *group && streq (tail->name, group))
       return NULL;
@@ -210,7 +207,8 @@ getgidbyname (const char *group)
     }
 #endif
 
-  tail = xmalloc (FLEXSIZEOF (struct userid, name, strlen (group) + 1));
+  struct userid *tail =
+    xmalloc (FLEXSIZEOF (struct userid, name, strlen (group) + 1));
   strcpy (tail->name, group);
 
   /* Add to the head of the list, so most recently used is first.  */
diff --git a/lib/inet_ntop.c b/lib/inet_ntop.c
index df3d9512ad..45300c91ee 100644
--- a/lib/inet_ntop.c
+++ b/lib/inet_ntop.c
@@ -164,7 +164,6 @@ inet_ntop6 (const unsigned char *src, char *dst, socklen_t size)
     int base, len;
   } best, cur;
   unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];
-  int i;
 
   /*
    * Preprocess:
@@ -172,13 +171,13 @@ inet_ntop6 (const unsigned char *src, char *dst, socklen_t size)
    *      Find the longest run of 0x00's in src[] for :: shorthanding.
    */
   memset (words, '\0', sizeof words);
-  for (i = 0; i < NS_IN6ADDRSZ; i += 2)
+  for (int i = 0; i < NS_IN6ADDRSZ; i += 2)
     words[i / 2] = (src[i] << 8) | src[i + 1];
   best.base = -1;
   cur.base = -1;
   IF_LINT(best.len = 0);
   IF_LINT(cur.len = 0);
-  for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
+  for (int i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
     {
       if (words[i] == 0)
         {
@@ -209,7 +208,7 @@ inet_ntop6 (const unsigned char *src, char *dst, socklen_t size)
    * Format the result.
    */
   tp = tmp;
-  for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
+  for (int i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
     {
       /* Are we inside the best run of 0x00's? */
       if (best.base != -1 && i >= best.base && i < (best.base + best.len))
diff --git a/lib/inet_pton.c b/lib/inet_pton.c
index 74d55c43b7..e096eb341b 100644
--- a/lib/inet_pton.c
+++ b/lib/inet_pton.c
@@ -246,11 +246,10 @@ inet_pton6 (const char *restrict src, unsigned char *restrict dst)
        * overlapping regions, we'll do the shift by hand.
        */
       const int n = tp - colonp;
-      int i;
 
       if (tp == endp)
         return (0);
-      for (i = 1; i <= n; i++)
+      for (int i = 1; i <= n; i++)
         {
           endp[-i] = colonp[n - i];
           colonp[n - i] = 0;
diff --git a/lib/ino-map.c b/lib/ino-map.c
index 5691f649f3..71c6057497 100644
--- a/lib/ino-map.c
+++ b/lib/ino-map.c
@@ -59,9 +59,8 @@ ino_hash (void const *x, size_t table_size)
      This avoids loss of info, without applying % to the wider type,
      which could be quite slow on some systems.  */
   size_t h = ino;
-  unsigned int i;
   unsigned int n_words = sizeof ino / sizeof h + (sizeof ino % sizeof h != 0);
-  for (i = 1; i < n_words; i++)
+  for (unsigned int i = 1; i < n_words; i++)
     h ^= ino >> CHAR_BIT * sizeof h * i;
 
   return h % table_size;
diff --git a/lib/integer_length.c b/lib/integer_length.c
index c6efb42678..9d64ab510e 100644
--- a/lib/integer_length.c
+++ b/lib/integer_length.c
@@ -142,9 +142,7 @@ integer_length (unsigned int x)
       {
         /* Naive loop.
            Works for any value of NBITS.  */
-        int j;
-
-        for (j = NBITS - 1; j >= 0; j--)
+        for (int j = NBITS - 1; j >= 0; j--)
           if (x & (1U << j))
             return j + 1;
         return 0;
diff --git a/lib/integer_length_l.c b/lib/integer_length_l.c
index 5cc710a570..519c84523f 100644
--- a/lib/integer_length_l.c
+++ b/lib/integer_length_l.c
@@ -84,9 +84,7 @@ FUNC (TYPE x)
   if (sizeof (TYPE) > 2 * sizeof (unsigned int))
     {
       /* Generic loop.  */
-      size_t i;
-
-      for (i = (sizeof (TYPE) - 1) / sizeof (unsigned int); i >= 2; i--)
+      for (size_t i = (sizeof (TYPE) - 1) / sizeof (unsigned int); i >= 2; i--)
         {
           unsigned int y = x >> (i * sizeof (unsigned int) * CHAR_BIT);
           if (y != 0)
diff --git a/lib/javacomp.c b/lib/javacomp.c
index 1c01a8d077..e56878e8df 100644
--- a/lib/javacomp.c
+++ b/lib/javacomp.c
@@ -188,7 +188,6 @@ compile_using_envjavac (const char *javac,
   char *command;
   const char *argv[4];
   int exitstatus;
-  unsigned int i;
   char *p;
 
   command_length = strlen (javac);
@@ -198,7 +197,7 @@ compile_using_envjavac (const char *javac,
     command_length += 3;
   if (directory != NULL)
     command_length += 4 + shell_quote_length (directory);
-  for (i = 0; i < java_sources_count; i++)
+  for (unsigned int i = 0; i < java_sources_count; i++)
     command_length += 1 + shell_quote_length (java_sources[i]);
   command_length += 1;
 
@@ -224,7 +223,7 @@ compile_using_envjavac (const char *javac,
       p += 4;
       p = shell_quote_copy (p, directory);
     }
-  for (i = 0; i < java_sources_count; i++)
+  for (unsigned int i = 0; i < java_sources_count; i++)
     {
       *p++ = ' ';
       p = shell_quote_copy (p, java_sources[i]);
@@ -268,7 +267,6 @@ compile_using_javac (const char * const *java_sources,
   const char **argv;
   const char **argp;
   int exitstatus;
-  unsigned int i;
 
   argc =
     1 + (nowarn_option != NULL ? 1 : 0) + (source_option ? 2 : 0)
@@ -299,7 +297,7 @@ compile_using_javac (const char * const *java_sources,
       *argp++ = "-d";
       *argp++ = directory;
     }
-  for (i = 0; i < java_sources_count; i++)
+  for (unsigned int i = 0; i < java_sources_count; i++)
     *argp++ = java_sources[i];
   *argp = NULL;
   /* Ensure argv length was correctly calculated.  */
diff --git a/lib/javaexec.c b/lib/javaexec.c
index 7e637f3533..fd20d8f9b5 100644
--- a/lib/javaexec.c
+++ b/lib/javaexec.c
@@ -94,7 +94,6 @@ execute_java_class (const char *class_name,
       char *old_classpath;
       const char **argv =
         (const char **) xmalloca ((1 + nargs + 1) * sizeof (const char *));
-      unsigned int i;
 
       /* Set CLASSPATH.  */
       old_classpath =
@@ -102,7 +101,7 @@ execute_java_class (const char *class_name,
                        verbose);
 
       argv[0] = exe_pathname;
-      for (i = 0; i <= nargs; i++)
+      for (unsigned int i = 0; i <= nargs; i++)
         argv[1 + i] = args[i];
 
       if (verbose)
@@ -134,7 +133,6 @@ execute_java_class (const char *class_name,
         unsigned int command_length;
         char *command;
         const char *argv[4];
-        const char * const *arg;
         char *p;
 
         /* Set CLASSPATH.  */
@@ -144,7 +142,7 @@ execute_java_class (const char *class_name,
 
         command_length = strlen (java);
         command_length += 1 + shell_quote_length (class_name);
-        for (arg = args; *arg != NULL; arg++)
+        for (const char * const *arg = args; *arg != NULL; arg++)
           command_length += 1 + shell_quote_length (*arg);
         command_length += 1;
 
@@ -156,7 +154,7 @@ execute_java_class (const char *class_name,
         p += strlen (java);
         *p++ = ' ';
         p = shell_quote_copy (p, class_name);
-        for (arg = args; *arg != NULL; arg++)
+        for (const char * const *arg = args; *arg != NULL; arg++)
           {
             *p++ = ' ';
             p = shell_quote_copy (p, *arg);
@@ -217,7 +215,6 @@ execute_java_class (const char *class_name,
         char *old_classpath;
         const char **argv =
           (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
-        unsigned int i;
 
         /* Set CLASSPATH.  We don't use the "-classpath ..." option because
            in JDK 1.1.x its argument should also contain the JDK's classes.zip,
@@ -228,7 +225,7 @@ execute_java_class (const char *class_name,
 
         argv[0] = "java";
         argv[1] = class_name;
-        for (i = 0; i <= nargs; i++)
+        for (unsigned int i = 0; i <= nargs; i++)
           argv[2 + i] = args[i];
 
         if (verbose)
@@ -273,7 +270,6 @@ execute_java_class (const char *class_name,
         char *old_classpath;
         const char **argv =
           (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
-        unsigned int i;
 
         /* Set CLASSPATH.  We don't use the "-classpath ..." option because
            in JDK 1.1.x its argument should also contain the JDK's classes.zip,
@@ -284,7 +280,7 @@ execute_java_class (const char *class_name,
 
         argv[0] = "jre";
         argv[1] = class_name;
-        for (i = 0; i <= nargs; i++)
+        for (unsigned int i = 0; i <= nargs; i++)
           argv[2 + i] = args[i];
 
         if (verbose)
diff --git a/lib/kwset.c b/lib/kwset.c
index f90b01dd34..c4be94edf5 100644
--- a/lib/kwset.c
+++ b/lib/kwset.c
@@ -480,8 +480,7 @@ kwsprep (kwset_t kwset)
 
           /* Update the shifts at each node in the current node's chain
              of fails back to the root.  */
-          struct trie *fail;
-          for (fail = curr->fail; fail; fail = fail->fail)
+          for (struct trie *fail = curr->fail; fail; fail = fail->fail)
             {
               /* If the current node has some outgoing edge that the fail
                  doesn't, then the shift at the fail should be no larger
diff --git a/lib/ldexpl.c b/lib/ldexpl.c
index caf4a3f928..a166842f04 100644
--- a/lib/ldexpl.c
+++ b/lib/ldexpl.c
@@ -46,8 +46,7 @@ int
 main (void)
 {
   long double x;
-  int y;
-  for (y = 0; y < 29; y++)
+  for (int y = 0; y < 29; y++)
     printf ("%5d %.16Lg %.16Lg\n", y, ldexpl (0.8L, y), ldexpl (0.8L, -y) * ldexpl (0.8L, y));
 }
 #endif
diff --git a/lib/localeinfo.c b/lib/localeinfo.c
index ff38e525ea..5123168527 100644
--- a/lib/localeinfo.c
+++ b/lib/localeinfo.c
@@ -140,7 +140,6 @@ static_assert (1 + 1 + sizeof lonesome_lower / sizeof *lonesome_lower
 int
 case_folded_counterparts (wint_t c, char32_t folded[CASE_FOLDED_BUFSIZE])
 {
-  int i;
   int n = 0;
   wint_t uc = c32toupper (c);
   wint_t lc = c32tolower (uc);
@@ -148,7 +147,7 @@ case_folded_counterparts (wint_t c, char32_t folded[CASE_FOLDED_BUFSIZE])
     folded[n++] = uc;
   if (lc != uc && lc != c && c32toupper (lc) == uc)
     folded[n++] = lc;
-  for (i = 0; i < sizeof lonesome_lower / sizeof *lonesome_lower; i++)
+  for (int i = 0; i < sizeof lonesome_lower / sizeof *lonesome_lower; i++)
     {
       wint_t li = lonesome_lower[i];
       if (li != lc && li != uc && li != c && c32toupper (li) == uc)
diff --git a/lib/localename-unsafe.c b/lib/localename-unsafe.c
index 08db8585cd..3163a5c713 100644
--- a/lib/localename-unsafe.c
+++ b/lib/localename-unsafe.c
@@ -1430,8 +1430,7 @@ gl_locale_name_canonicalize (char *name)
 
   /* Step 3: Convert new-style dash to Unix underscore. */
   {
-    char *p;
-    for (p = name; *p != '\0'; p++)
+    for (char *p = name; *p != '\0'; p++)
       if (*p == '-')
         *p = '_';
   }
@@ -1454,9 +1453,7 @@ gl_locale_name_canonicalize (char *name)
 {
   /* FIXME: This is probably incomplete: it does not handle "zh-Hans" and
      "zh-Hant".  */
-  char *p;
-
-  for (p = name; *p != '\0'; p++)
+  for (char *p = name; *p != '\0'; p++)
     if (*p == '-')
       {
         *p = '_';
diff --git a/lib/login_tty.c b/lib/login_tty.c
index 98fd649668..f7926171f6 100644
--- a/lib/login_tty.c
+++ b/lib/login_tty.c
@@ -27,8 +27,6 @@
 int
 login_tty (int slave_fd)
 {
-  int i;
-
   /* Create a new session.  */
   setsid ();
 
@@ -42,7 +40,7 @@ login_tty (int slave_fd)
             a controlling terminal.
        We assume condition 1, try to ensure condition 2, and then open() it.
    */
-  for (i = 0; i < 3; i++)
+  for (int i = 0; i < 3; i++)
     if (i != slave_fd)
       close (i);
 #ifdef TIOCSCTTY
@@ -65,7 +63,7 @@ login_tty (int slave_fd)
 
   /* Assign fd to the standard input, standard output, and standard error of
      the current process.  */
-  for (i = 0; i < 3; i++)
+  for (int i = 0; i < 3; i++)
     if (slave_fd != i)
       if (dup2 (slave_fd, i) < 0)
         return -1;
diff --git a/lib/mbscasestr.c b/lib/mbscasestr.c
index 843229666f..6a1b59f608 100644
--- a/lib/mbscasestr.c
+++ b/lib/mbscasestr.c
@@ -108,13 +108,13 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle,
           forall 0 <= x < table[i]: rhaystack[x..x+m-1] != needle[0..m-1].
      table[0] remains uninitialized.  */
   {
-    size_t i, j;
+    size_t j;
 
     /* i = 1: Nothing to verify for x = 0.  */
     table[1] = 1;
     j = 0;
 
-    for (i = 2; i < m; i++)
+    for (size_t i = 2; i < m; i++)
       {
         /* Here: j = i-1 - table[i-1].
            The inequality needle[x..i-1] != needle[0..i-1-x] is known to hold
diff --git a/lib/mbsstr.c b/lib/mbsstr.c
index 8e8eb73d55..fe9cf655c5 100644
--- a/lib/mbsstr.c
+++ b/lib/mbsstr.c
@@ -100,13 +100,13 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle,
           forall 0 <= x < table[i]: rhaystack[x..x+m-1] != needle[0..m-1].
      table[0] remains uninitialized.  */
   {
-    size_t i, j;
+    size_t j;
 
     /* i = 1: Nothing to verify for x = 0.  */
     table[1] = 1;
     j = 0;
 
-    for (i = 2; i < m; i++)
+    for (size_t i = 2; i < m; i++)
       {
         /* Here: j = i-1 - table[i-1].
            The inequality needle[x..i-1] != needle[0..i-1-x] is known to hold
diff --git a/lib/md2.c b/lib/md2.c
index bb8361cf4c..799c421fed 100644
--- a/lib/md2.c
+++ b/lib/md2.c
@@ -58,11 +58,11 @@ md2_read_ctx (const struct md2_ctx *ctx, void *resbuf)
 void *
 md2_finish_ctx (struct md2_ctx *ctx, void *resbuf)
 {
-  unsigned long i, k;
+  unsigned long k;
 
   /* pad the message */
   k = 16 - ctx->curlen;
-  for (i = ctx->curlen; i < 16; i++)
+  for (unsigned long i = ctx->curlen; i < 16; i++)
     {
       ctx->buf[i] = (unsigned char) k;
     }
@@ -146,11 +146,10 @@ static const unsigned char PI_SUBST[256] = {
 static void
 md2_update_chksum (struct md2_ctx *ctx)
 {
-  int j;
   unsigned char L;
 
   L = ctx->chksum[15];
-  for (j = 0; j < 16; j++)
+  for (int j = 0; j < 16; j++)
     {
       /* caution, the RFC says its "C[j] = S[M[i*16+j] xor L]" but the
          reference source code [and test vectors] say otherwise. */
@@ -161,11 +160,10 @@ md2_update_chksum (struct md2_ctx *ctx)
 static void
 md2_compress (struct md2_ctx *ctx)
 {
-  size_t j, k;
   unsigned char t;
 
   /* copy block */
-  for (j = 0; j < 16; j++)
+  for (size_t j = 0; j < 16; j++)
     {
       ctx->X[16 + j] = ctx->buf[j];
       ctx->X[32 + j] = ctx->X[j] ^ ctx->X[16 + j];
@@ -174,9 +172,9 @@ md2_compress (struct md2_ctx *ctx)
   t = (unsigned char) 0;
 
   /* do 18 rounds */
-  for (j = 0; j < 18; j++)
+  for (size_t j = 0; j < 18; j++)
     {
-      for (k = 0; k < 48; k++)
+      for (size_t k = 0; k < 48; k++)
         {
           t = (ctx->X[k] ^= PI_SUBST[(int) (t & 255)]);
         }
diff --git a/lib/md4.c b/lib/md4.c
index 2135fdfb67..391f8ec0ad 100644
--- a/lib/md4.c
+++ b/lib/md4.c
@@ -230,8 +230,7 @@ md4_process_block (const void *buffer, size_t len, struct md4_ctx *ctx)
      the loop.  */
   while (words < endp)
     {
-      int t;
-      for (t = 0; t < 16; t++)
+      for (int t = 0; t < 16; t++)
         {
           x[t] = SWAP (*words);
           words++;
diff --git a/lib/mem-hash-map.c b/lib/mem-hash-map.c
index 23fc80fa89..81540e0567 100644
--- a/lib/mem-hash-map.c
+++ b/lib/mem-hash-map.c
@@ -208,14 +208,13 @@ resize (hash_table *htab)
 {
   size_t old_size = htab->size;
   hash_entry *table = htab->table;
-  size_t idx;
 
   htab->size = next_prime (htab->size * 2);
   htab->filled = 0;
   htab->first = NULL;
   htab->table = XCALLOC (1 + htab->size, hash_entry);
 
-  for (idx = 1; idx <= old_size; ++idx)
+  for (size_t idx = 1; idx <= old_size; ++idx)
     if (table[idx].used)
       insert_entry_2 (htab, table[idx].key, table[idx].keylen,
                       table[idx].used,
diff --git a/lib/memcasecmp.c b/lib/memcasecmp.c
index 8ee5cc3aef..783aa37377 100644
--- a/lib/memcasecmp.c
+++ b/lib/memcasecmp.c
@@ -31,10 +31,9 @@
 int
 memcasecmp (const void *vs1, const void *vs2, size_t n)
 {
-  size_t i;
   char const *s1 = vs1;
   char const *s2 = vs2;
-  for (i = 0; i < n; i++)
+  for (size_t i = 0; i < n; i++)
     {
       unsigned char u1 = s1[i];
       unsigned char u2 = s2[i];
diff --git a/lib/memchr.c b/lib/memchr.c
index ef0d15f7bf..c1fe496462 100644
--- a/lib/memchr.c
+++ b/lib/memchr.c
@@ -97,15 +97,11 @@ __memchr (void const *s, int c_in, size_t n)
       repeated_one |= repeated_one << 31 << 1;
       repeated_c |= repeated_c << 31 << 1;
       if (8 < sizeof (longword))
-        {
-          size_t i;
-
-          for (i = 64; i < sizeof (longword) * 8; i *= 2)
-            {
-              repeated_one |= repeated_one << i;
-              repeated_c |= repeated_c << i;
-            }
-        }
+        for (size_t i = 64; i < sizeof (longword) * 8; i *= 2)
+          {
+            repeated_one |= repeated_one << i;
+            repeated_c |= repeated_c << i;
+          }
     }
 
   /* Instead of the traditional loop which tests each byte, we will test a
diff --git a/lib/memchr2.c b/lib/memchr2.c
index 7493823fd4..c6e7f4e9dc 100644
--- a/lib/memchr2.c
+++ b/lib/memchr2.c
@@ -89,16 +89,12 @@ memchr2 (void const *s, int c1_in, int c2_in, size_t n)
       repeated_c1 |= repeated_c1 << 31 << 1;
       repeated_c2 |= repeated_c2 << 31 << 1;
       if (8 < sizeof (longword))
-        {
-          size_t i;
-
-          for (i = 64; i < sizeof (longword) * 8; i *= 2)
-            {
-              repeated_one |= repeated_one << i;
-              repeated_c1 |= repeated_c1 << i;
-              repeated_c2 |= repeated_c2 << i;
-            }
-        }
+        for (size_t i = 64; i < sizeof (longword) * 8; i *= 2)
+          {
+            repeated_one |= repeated_one << i;
+            repeated_c1 |= repeated_c1 << i;
+            repeated_c2 |= repeated_c2 << i;
+          }
     }
 
   /* Instead of the traditional loop which tests each byte, we will test a
diff --git a/lib/memrchr.c b/lib/memrchr.c
index b143fb0a3a..0c4022caff 100644
--- a/lib/memrchr.c
+++ b/lib/memrchr.c
@@ -84,15 +84,11 @@ __memrchr (void const *s, int c_in, size_t n)
       repeated_one |= repeated_one << 31 << 1;
       repeated_c |= repeated_c << 31 << 1;
       if (8 < sizeof (longword))
-        {
-          size_t i;
-
-          for (i = 64; i < sizeof (longword) * 8; i *= 2)
-            {
-              repeated_one |= repeated_one << i;
-              repeated_c |= repeated_c << i;
-            }
-        }
+        for (size_t i = 64; i < sizeof (longword) * 8; i *= 2)
+          {
+            repeated_one |= repeated_one << i;
+            repeated_c |= repeated_c << i;
+          }
     }
 
   /* Instead of the traditional loop which tests each byte, we will test a
diff --git a/lib/mgetgroups.c b/lib/mgetgroups.c
index fbe20003b5..44da49a93f 100644
--- a/lib/mgetgroups.c
+++ b/lib/mgetgroups.c
@@ -181,10 +181,9 @@ mgetgroups (char const *username, gid_t gid, gid_t **groups)
   if (1 < ng)
     {
       gid_t first = *g;
-      gid_t *next;
       gid_t *groups_end = g + ng;
 
-      for (next = g + 1; next < groups_end; next++)
+      for (gid_t *next = g + 1; next < groups_end; next++)
         {
           if (*next == first || *next == *g)
             ng--;
diff --git a/lib/mktime.c b/lib/mktime.c
index 4218fca69b..90d2002f27 100644
--- a/lib/mktime.c
+++ b/lib/mktime.c
@@ -468,11 +468,9 @@ __mktime_internal (struct tm *tp, bool local, mktime_offset_t *offset)
       int year_seconds_bound = 366 * 24 * 60 * 60 + 1;
       int delta_bound = year_seconds_bound + stride;
 
-      int delta, direction;
-
       /* Search in both directions, closest first.  */
-      for (delta = stride; delta < delta_bound; delta += stride)
-	for (direction = -1; direction <= 1; direction += 2)
+      for (int delta = stride; delta < delta_bound; delta += stride)
+	for (int direction = -1; direction <= 1; direction += 2)
 	  {
 	    long_int ot;
 	    if (! ckd_add (&ot, t, delta * direction))
diff --git a/lib/modechange.c b/lib/modechange.c
index 6bbe1064d8..17a3eecb5b 100644
--- a/lib/modechange.c
+++ b/lib/modechange.c
@@ -136,10 +136,10 @@ mode_compile (char const *mode_string)
   /* The array of mode-change directives to be returned.  */
   struct mode_change *mc;
   size_t used = 0;
-  char const *p;
 
   if ('0' <= *mode_string && *mode_string < '8')
     {
+      char const *p;
       unsigned int octal_mode = 0;
       mode_t mode;
       mode_t mentioned;
@@ -166,13 +166,14 @@ mode_compile (char const *mode_string)
   /* Allocate enough space to hold the result.  */
   {
     size_t needed = 1;
-    for (p = mode_string; *p; p++)
+    for (char const *p = mode_string; *p; p++)
       needed += (*p == '=' || *p == '+' || *p == '-');
     mc = xnmalloc (needed, sizeof *mc);
   }
 
   /* One loop iteration for each
      '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+'.  */
+  char const *p;
   for (p = mode_string; ; p++)
     {
       /* Which bits in the mode are operated on.  */
diff --git a/lib/mountlist.c b/lib/mountlist.c
index 1a1e7fbf78..963dc7b6f1 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -425,9 +425,9 @@ dev_from_mount_options (char const *mount_options)
 static void
 unescape_tab (char *str)
 {
-  size_t i, j = 0;
+  size_t j = 0;
   size_t len = strlen (str) + 1;
-  for (i = 0; i < len; i++)
+  for (size_t i = 0; i < len; i++)
     {
       if (str[i] == '\\' && (i + 4 < len)
           && str[i + 1] >= '0' && str[i + 1] <= '3'
@@ -729,9 +729,7 @@ read_file_system_list (bool need_fs_type)
       if (fs_stat_dev (dev, &fi) >= 0)
         {
           /* Note: fi.dev == dev. */
-          struct rootdir_entry *re;
-
-          for (re = rootdir_list; re; re = re->next)
+          for (struct rootdir_entry *re = rootdir_list; re; re = re->next)
             if (re->dev == fi.dev && re->ino == fi.root)
               break;
 
@@ -764,7 +762,7 @@ read_file_system_list (bool need_fs_type)
 
 #if defined MOUNTED_GETFSSTAT   /* (obsolete) Apple Darwin 1.3 */
   {
-    int numsys, counter;
+    int numsys;
     size_t bufsize;
     struct statfs *stats;
 
@@ -784,7 +782,7 @@ read_file_system_list (bool need_fs_type)
         return NULL;
       }
 
-    for (counter = 0; counter < numsys; counter++)
+    for (int counter = 0; counter < numsys; counter++)
       {
         me = xmalloc (sizeof *me);
         me->me_devname = xstrdup (stats[counter].f_mntfromname);
@@ -1105,9 +1103,8 @@ read_file_system_list (bool need_fs_type)
        if ASCII 'A' + i is an available drive.  See:
        <https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getlogicaldrives>.  */
     DWORD value = GetLogicalDrives ();
-    unsigned int i;
 
-    for (i = 0; i < 26; ++i)
+    for (unsigned int i = 0; i < 26; ++i)
       {
         if (value & (1U << i))
           {
diff --git a/lib/mpsort.c b/lib/mpsort.c
index 8c1088ac06..76b7598600 100644
--- a/lib/mpsort.c
+++ b/lib/mpsort.c
@@ -104,7 +104,6 @@ mpsort_with_tmp (void const **restrict base, size_t n,
     {
       size_t n1 = n / 2;
       size_t n2 = n - n1;
-      size_t i;
       size_t t = 0;
       size_t tlim = n1;
       size_t b = n1;
@@ -122,7 +121,7 @@ mpsort_with_tmp (void const **restrict base, size_t n,
       tt = tmp[t];
       bb = base[b];
 
-      for (i = 0; ; )
+      for (size_t i = 0; ; )
         if (cmp (tt, bb) <= 0)
           {
             base[i++] = tt;
diff --git a/lib/newlocale.c b/lib/newlocale.c
index 7dfa0a9a42..407c54ab96 100644
--- a/lib/newlocale.c
+++ b/lib/newlocale.c
@@ -123,9 +123,8 @@ newlocale (int category_mask, const char *name, locale_t base)
     }
 # endif
 
-  int i;
   int err;
-  for (i = 0; i < 6; i++)
+  for (int i = 0; i < 6; i++)
     {
       int log2_lcmask = gl_index_to_log2_lcmask (i);
 
@@ -213,13 +212,33 @@ newlocale (int category_mask, const char *name, locale_t base)
 # endif
             }
         }
+
+      if (0)
+        {
+         fail_with_err:
+          while (--i >= 0)
+            {
+# if HAVE_WINDOWS_LOCALE_T
+              if (!(i == gl_log2_lcmask_to_index (gl_log2_lc_mask (LC_MESSAGES))
+                    || result->category[i].is_c_locale))
+                /* Documentation:
+                   <https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/free-locale>  */
+                _free_locale (result->category[i].system_locale);
+# endif
+              free (result->category[i].name);
+            }
+          if (base == NULL)
+            free (result);
+          errno = err;
+          return NULL;
+        }
     }
 
   /* Success.  */
   if (base != NULL)
     {
       /* Copy the modified entries from RESULT to BASE.  */
-      for (i = 0; i < 6; i++)
+      for (int i = 0; i < 6; i++)
         {
           int log2_lcmask = gl_index_to_log2_lcmask (i);
           if ((category_mask & (1 << log2_lcmask)) != 0)
@@ -240,23 +259,6 @@ newlocale (int category_mask, const char *name, locale_t base)
     }
   else
     return result;
-
- fail_with_err:
-  while (--i >= 0)
-    {
-# if HAVE_WINDOWS_LOCALE_T
-      if (!(i == gl_log2_lcmask_to_index (gl_log2_lc_mask (LC_MESSAGES))
-            || result->category[i].is_c_locale))
-        /* Documentation:
-           <https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/free-locale>  */
-        _free_locale (result->category[i].system_locale);
-# endif
-      free (result->category[i].name);
-    }
-  if (base == NULL)
-    free (result);
-  errno = err;
-  return NULL;
 }
 
 #endif
diff --git a/lib/nproc.c b/lib/nproc.c
index 9404be1d38..1cccfc5606 100644
--- a/lib/nproc.c
+++ b/lib/nproc.c
@@ -89,10 +89,8 @@ num_processors_via_affinity_mask (void)
         /* glibc >= 2.6 has the CPU_COUNT macro.  */
         count = CPU_COUNT (&set);
 # else
-        size_t i;
-
         count = 0;
-        for (i = 0; i < CPU_SETSIZE; i++)
+        for (size_t i = 0; i < CPU_SETSIZE; i++)
           if (CPU_ISSET (i, &set))
             count++;
 # endif
@@ -112,9 +110,7 @@ num_processors_via_affinity_mask (void)
         if (pthread_getaffinity_np (pthread_self (), cpuset_size (set), set)
             == 0)
           {
-            cpuid_t i;
-
-            for (i = 0;; i++)
+            for (cpuid_t i = 0;; i++)
               {
                 int ret = cpuset_isset (i, set);
                 if (ret < 0)
@@ -180,10 +176,8 @@ num_processors_via_affinity_mask (void)
         /* glibc >= 2.6 has the CPU_COUNT macro.  */
         count = CPU_COUNT (&set);
 # else
-        size_t i;
-
         count = 0;
-        for (i = 0; i < CPU_SETSIZE; i++)
+        for (size_t i = 0; i < CPU_SETSIZE; i++)
           if (CPU_ISSET (i, &set))
             count++;
 # endif
@@ -202,9 +196,7 @@ num_processors_via_affinity_mask (void)
 
         if (sched_getaffinity_np (getpid (), cpuset_size (set), set) == 0)
           {
-            cpuid_t i;
-
-            for (i = 0;; i++)
+            for (cpuid_t i = 0;; i++)
               {
                 int ret = cpuset_isset (i, set);
                 if (ret < 0)
diff --git a/lib/obstack.c b/lib/obstack.c
index 8c4a5d55ab..fed3f6f711 100644
--- a/lib/obstack.c
+++ b/lib/obstack.c
@@ -315,10 +315,9 @@ strong_alias (_obstack_free, obstack_free)
 _OBSTACK_INDEX_T
 _obstack_memory_used (struct obstack *h)
 {
-  struct _obstack_chunk *lp;
   _OBSTACK_INDEX_T nbytes = 0;
 
-  for (lp = h->chunk; lp != NULL; lp = lp->prev)
+  for (struct _obstack_chunk *lp = h->chunk; lp != NULL; lp = lp->prev)
     {
       nbytes += lp->limit - (char *) lp;
     }
diff --git a/lib/os2-spawn.c b/lib/os2-spawn.c
index c532c07078..97a13aebf5 100644
--- a/lib/os2-spawn.c
+++ b/lib/os2-spawn.c
@@ -102,7 +102,6 @@ prepare_spawn (const char * const *argv, char **mem_to_free)
 {
   size_t argc;
   const char **new_argv;
-  size_t i;
 
   /* Count number of arguments.  */
   for (argc = 0; argv[argc] != NULL; argc++)
@@ -120,7 +119,7 @@ prepare_spawn (const char * const *argv, char **mem_to_free)
 
   /* Put quoted arguments into the new argument vector.  */
   size_t needed_size = 0;
-  for (i = 0; i < argc; i++)
+  for (size_t i = 0; i < argc; i++)
     {
       const char *string = argv[i];
       const char *quoted_string = (string[0] == '\0' ? "\"\"" : string);
@@ -144,7 +143,7 @@ prepare_spawn (const char * const *argv, char **mem_to_free)
     }
   *mem_to_free = mem;
 
-  for (i = 0; i < argc; i++)
+  for (size_t i = 0; i < argc; i++)
     {
       const char *string = argv[i];
 
diff --git a/lib/pipe-filter-ii.c b/lib/pipe-filter-ii.c
index c58c62765b..c4fda29fef 100644
--- a/lib/pipe-filter-ii.c
+++ b/lib/pipe-filter-ii.c
@@ -120,13 +120,12 @@ WaitForMultipleObjects (DWORD nCount, const HANDLE *pHandles, BOOL bWaitAll,
   PSEMRECORD psr;
   ULONG ulUser;
   ULONG rc = (ULONG) -1;
-  DWORD i;
 
   psr = malloc (sizeof (*psr) * nCount);
   if (!psr)
     goto exit_return;
 
-  for (i = 0; i < nCount; ++i)
+  for (DWORD i = 0; i < nCount; ++i)
     {
       psr[i].hsemCur = (HSEM) pHandles[i]->hevDone;
       psr[i].ulUser  = WAIT_OBJECT_0 + i;
diff --git a/lib/pipe-safer.c b/lib/pipe-safer.c
index c6eb8f7c2f..e23407c51e 100644
--- a/lib/pipe-safer.c
+++ b/lib/pipe-safer.c
@@ -32,8 +32,7 @@ pipe_safer (int fd[2])
 {
   if (pipe (fd) == 0)
     {
-      int i;
-      for (i = 0; i < 2; i++)
+      for (int i = 0; i < 2; i++)
         {
           fd[i] = fd_safer (fd[i]);
           if (fd[i] < 0)
diff --git a/lib/pipe2-safer.c b/lib/pipe2-safer.c
index 5c9591087d..89ae3ff6f5 100644
--- a/lib/pipe2-safer.c
+++ b/lib/pipe2-safer.c
@@ -33,8 +33,7 @@ pipe2_safer (int fd[2], int flags)
   /* This is a generalization of the pipe_safer implementation.  */
   if (pipe2 (fd, flags) == 0)
     {
-      int i;
-      for (i = 0; i < 2; i++)
+      for (int i = 0; i < 2; i++)
         {
           fd[i] = fd_safer_flag (fd[i], flags);
           if (fd[i] < 0)
diff --git a/lib/poll.c b/lib/poll.c
index c261ba1dd1..0794ad0d6f 100644
--- a/lib/poll.c
+++ b/lib/poll.c
@@ -167,7 +167,7 @@ typedef DWORD (WINAPI *PNtQueryInformationFile)
 static int
 windows_compute_revents (HANDLE h, int *p_sought)
 {
-  int i, ret, happened;
+  int ret, happened;
   INPUT_RECORD *irbuffer;
   DWORD avail, nbuffer;
   BOOL bRet;
@@ -240,7 +240,7 @@ windows_compute_revents (HANDLE h, int *p_sought)
           if (!bRet || avail == 0)
             return POLLHUP;
 
-          for (i = 0; i < avail; i++)
+          for (int i = 0; i < avail; i++)
             if (irbuffer[i].EventType == KEY_EVENT)
               return *p_sought;
           return 0;
@@ -415,7 +415,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
   FD_ZERO (&rfds);
   FD_ZERO (&wfds);
   FD_ZERO (&efds);
-  for (i = 0; i < nfd; i++)
+  for (int i = 0; i < nfd; i++)
     {
       if (pfd[i].fd < 0)
         continue;
@@ -446,7 +446,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
 
   /* establish results */
   rc = 0;
-  for (i = 0; i < nfd; i++)
+  for (int i = 0; i < nfd; i++)
     {
       pfd[i].revents = (pfd[i].fd < 0
                         ? 0
@@ -466,7 +466,6 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
   BOOL poll_again;
   MSG msg;
   int rc = 0;
-  nfds_t i;
 
   if (nfd > INT_MAX || timeout < -1)
     {
@@ -485,7 +484,7 @@ restart:
   FD_ZERO (&xfds);
 
   /* Classify socket handles and create fd sets. */
-  for (i = 0; i < nfd; i++)
+  for (nfds_t i = 0; i < nfd; i++)
     {
       int sought = pfd[i].events;
       pfd[i].revents = 0;
@@ -576,7 +575,7 @@ restart:
   /* Place a sentinel at the end of the array.  */
   handle_array[nhandles] = NULL;
   nhandles = 1;
-  for (i = 0; i < nfd; i++)
+  for (nfds_t i = 0; i < nfd; i++)
     {
       int happened;
 
diff --git a/lib/progreloc.c b/lib/progreloc.c
index 71d8c34ae5..a26c977422 100644
--- a/lib/progreloc.c
+++ b/lib/progreloc.c
@@ -349,15 +349,12 @@ find_executable (const char *argv0)
      login(1) convention to add a '-' prefix to argv[0] is not supported.  */
   {
     bool has_slash = false;
-    {
-      const char *p;
-      for (p = argv0; *p; p++)
-        if (*p == '/')
-          {
-            has_slash = true;
-            break;
-          }
-    }
+    for (const char *p = argv0; *p; p++)
+      if (*p == '/')
+        {
+          has_slash = true;
+          break;
+        }
     if (!has_slash)
       {
         /* exec searches paths without slashes in the directory list given
@@ -366,10 +363,9 @@ find_executable (const char *argv0)
 
         if (path != NULL)
           {
-            const char *p;
             const char *p_next;
 
-            for (p = path; *p; p = p_next)
+            for (const char *p = path; *p; p = p_next)
               {
                 const char *q;
                 size_t p_len;
diff --git a/lib/pselect.c b/lib/pselect.c
index 78f0446fee..f6599f5f23 100644
--- a/lib/pselect.c
+++ b/lib/pselect.c
@@ -95,15 +95,13 @@ rpl_pselect (int nfds, fd_set *restrict rfds,
              struct timespec const *restrict timeout,
              sigset_t const *restrict sigmask)
 {
-  int i;
-
   /* FreeBSD 8.2 has a bug: it does not always detect invalid fds.  */
   if (nfds < 0 || nfds > FD_SETSIZE)
     {
       errno = EINVAL;
       return -1;
     }
-  for (i = 0; i < nfds; i++)
+  for (int i = 0; i < nfds; i++)
     {
       if (((rfds && FD_ISSET (i, rfds))
            || (wfds && FD_ISSET (i, wfds))
diff --git a/lib/putenv.c b/lib/putenv.c
index c310ebda65..2c29d8033a 100644
--- a/lib/putenv.c
+++ b/lib/putenv.c
@@ -70,7 +70,6 @@ int
 putenv (char *string)
 {
   const char *name_end = strchr (string, '=');
-  char **ep;
 
   if (name_end == NULL)
     {
@@ -105,7 +104,7 @@ putenv (char *string)
       name_x[name_end - string + 1] = ' ';
       name_x[name_end - string + 2] = 0;
       putenv_result = _putenv (name_x);
-      for (ep = environ; *ep; ep++)
+      for (char **ep = environ; *ep; ep++)
         if (streq (*ep, name_x))
           {
             *ep = string;
@@ -125,6 +124,7 @@ putenv (char *string)
       return putenv_result;
     }
 #else
+  char **ep;
   for (ep = environ; *ep; ep++)
     if (strncmp (*ep, string, name_end - string) == 0
         && (*ep)[name_end - string] == '=')
diff --git a/lib/qsort.c b/lib/qsort.c
index f69a881a5d..2f5898312b 100644
--- a/lib/qsort.c
+++ b/lib/qsort.c
@@ -215,13 +215,12 @@ _quicksort (void *const pbase, size_t total_elems, size_t size,
     char *const end_ptr = &base_ptr[size * (total_elems - 1)];
     char *tmp_ptr = base_ptr;
     char *thresh = min(end_ptr, base_ptr + max_thresh);
-    char *run_ptr;
 
     /* Find smallest element in first threshold and place it at the
        array's beginning.  This is the smallest array element,
        and the operation speeds up insertion sort's inner loop. */
 
-    for (run_ptr = tmp_ptr + size; run_ptr <= thresh; run_ptr += size)
+    for (char *run_ptr = tmp_ptr + size; run_ptr <= thresh; run_ptr += size)
       if ((*cmp) ((void *) run_ptr, (void *) tmp_ptr, arg) < 0)
         tmp_ptr = run_ptr;
 
@@ -230,7 +229,7 @@ _quicksort (void *const pbase, size_t total_elems, size_t size,
 
     /* Insertion sort, running from left-hand-side up to right-hand-side.  */
 
-    run_ptr = base_ptr + size;
+    char *run_ptr = base_ptr + size;
     while ((run_ptr += size) <= end_ptr)
       {
 	tmp_ptr = run_ptr - size;
diff --git a/lib/quotearg.c b/lib/quotearg.c
index ded23c710f..ab87d741d2 100644
--- a/lib/quotearg.c
+++ b/lib/quotearg.c
@@ -256,7 +256,6 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
                           char const *left_quote,
                           char const *right_quote)
 {
-  size_t i;
   size_t len = 0;
   size_t orig_buffersize = 0;
   char const *quote_string = NULL;
@@ -393,7 +392,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
       abort ();
     }
 
-  for (i = 0;  ! (argsize == SIZE_MAX ? arg[i] == '\0' : i == argsize);  i++)
+  for (size_t i = 0;  ! (argsize == SIZE_MAX ? arg[i] == '\0' : i == argsize);  i++)
     {
       unsigned char c;
       unsigned char esc;
@@ -644,8 +643,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
                         if ('[' == 0x5b && elide_outer_quotes
                             && quoting_style == shell_always_quoting_style)
                           {
-                            size_t j;
-                            for (j = 1; j < bytes; j++)
+                            for (size_t j = 1; j < bytes; j++)
                               switch (arg[i + m + j])
                                 {
                                 case '[': case '\\': case '^':
@@ -837,8 +835,7 @@ void
 quotearg_free (void)
 {
   struct slotvec *sv = slotvec;
-  int i;
-  for (i = 1; i < nslots; i++)
+  for (int i = 1; i < nslots; i++)
     free (sv[i].val);
   if (sv[0].val != slot0)
     {
diff --git a/lib/random_r.c b/lib/random_r.c
index 19ffb6a6b3..23bcd449c5 100644
--- a/lib/random_r.c
+++ b/lib/random_r.c
@@ -189,7 +189,6 @@ __srandom_r (unsigned int seed, struct random_data *buf)
 {
   int type;
   int32_t *state;
-  long int i;
   int32_t word;
   int32_t *dst;
   int kc;
@@ -211,7 +210,7 @@ __srandom_r (unsigned int seed, struct random_data *buf)
   dst = state;
   word = seed;
   kc = buf->rand_deg;
-  for (i = 1; i < kc; ++i)
+  for (long int i = 1; i < kc; ++i)
     {
       /* This does:
            state[i] = (16807 * state[i - 1]) % 2147483647;
diff --git a/lib/readtokens.c b/lib/readtokens.c
index 8a97f2af09..e9c40791e8 100644
--- a/lib/readtokens.c
+++ b/lib/readtokens.c
@@ -82,11 +82,10 @@ readtoken (FILE *stream,
            token_buffer *tokenbuffer)
 {
   int c;
-  idx_t i;
   word isdelim[(UCHAR_MAX + bits_per_word) / bits_per_word];
 
   memset (isdelim, 0, sizeof isdelim);
-  for (i = 0; i < n_delim; i++)
+  for (idx_t i = 0; i < n_delim; i++)
     {
       unsigned char ch = delim[i];
       set_nth_bit (ch, isdelim);
@@ -100,7 +99,7 @@ readtoken (FILE *stream,
 
   char *p = tokenbuffer->buffer;
   idx_t n = tokenbuffer->size;
-  i = 0;
+  idx_t i = 0;
   for (;;)
     {
       if (c < 0 && i == 0)
diff --git a/lib/readutmp.c b/lib/readutmp.c
index ce9aff9595..d14a8e2072 100644
--- a/lib/readutmp.c
+++ b/lib/readutmp.c
@@ -815,8 +815,7 @@ read_utmp_from_systemd (idx_t *n_entries, STRUCT_UTMP **utmp_buf, int options)
       int num_sessions = sd_get_sessions (&sessions);
       if (num_sessions >= 0 && sessions != NULL)
         {
-          char **session_ptr;
-          for (session_ptr = sessions; *session_ptr != NULL; session_ptr++)
+          for (char **session_ptr = sessions; *session_ptr != NULL; session_ptr++)
             {
               char *session = *session_ptr;
 
diff --git a/lib/regex-quote.c b/lib/regex-quote.c
index 9feffb182b..456f8921cd 100644
--- a/lib/regex-quote.c
+++ b/lib/regex-quote.c
@@ -167,9 +167,7 @@ regex_quote_length (const char *string, const struct regex_quote_spec *spec)
     }
   else
     {
-      const char *iter;
-
-      for (iter = string; *iter != '\0'; iter++)
+      for (const char *iter = string; *iter != '\0'; iter++)
         {
           if (strchr (special, *iter))
             length += 1;
@@ -215,9 +213,7 @@ regex_quote_copy (char *p, const char *string, const struct regex_quote_spec *sp
     }
   else
     {
-      const char *iter;
-
-      for (iter = string; *iter != '\0'; iter++)
+      for (const char *iter = string; *iter != '\0'; iter++)
         {
           if (strchr (special, *iter))
             *p++ = '\\';
diff --git a/lib/relocwrapper.c b/lib/relocwrapper.c
index 3e3900c708..c1524a5480 100644
--- a/lib/relocwrapper.c
+++ b/lib/relocwrapper.c
@@ -148,9 +148,7 @@ static_assert (sizeof (libdirs) / sizeof (libdirs[0]) > 1);
 static void
 relocate_libdirs ()
 {
-  size_t i;
-
-  for (i = 0; i < sizeof (libdirs) / sizeof (libdirs[0]) - 1; i++)
+  for (size_t i = 0; i < sizeof (libdirs) / sizeof (libdirs[0]) - 1; i++)
     libdirs[i] = relocate (libdirs[i]);
 }
 
@@ -160,7 +158,6 @@ activate_libdirs ()
 {
   const char *old_value;
   size_t total;
-  size_t i;
   char *value;
   char *p;
 
@@ -169,7 +166,7 @@ activate_libdirs ()
     old_value = "";
 
   total = 0;
-  for (i = 0; i < sizeof (libdirs) / sizeof (libdirs[0]) - 1; i++)
+  for (size_t i = 0; i < sizeof (libdirs) / sizeof (libdirs[0]) - 1; i++)
     total += strlen (libdirs[i]) + 1;
   total += strlen (old_value) + 1;
 
@@ -180,7 +177,7 @@ activate_libdirs ()
       exit (1);
     }
   p = value;
-  for (i = 0; i < sizeof (libdirs) / sizeof (libdirs[0]) - 1; i++)
+  for (size_t i = 0; i < sizeof (libdirs) / sizeof (libdirs[0]) - 1; i++)
     {
       size_t len = strlen (libdirs[i]);
       memcpy (p, libdirs[i], len);
diff --git a/lib/scandir.c b/lib/scandir.c
index 9aab6c0e1c..e16b07d470 100644
--- a/lib/scandir.c
+++ b/lib/scandir.c
@@ -91,10 +91,9 @@ static void
 cancel_handler (void *arg)
 {
   struct scandir_cancel_struct *cp = arg;
-  size_t i;
   void **v = cp->v;
 
-  for (i = 0; i < cp->cnt; ++i)
+  for (size_t i = 0; i < cp->cnt; ++i)
     free (v[i]);
   free (v);
   (void) __closedir (cp->dp);
diff --git a/lib/select.c b/lib/select.c
index 5a58d6ee47..169e1c20a5 100644
--- a/lib/select.c
+++ b/lib/select.c
@@ -136,7 +136,7 @@ windows_poll_handle (HANDLE h, int fd,
                      struct bitset *xbits)
 {
   BOOL read, write, except;
-  int i, ret;
+  int ret;
   INPUT_RECORD *irbuffer;
   DWORD avail, nbuffer;
   BOOL bRet;
@@ -226,7 +226,7 @@ windows_poll_handle (HANDLE h, int fd,
               break;
             }
 
-          for (i = 0; i < avail; i++)
+          for (int i = 0; i < avail; i++)
             if (irbuffer[i].EventType == KEY_EVENT)
               read = TRUE;
         }
@@ -276,7 +276,7 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
   unsigned char anyfds_in[FD_SETSIZE / CHAR_BIT];
   DWORD ret, wait_timeout, nhandles, nsock, nbuffer;
   MSG msg;
-  int i, fd, rc;
+  int fd, rc;
   clock_t tend;
 
   if (nfds < 0 || nfds > FD_SETSIZE)
@@ -315,7 +315,7 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
   memset (&xbits, 0, sizeof (xbits));
   memset (anyfds_in, 0, sizeof (anyfds_in));
   if (rfds)
-    for (i = 0; i < rfds->fd_count; i++)
+    for (int i = 0; i < rfds->fd_count; i++)
       {
         fd = rfds->fd_array[i];
         h = (HANDLE) _get_osfhandle (fd);
@@ -330,7 +330,7 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
     rfds = (fd_set *) alloca (sizeof (fd_set));
 
   if (wfds)
-    for (i = 0; i < wfds->fd_count; i++)
+    for (int i = 0; i < wfds->fd_count; i++)
       {
         fd = wfds->fd_array[i];
         h = (HANDLE) _get_osfhandle (fd);
@@ -345,7 +345,7 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
     wfds = (fd_set *) alloca (sizeof (fd_set));
 
   if (xfds)
-    for (i = 0; i < xfds->fd_count; i++)
+    for (int i = 0; i < xfds->fd_count; i++)
       {
         fd = xfds->fd_array[i];
         xbits.in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
@@ -363,7 +363,7 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
   FD_ZERO (&handle_xfds);
 
   /* Classify handles.  Create fd sets for sockets, poll the others. */
-  for (i = 0; i < nfds; i++)
+  for (int i = 0; i < nfds; i++)
     {
       if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) == 0)
         continue;
@@ -478,7 +478,7 @@ restart:
     {
       /* Count results that are not counted in the return value of select.  */
       nhandles = 1;
-      for (i = 0; i < nfds; i++)
+      for (int i = 0; i < nfds; i++)
         {
           if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) == 0)
             continue;
@@ -524,7 +524,7 @@ restart:
   FD_ZERO (wfds);
   FD_ZERO (xfds);
   nhandles = 1;
-  for (i = 0; i < nfds; i++)
+  for (int i = 0; i < nfds; i++)
     {
       if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) == 0)
         continue;
@@ -578,7 +578,7 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
       errno = EINVAL;
       return -1;
     }
-  for (i = 0; i < nfds; i++)
+  for (int i = 0; i < nfds; i++)
     {
       if (((rfds && FD_ISSET (i, rfds))
            || (wfds && FD_ISSET (i, wfds))
diff --git a/lib/set-permissions.c b/lib/set-permissions.c
index af0b5de228..f12168a26d 100644
--- a/lib/set-permissions.c
+++ b/lib/set-permissions.c
@@ -108,10 +108,8 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod)
       convention = -1;
     else
       {
-        int i;
-
         convention = 0;
-        for (i = 0; i < count; i++)
+        for (int i = 0; i < count; i++)
           if (entries[i].a_flags & (OLD_ACE_OWNER | OLD_ACE_GROUP | OLD_ACE_OTHER))
             {
               convention = 1;
diff --git a/lib/setlocale-fixes.c b/lib/setlocale-fixes.c
index caa1863329..92309886fe 100644
--- a/lib/setlocale-fixes.c
+++ b/lib/setlocale-fixes.c
@@ -109,9 +109,8 @@ fill_lc_all_name (void)
   else
     {
       /* Produce a mixed locale name.  */
-      size_t i;
-      char *q;
-      for (i = 0, q = lc_all_name; i < 12; i++)
+      char *q = lc_all_name;
+      for (size_t i = 0; i < 12; i++)
         {
           const char *p = cat_names[i];
           size_t n = strlen (p);
@@ -178,10 +177,9 @@ setlocale_fixed (int category, const char *name)
       if (name != NULL)
         {
           char single_name[256+1];
-          int i;
 
           /* Test whether NAME is valid.  */
-          for (i = 12-1; i >= 0; i--)
+          for (int i = 12-1; i >= 0; i--)
             if (extract_single_name (single_name, index_to_cat (i), name) < 0)
               return NULL;
           /* Now single_name contains the one for the index 0,
@@ -190,7 +188,7 @@ setlocale_fixed (int category, const char *name)
             return NULL;
 
           /* Fill lc_cat_name[].  */
-          for (i = 12-1; i >= 0; i--)
+          for (int i = 12-1; i >= 0; i--)
             {
               if (extract_single_name (single_name, index_to_cat (i), name) < 0)
                 abort ();
diff --git a/lib/setlocale.c b/lib/setlocale.c
index 814a9bd8c7..205e5c4db2 100644
--- a/lib/setlocale.c
+++ b/lib/setlocale.c
@@ -638,31 +638,23 @@ search (const struct table_entry *table, size_t table_size, const char *string,
           /* Found an i with
                strcmp (language_table[i].code, string) == 0.
              Find the entire interval of such i.  */
-          {
-            size_t i;
-
-            for (i = mid; i > lo; )
-              {
-                i--;
-                if (strcmp (table[i].code, string) < 0)
-                  {
-                    lo = i + 1;
-                    break;
-                  }
-              }
-          }
-          {
-            size_t i;
-
-            for (i = mid + 1; i < hi; i++)
-              {
-                if (strcmp (table[i].code, string) > 0)
-                  {
-                    hi = i;
-                    break;
-                  }
-              }
-          }
+          for (size_t i = mid; i > lo; )
+            {
+              i--;
+              if (strcmp (table[i].code, string) < 0)
+                {
+                  lo = i + 1;
+                  break;
+                }
+            }
+          for (size_t i = mid + 1; i < hi; i++)
+            {
+              if (strcmp (table[i].code, string) > 0)
+                {
+                  hi = i;
+                  break;
+                }
+            }
           /* The set of i with
                strcmp (language_table[i].code, string) == 0
              is the interval [lo, hi-1].  */
@@ -745,14 +737,13 @@ setlocale_unixlike (int category, const char *locale)
       /* Look it up in language_table.  */
       {
         range_t range;
-        size_t i;
 
         search (language_table,
                 sizeof (language_table) / sizeof (language_table[0]),
                 llCC_buf,
                 &range);
 
-        for (i = range.lo; i < range.hi; i++)
+        for (size_t i = range.lo; i < range.hi; i++)
           {
             /* Try the replacement in language_table[i].  */
             if (is_utf8)
@@ -805,58 +796,49 @@ setlocale_unixlike (int category, const char *locale)
                           CC_buf,
                           &country_range);
                   if (country_range.lo < country_range.hi)
-                    {
-                      size_t i;
-                      size_t j;
+                    for (size_t i = language_range.lo; i < language_range.hi; i++)
+                      for (size_t j = country_range.lo; j < country_range.hi; j++)
+                        {
+                          /* Concatenate the replacements.  */
+                          const char *part1 = language_table[i].english;
+                          size_t part1_len = strlen (part1);
+                          const char *part2 = country_table[j].english;
+                          size_t part2_len = strlen (part2) + 1;
+                          char buf[64+64+6];
+
+                          if (!(part1_len + 1 + part2_len + 6 <= sizeof (buf)))
+                            abort ();
+                          memcpy (buf, part1, part1_len);
+                          buf[part1_len] = '_';
+                          memcpy (buf + part1_len + 1, part2, part2_len);
+                          if (is_utf8)
+                            strcat (buf, ".65001");
 
-                      for (i = language_range.lo; i < language_range.hi; i++)
-                        for (j = country_range.lo; j < country_range.hi; j++)
-                          {
-                            /* Concatenate the replacements.  */
-                            const char *part1 = language_table[i].english;
-                            size_t part1_len = strlen (part1);
-                            const char *part2 = country_table[j].english;
-                            size_t part2_len = strlen (part2) + 1;
-                            char buf[64+64+6];
-
-                            if (!(part1_len + 1 + part2_len + 6 <= sizeof (buf)))
-                              abort ();
-                            memcpy (buf, part1, part1_len);
-                            buf[part1_len] = '_';
-                            memcpy (buf + part1_len + 1, part2, part2_len);
-                            if (is_utf8)
-                              strcat (buf, ".65001");
-
-                            /* Try the concatenated replacements.  */
-                            result = setlocale (category, buf);
-                            if (result != NULL)
-                              return result;
-                          }
-                    }
+                          /* Try the concatenated replacements.  */
+                          result = setlocale (category, buf);
+                          if (result != NULL)
+                            return result;
+                        }
 
                   /* Try omitting the country entirely.  This may set a locale
                      corresponding to the wrong country, but is better than
                      failing entirely.  */
-                  {
-                    size_t i;
-
-                    for (i = language_range.lo; i < language_range.hi; i++)
-                      {
-                        /* Try only the language replacement.  */
-                        if (is_utf8)
-                          {
-                            char buf[64+6];
-                            strcpy (buf, language_table[i].english);
-                            strcat (buf, ".65001");
-                            result = setlocale (category, buf);
-                          }
-                        else
-                          result =
-                            setlocale (category, language_table[i].english);
-                        if (result != NULL)
-                          return result;
-                      }
-                  }
+                  for (size_t i = language_range.lo; i < language_range.hi; i++)
+                    {
+                      /* Try only the language replacement.  */
+                      if (is_utf8)
+                        {
+                          char buf[64+6];
+                          strcpy (buf, language_table[i].english);
+                          strcat (buf, ".65001");
+                          result = setlocale (category, buf);
+                        }
+                      else
+                        result =
+                          setlocale (category, language_table[i].english);
+                      if (result != NULL)
+                        return result;
+                    }
                 }
             }
           }
diff --git a/lib/setlocale_null-unlocked.c b/lib/setlocale_null-unlocked.c
index 72729e6b1b..00214af5f8 100644
--- a/lib/setlocale_null-unlocked.c
+++ b/lib/setlocale_null-unlocked.c
@@ -86,10 +86,8 @@ setlocale_null_r_unlocked (int category, char *buf, size_t bufsize)
       size_t length = wcslen (result);
       if (length < bufsize)
         {
-          size_t i;
-
           /* Convert wchar_t[] -> char[], assuming plain ASCII.  */
-          for (i = 0; i <= length; i++)
+          for (size_t i = 0; i <= length; i++)
             buf[i] = result[i];
 
           return 0;
@@ -101,10 +99,8 @@ setlocale_null_r_unlocked (int category, char *buf, size_t bufsize)
               /* Return a truncated result in BUF.
                  This is a convenience for callers that don't want to write
                  explicit code for handling ERANGE.  */
-              size_t i;
-
               /* Convert wchar_t[] -> char[], assuming plain ASCII.  */
-              for (i = 0; i < bufsize; i++)
+              for (size_t i = 0; i < bufsize; i++)
                 buf[i] = result[i];
               buf[bufsize - 1] = '\0';
             }
diff --git a/lib/sh-quote.c b/lib/sh-quote.c
index 206e8e4ade..169802f8a3 100644
--- a/lib/sh-quote.c
+++ b/lib/sh-quote.c
@@ -73,13 +73,12 @@ shell_quote_argv (const char * const *argv)
 {
   if (*argv != NULL)
     {
-      const char * const *argp;
       size_t length;
       char *command;
       char *p;
 
       length = 0;
-      for (argp = argv; ; )
+      for (const char * const *argp = argv; ; )
         {
           length += shell_quote_length (*argp) + 1;
           argp++;
@@ -90,7 +89,7 @@ shell_quote_argv (const char * const *argv)
       command = XNMALLOC (length, char);
 
       p = command;
-      for (argp = argv; ; )
+      for (const char * const *argp = argv; ; )
         {
           p = shell_quote_copy (p, *argp);
           argp++;
diff --git a/lib/sha1.c b/lib/sha1.c
index d10c159af6..fd72199d2f 100644
--- a/lib/sha1.c
+++ b/lib/sha1.c
@@ -254,8 +254,7 @@ sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
   while (words < endp)
     {
       uint32_t tm;
-      int t;
-      for (t = 0; t < 16; t++)
+      for (int t = 0; t < 16; t++)
         {
           x[t] = SWAP (*words);
           words++;
diff --git a/lib/sha256.c b/lib/sha256.c
index 9358faff3e..27c4f0c76f 100644
--- a/lib/sha256.c
+++ b/lib/sha256.c
@@ -96,10 +96,9 @@ set_uint32 (char *cp, uint32_t v)
 void *
 sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf)
 {
-  int i;
   char *r = resbuf;
 
-  for (i = 0; i < 8; i++)
+  for (int i = 0; i < 8; i++)
     set_uint32 (r + i * sizeof ctx->state[0], SWAP (ctx->state[i]));
 
   return resbuf;
@@ -108,10 +107,9 @@ sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf)
 void *
 sha224_read_ctx (const struct sha256_ctx *ctx, void *resbuf)
 {
-  int i;
   char *r = resbuf;
 
-  for (i = 0; i < 7; i++)
+  for (int i = 0; i < 7; i++)
     set_uint32 (r + i * sizeof ctx->state[0], SWAP (ctx->state[i]));
 
   return resbuf;
@@ -338,9 +336,8 @@ sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx)
     {
       uint32_t tm;
       uint32_t t0, t1;
-      int t;
       /* FIXME: see sha1.c for a better implementation.  */
-      for (t = 0; t < 16; t++)
+      for (int t = 0; t < 16; t++)
         {
           x[t] = SWAP (*words);
           words++;
diff --git a/lib/sha512.c b/lib/sha512.c
index 904a891227..76deb73100 100644
--- a/lib/sha512.c
+++ b/lib/sha512.c
@@ -96,10 +96,9 @@ set_uint64 (char *cp, u64 v)
 void *
 sha512_read_ctx (const struct sha512_ctx *ctx, void *resbuf)
 {
-  int i;
   char *r = resbuf;
 
-  for (i = 0; i < 8; i++)
+  for (int i = 0; i < 8; i++)
     set_uint64 (r + i * sizeof ctx->state[0], SWAP (ctx->state[i]));
 
   return resbuf;
@@ -108,10 +107,9 @@ sha512_read_ctx (const struct sha512_ctx *ctx, void *resbuf)
 void *
 sha384_read_ctx (const struct sha512_ctx *ctx, void *resbuf)
 {
-  int i;
   char *r = resbuf;
 
-  for (i = 0; i < 6; i++)
+  for (int i = 0; i < 6; i++)
     set_uint64 (r + i * sizeof ctx->state[0], SWAP (ctx->state[i]));
 
   return resbuf;
@@ -367,9 +365,8 @@ sha512_process_block (const void *buffer, size_t len, struct sha512_ctx *ctx)
 
   while (words < endp)
     {
-      int t;
       /* FIXME: see sha1.c for a better implementation.  */
-      for (t = 0; t < 16; t++)
+      for (int t = 0; t < 16; t++)
         {
           x[t] = SWAP (*words);
           words++;
diff --git a/lib/sig2str.c b/lib/sig2str.c
index bf4d009578..d21aac1c64 100644
--- a/lib/sig2str.c
+++ b/lib/sig2str.c
@@ -286,8 +286,7 @@ str2signum (char const *signame)
     }
   else
     {
-      unsigned int i;
-      for (i = 0; i < NUMNAME_ENTRIES; i++)
+      for (unsigned int i = 0; i < NUMNAME_ENTRIES; i++)
         if (streq (numname_table[i].name, signame))
           return numname_table[i].num;
 
@@ -331,8 +330,7 @@ str2sig (char const *signame, int *signum)
 int
 sig2str (int signum, char *signame)
 {
-  unsigned int i;
-  for (i = 0; i < NUMNAME_ENTRIES; i++)
+  for (unsigned int i = 0; i < NUMNAME_ENTRIES; i++)
     if (numname_table[i].num == signum)
       {
         strcpy (signame, numname_table[i].name);
diff --git a/lib/sigprocmask.c b/lib/sigprocmask.c
index d52e191c44..5c3899efba 100644
--- a/lib/sigprocmask.c
+++ b/lib/sigprocmask.c
@@ -211,9 +211,8 @@ int
 sigpending (sigset_t *set)
 {
   sigset_t pending = 0;
-  int sig;
 
-  for (sig = 0; sig < NSIG; sig++)
+  for (int sig = 0; sig < NSIG; sig++)
     if (pending_array[sig])
       pending |= 1U << sig;
   *set = pending;
@@ -258,24 +257,19 @@ sigprocmask (int operation, const sigset_t *set, sigset_t *old_set)
       to_block = new_blocked_set & ~blocked_set;
 
       if (to_block != 0)
-        {
-          int sig;
-
-          for (sig = 0; sig < NSIG; sig++)
-            if ((to_block >> sig) & 1)
-              {
-                pending_array[sig] = 0;
-                if ((old_handlers[sig] = signal (sig, blocked_handler)) != SIG_ERR)
-                  blocked_set |= 1U << sig;
-              }
-        }
+        for (int sig = 0; sig < NSIG; sig++)
+          if ((to_block >> sig) & 1)
+            {
+              pending_array[sig] = 0;
+              if ((old_handlers[sig] = signal (sig, blocked_handler)) != SIG_ERR)
+                blocked_set |= 1U << sig;
+            }
 
       if (to_unblock != 0)
         {
           sig_atomic_t received[NSIG];
-          int sig;
 
-          for (sig = 0; sig < NSIG; sig++)
+          for (int sig = 0; sig < NSIG; sig++)
             if ((to_unblock >> sig) & 1)
               {
                 if (signal (sig, old_handlers[sig]) != blocked_handler)
@@ -290,7 +284,7 @@ sigprocmask (int operation, const sigset_t *set, sigset_t *old_set)
             else
               received[sig] = 0;
 
-          for (sig = 0; sig < NSIG; sig++)
+          for (int sig = 0; sig < NSIG; sig++)
             if (received[sig])
               raise (sig);
         }
diff --git a/lib/sm3.c b/lib/sm3.c
index 9c1a053729..4941de5684 100644
--- a/lib/sm3.c
+++ b/lib/sm3.c
@@ -93,10 +93,9 @@ set_uint32 (char *cp, uint32_t v)
 void *
 sm3_read_ctx (const struct sm3_ctx *ctx, void *resbuf)
 {
-  int i;
   char *r = resbuf;
 
-  for (i = 0; i < 8; i++)
+  for (int i = 0; i < 8; i++)
     set_uint32 (r + i * sizeof ctx->state[0], SWAP (ctx->state[i]));
 
   return resbuf;
@@ -311,15 +310,14 @@ sm3_process_block (const void *buffer, size_t len, struct sm3_ctx *ctx)
     {
       uint32_t tw;
       uint32_t ss1, ss2;
-      int j;
 
-      for (j = 0; j < 16; j++)
+      for (int j = 0; j < 16; j++)
         {
           x[j] = SWAP (*words);
           words++;
         }
 
-      j = -1;
+      int j = -1;
 
       dbg_printf (" j    A        B        C        D        E  "
                   "      F        G        H\n"
diff --git a/lib/spawn_faction_destroy.c b/lib/spawn_faction_destroy.c
index ba4c84dee2..6d3ae4fc9c 100644
--- a/lib/spawn_faction_destroy.c
+++ b/lib/spawn_faction_destroy.c
@@ -33,10 +33,8 @@ posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *file_actions)
 #if !REPLACE_POSIX_SPAWN
   return posix_spawn_file_actions_destroy (file_actions);
 #else
-  int i;
-
   /* Free the paths in the open actions.  */
-  for (i = 0; i < file_actions->_used; ++i)
+  for (int i = 0; i < file_actions->_used; ++i)
     {
       struct __spawn_action *sa = &file_actions->_actions[i];
       switch (sa->tag)
diff --git a/lib/spawni.c b/lib/spawni.c
index 3f81d95697..a4cf875d68 100644
--- a/lib/spawni.c
+++ b/lib/spawni.c
@@ -185,9 +185,8 @@ do_remaining_delayed_dup2 (struct inheritable_handles *inh_handles,
                            HANDLE curr_process)
 {
   size_t handles_count = inh_handles->count;
-  int newfd;
 
-  for (newfd = 0; newfd < handles_count; newfd++)
+  for (int newfd = 0; newfd < handles_count; newfd++)
     if (inh_handles->ih[newfd].handle != INVALID_HANDLE_VALUE
         && (inh_handles->ih[newfd].flags & DELAYED_DUP2_NEWFD) != 0)
       if (do_delayed_dup2 (newfd, inh_handles, curr_process) < 0)
@@ -204,9 +203,8 @@ shrink_inheritable_handles (struct inheritable_handles *inh_handles)
 {
   struct IHANDLE *ih = inh_handles->ih;
   size_t handles_count = inh_handles->count;
-  unsigned int fd;
 
-  for (fd = 0; fd < handles_count; fd++)
+  for (unsigned int fd = 0; fd < handles_count; fd++)
     {
       HANDLE handle = ih[fd].handle;
 
@@ -232,9 +230,8 @@ close_inheritable_handles (struct inheritable_handles *inh_handles)
 {
   struct IHANDLE *ih = inh_handles->ih;
   size_t handles_count = inh_handles->count;
-  unsigned int fd;
 
-  for (fd = 0; fd < handles_count; fd++)
+  for (unsigned int fd = 0; fd < handles_count; fd++)
     {
       HANDLE handle = ih[fd].handle;
 
@@ -691,9 +688,8 @@ __spawni (pid_t *pid, const char *prog_filename,
   if (file_actions != NULL)
     {
       HANDLE curr_process = GetCurrentProcess ();
-      int cnt;
 
-      for (cnt = 0; cnt < file_actions->_used; ++cnt)
+      for (int cnt = 0; cnt < file_actions->_used; ++cnt)
         {
           struct __spawn_action *action = &file_actions->_actions[cnt];
 
@@ -951,13 +947,12 @@ __spawni (pid_t *pid, const char *file,
          done better but it requires system specific solutions since
          the sigset_t data type can be very different on different
          architectures.  */
-      int sig;
       struct sigaction sa;
 
       memset (&sa, '\0', sizeof (sa));
       sa.sa_handler = SIG_DFL;
 
-      for (sig = 1; sig < NSIG; ++sig)
+      for (int sig = 1; sig < NSIG; ++sig)
         if (sigismember (&attrp->_sd, sig) != 0
             && sigaction (sig, &sa, NULL) != 0)
           _exit (SPAWN_ERROR);
@@ -994,69 +989,65 @@ __spawni (pid_t *pid, const char *file,
 
   /* Execute the file actions.  */
   if (file_actions != NULL)
-    {
-      int cnt;
+    for (int cnt = 0; cnt < file_actions->_used; ++cnt)
+      {
+        struct __spawn_action *action = &file_actions->_actions[cnt];
 
-      for (cnt = 0; cnt < file_actions->_used; ++cnt)
-        {
-          struct __spawn_action *action = &file_actions->_actions[cnt];
+        switch (action->tag)
+          {
+          case spawn_do_close:
+            if (close_not_cancel (action->action.close_action.fd) != 0)
+              /* Signal the error.  */
+              _exit (SPAWN_ERROR);
+            break;
 
-          switch (action->tag)
+          case spawn_do_open:
             {
-            case spawn_do_close:
-              if (close_not_cancel (action->action.close_action.fd) != 0)
-                /* Signal the error.  */
-                _exit (SPAWN_ERROR);
-              break;
+              int new_fd = open_not_cancel (action->action.open_action.path,
+                                            action->action.open_action.oflag
+                                            | O_LARGEFILE,
+                                            action->action.open_action.mode);
 
-            case spawn_do_open:
-              {
-                int new_fd = open_not_cancel (action->action.open_action.path,
-                                              action->action.open_action.oflag
-                                              | O_LARGEFILE,
-                                              action->action.open_action.mode);
-
-                if (new_fd == -1)
-                  /* The 'open' call failed.  */
-                  _exit (SPAWN_ERROR);
-
-                /* Make sure the desired file descriptor is used.  */
-                if (new_fd != action->action.open_action.fd)
-                  {
-                    if (dup2 (new_fd, action->action.open_action.fd)
-                        != action->action.open_action.fd)
-                      /* The 'dup2' call failed.  */
-                      _exit (SPAWN_ERROR);
-
-                    if (close_not_cancel (new_fd) != 0)
-                      /* The 'close' call failed.  */
-                      _exit (SPAWN_ERROR);
-                  }
-              }
-              break;
-
-            case spawn_do_dup2:
-              if (dup2 (action->action.dup2_action.fd,
-                        action->action.dup2_action.newfd)
-                  != action->action.dup2_action.newfd)
-                /* The 'dup2' call failed.  */
-                _exit (SPAWN_ERROR);
-              break;
-
-            case spawn_do_chdir:
-              if (chdir (action->action.chdir_action.path) < 0)
-                /* The 'chdir' call failed.  */
+              if (new_fd == -1)
+                /* The 'open' call failed.  */
                 _exit (SPAWN_ERROR);
-              break;
 
-            case spawn_do_fchdir:
-              if (fchdir (action->action.fchdir_action.fd) < 0)
-                /* The 'fchdir' call failed.  */
-                _exit (SPAWN_ERROR);
-              break;
+              /* Make sure the desired file descriptor is used.  */
+              if (new_fd != action->action.open_action.fd)
+                {
+                  if (dup2 (new_fd, action->action.open_action.fd)
+                      != action->action.open_action.fd)
+                    /* The 'dup2' call failed.  */
+                    _exit (SPAWN_ERROR);
+
+                  if (close_not_cancel (new_fd) != 0)
+                    /* The 'close' call failed.  */
+                    _exit (SPAWN_ERROR);
+                }
             }
-        }
-    }
+            break;
+
+          case spawn_do_dup2:
+            if (dup2 (action->action.dup2_action.fd,
+                      action->action.dup2_action.newfd)
+                != action->action.dup2_action.newfd)
+              /* The 'dup2' call failed.  */
+              _exit (SPAWN_ERROR);
+            break;
+
+          case spawn_do_chdir:
+            if (chdir (action->action.chdir_action.path) < 0)
+              /* The 'chdir' call failed.  */
+              _exit (SPAWN_ERROR);
+            break;
+
+          case spawn_do_fchdir:
+            if (fchdir (action->action.fchdir_action.fd) < 0)
+              /* The 'fchdir' call failed.  */
+              _exit (SPAWN_ERROR);
+            break;
+          }
+      }
 
   if (! use_path)
     {
diff --git a/lib/ssfmalloc-bitmap.h b/lib/ssfmalloc-bitmap.h
index 2de465c03f..70a0139917 100644
--- a/lib/ssfmalloc-bitmap.h
+++ b/lib/ssfmalloc-bitmap.h
@@ -27,8 +27,7 @@
 static inline void
 init_bitmap_all_bits_clear (size_t num_words, uint32_t *words)
 {
-  size_t i;
-  for (i = 0; i < num_words; i++)
+  for (size_t i = 0; i < num_words; i++)
     words[i] = 0;
 }
 
@@ -36,8 +35,7 @@ init_bitmap_all_bits_clear (size_t num_words, uint32_t *words)
 static inline void
 init_bitmap_all_bits_set (size_t num_words, uint32_t *words)
 {
-  size_t i;
-  for (i = 0; i < num_words; i++)
+  for (size_t i = 0; i < num_words; i++)
     words[i] = ~(uint32_t)0;
 }
 
diff --git a/lib/ssfmalloc.h b/lib/ssfmalloc.h
index ff05b997c9..f05f150409 100644
--- a/lib/ssfmalloc.h
+++ b/lib/ssfmalloc.h
@@ -287,8 +287,7 @@ static inline void
 add_update (uintptr_t page, struct page_pool *pool)
 {
   size_t count = pool->update_queue_count;
-  size_t i;
-  for (i = 0; i < count; i++)
+  for (size_t i = 0; i < count; i++)
     if (pool->update_queue[i] == page)
       /* It's already in the queue.  */
       return;
@@ -306,8 +305,7 @@ static inline void
 drop_update (uintptr_t page, struct page_pool *pool)
 {
   size_t count = pool->update_queue_count;
-  size_t i;
-  for (i = 0; i < count; i++)
+  for (size_t i = 0; i < count; i++)
     if (pool->update_queue[i] == page)
       {
         /* It's in the queue.  Remove it.  */
@@ -577,8 +575,7 @@ allocate_medium_block_in_page (size_t size, uintptr_t page)
   size_t best_i = (size_t)(-1);
   size_t best_length = (size_t)(-1);
   size_t num_gaps = pageptr->num_gaps;
-  size_t i;
-  for (i = 0; i < num_gaps; i++)
+  for (size_t i = 0; i < num_gaps; i++)
     {
       size_t length = pageptr->gaps[i].end - pageptr->gaps[i].start;
       if (length >= size)
@@ -602,7 +599,7 @@ allocate_medium_block_in_page (size_t size, uintptr_t page)
     abort ();
 
   /* Split the gap, leaving an empty gap and a remaining gap.  */
-  for (i = num_gaps - 1; ; i--)
+  for (size_t i = num_gaps - 1; ; i--)
     {
       pageptr->gaps[i + 1] = pageptr->gaps[i];
       if (i == best_i)
@@ -665,8 +662,7 @@ free_medium_block_in_page (uintptr_t block, uintptr_t page)
   gaps[index].end = gaps[index + 1].end;
 
   size_t num_gaps = pageptr->num_gaps - 1;
-  size_t i;
-  for (i = index + 1; i < num_gaps; i++)
+  for (size_t i = index + 1; i < num_gaps; i++)
     gaps[i] = gaps[i + 1];
   pageptr->num_gaps = num_gaps;
 }
diff --git a/lib/stack-trace-impl.h b/lib/stack-trace-impl.h
index abbd5f4db6..131b3671bb 100644
--- a/lib/stack-trace-impl.h
+++ b/lib/stack-trace-impl.h
@@ -75,10 +75,8 @@ print_stack_trace_to (FILE *stream)
       char **symbols = backtrace_symbols (buffer, size);
       if (symbols != NULL)
         {
-          int i;
-
           fprintf (stream, "Stack trace:\n");
-          for (i = 0; i < size; i++)
+          for (int i = 0; i < size; i++)
             fprintf (stream, "%s\n", symbols[i]);
           fflush (stream);
 
diff --git a/lib/stat-time.h b/lib/stat-time.h
index 38315b9f56..3fab4db692 100644
--- a/lib/stat-time.h
+++ b/lib/stat-time.h
@@ -232,8 +232,7 @@ stat_time_normalize (int result, _GL_UNUSED struct stat *st)
       short int const ts_off[] = { STAT_TIMESPEC_OFFSETOF (st_atim),
                                    STAT_TIMESPEC_OFFSETOF (st_mtim),
                                    STAT_TIMESPEC_OFFSETOF (st_ctim) };
-      int i;
-      for (i = 0; i < sizeof ts_off / sizeof *ts_off; i++)
+      for (int i = 0; i < sizeof ts_off / sizeof *ts_off; i++)
         {
           struct timespec *ts = (struct timespec *) ((char *) st + ts_off[i]);
           long int q = ts->tv_nsec / timespec_hz;
diff --git a/lib/stat-w32.c b/lib/stat-w32.c
index 8da8fe5c5b..097ff96903 100644
--- a/lib/stat-w32.c
+++ b/lib/stat-w32.c
@@ -289,8 +289,7 @@ _gl_fstat_by_handle (HANDLE h, const char *path, struct stat *buf)
                       && (path = fpath, 1)))
                 {
                   const char *last_dot = NULL;
-                  const char *p;
-                  for (p = path; *p != '\0'; p++)
+                  for (const char *p = path; *p != '\0'; p++)
                     if (*p == '.')
                       last_dot = p;
                   if (last_dot != NULL)
diff --git a/lib/stat.c b/lib/stat.c
index f4cc02e9d7..f7c03eb06b 100644
--- a/lib/stat.c
+++ b/lib/stat.c
@@ -287,8 +287,7 @@ rpl_stat (char const *name, struct stat *buf)
           if (info.nFileSizeHigh > 0 || info.nFileSizeLow > 0)
             {
               const char *last_dot = NULL;
-              const char *p;
-              for (p = info.cFileName; *p != '\0'; p++)
+              for (const char *p = info.cFileName; *p != '\0'; p++)
                 if (*p == '.')
                   last_dot = p;
               if (last_dot != NULL)
diff --git a/lib/stdopen.c b/lib/stdopen.c
index 9b5227e84d..148f97ceff 100644
--- a/lib/stdopen.c
+++ b/lib/stdopen.c
@@ -42,8 +42,7 @@
 int
 stdopen (void)
 {
-  int fd;
-  for (fd = STDIN_FILENO; fd <= STDERR_FILENO; fd++)
+  for (int fd = STDIN_FILENO; fd <= STDERR_FILENO; fd++)
     {
       if (fcntl (fd, F_GETFD) < 0)
         {
diff --git a/lib/str-kmp.h b/lib/str-kmp.h
index ebbfc208dd..352ea72aa6 100644
--- a/lib/str-kmp.h
+++ b/lib/str-kmp.h
@@ -66,13 +66,13 @@ knuth_morris_pratt (const UNIT *haystack,
           forall 0 <= x < table[i]: rhaystack[x..x+m-1] != needle[0..m-1].
      table[0] remains uninitialized.  */
   {
-    size_t i, j;
+    size_t j;
 
     /* i = 1: Nothing to verify for x = 0.  */
     table[1] = 1;
     j = 0;
 
-    for (i = 2; i < m; i++)
+    for (size_t i = 2; i < m; i++)
       {
         /* Here: j = i-1 - table[i-1].
            The inequality needle[x..i-1] != needle[0..i-1-x] is known to hold
diff --git a/lib/str-two-way.h b/lib/str-two-way.h
index d13fb298fd..852e5d078f 100644
--- a/lib/str-two-way.h
+++ b/lib/str-two-way.h
@@ -329,7 +329,6 @@ static RETURN_TYPE _GL_ATTRIBUTE_PURE
 two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
                      const unsigned char *needle, size_t needle_len)
 {
-  size_t i; /* Index into current byte of NEEDLE.  */
   size_t j; /* Index into current window of HAYSTACK.  */
   size_t period; /* The period of the right half of needle.  */
   size_t suffix; /* The index of the right half of needle.  */
@@ -344,9 +343,9 @@ two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
      shift_table[c] is the distance from the last occurrence of c to
      the end of NEEDLE, or NEEDLE_LEN if c is absent from the NEEDLE.
      shift_table[NEEDLE[NEEDLE_LEN - 1]] contains the only 0.  */
-  for (i = 0; i < 1U << CHAR_BIT; i++)
+  for (size_t i = 0; i < 1U << CHAR_BIT; i++)
     shift_table[i] = needle_len;
-  for (i = 0; i < needle_len; i++)
+  for (size_t i = 0; i < needle_len; i++)
     shift_table[CANON_ELEMENT (needle[i])] = needle_len - i - 1;
 
   /* Perform the search.  Each iteration compares the right half
@@ -379,7 +378,7 @@ two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
             }
           /* Scan for matches in right half.  The last byte has
              already been matched, by virtue of the shift table.  */
-          i = MAX (suffix, memory);
+          size_t i = MAX (suffix, memory);
           while (i < needle_len - 1 && (CANON_ELEMENT (needle[i])
                                         == CANON_ELEMENT (haystack[i + j])))
             ++i;
@@ -423,7 +422,7 @@ two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
             }
           /* Scan for matches in right half.  The last byte has
              already been matched, by virtue of the shift table.  */
-          i = suffix;
+          size_t i = suffix;
           while (i < needle_len - 1 && (CANON_ELEMENT (needle[i])
                                         == CANON_ELEMENT (haystack[i + j])))
             ++i;
diff --git a/lib/strchrnul.c b/lib/strchrnul.c
index fbd16b23da..e6d9c7f8c8 100644
--- a/lib/strchrnul.c
+++ b/lib/strchrnul.c
@@ -64,15 +64,11 @@ strchrnul (const char *s, int c_in)
       repeated_one |= repeated_one << 31 << 1;
       repeated_c |= repeated_c << 31 << 1;
       if (8 < sizeof (longword))
-        {
-          size_t i;
-
-          for (i = 64; i < sizeof (longword) * 8; i *= 2)
-            {
-              repeated_one |= repeated_one << i;
-              repeated_c |= repeated_c << i;
-            }
-        }
+        for (size_t i = 64; i < sizeof (longword) * 8; i *= 2)
+          {
+            repeated_one |= repeated_one << i;
+            repeated_c |= repeated_c << i;
+          }
     }
 
   /* Instead of the traditional loop which tests each byte, we will
diff --git a/lib/strfmon_l.c b/lib/strfmon_l.c
index 63f14aea75..1da4d1d8fe 100644
--- a/lib/strfmon_l.c
+++ b/lib/strfmon_l.c
@@ -146,10 +146,9 @@ rpl_strfmon_l (char *s, size_t maxsize, locale_t locale, const char *format, ...
   else
     {
       bool use_long_double;
-      unsigned int i;
 
       use_long_double = false;
-      for (i = 0; i < directives.count; i++)
+      for (unsigned int i = 0; i < directives.count; i++)
         if (directives.dir[i].needs_long_double)
           {
             use_long_double = true;
@@ -177,7 +176,7 @@ rpl_strfmon_l (char *s, size_t maxsize, locale_t locale, const char *format, ...
               {
                 const char *p = format;
                 char *dest = ld_format;
-                for (i = 0; i < directives.count; i++)
+                for (unsigned int i = 0; i < directives.count; i++)
                   {
                     const char *q = directives.dir[i].conversion_ptr;
                     memcpy (dest, p, q - p);
@@ -189,14 +188,18 @@ rpl_strfmon_l (char *s, size_t maxsize, locale_t locale, const char *format, ...
                 strcpy (dest, p);
               }
 
-              /* Set up arguments array.  */
-              for (i = 0; i < directives.count; i++)
-                args[i] = (directives.dir[i].needs_long_double
-                           ? va_arg (argptr, long double)
-                           : (long double) va_arg (argptr, double));
-              /* Avoid uninitialized memory references.  */
-              for (; i < MAX_ARGS; i++)
-                args[i] = 0.0L;
+              {
+                unsigned int i;
+
+                /* Set up arguments array.  */
+                for (i = 0; i < directives.count; i++)
+                  args[i] = (directives.dir[i].needs_long_double
+                             ? va_arg (argptr, long double)
+                             : (long double) va_arg (argptr, double));
+                /* Avoid uninitialized memory references.  */
+                for (; i < MAX_ARGS; i++)
+                  args[i] = 0.0L;
+              }
 
               result = strfmon_l (s, maxsize, locale, ld_format,
                                   args[0], args[1], args[2], args[3], args[4],
@@ -211,12 +214,16 @@ rpl_strfmon_l (char *s, size_t maxsize, locale_t locale, const char *format, ...
         {
           double args[MAX_ARGS];
 
-          /* Set up arguments array.  */
-          for (i = 0; i < directives.count; i++)
-            args[i] = va_arg (argptr, double);
-          /* Avoid uninitialized memory references.  */
-          for (; i < MAX_ARGS; i++)
-            args[i] = 0.0;
+          {
+            unsigned int i;
+
+            /* Set up arguments array.  */
+            for (i = 0; i < directives.count; i++)
+              args[i] = va_arg (argptr, double);
+            /* Avoid uninitialized memory references.  */
+            for (; i < MAX_ARGS; i++)
+              args[i] = 0.0;
+          }
 
           result = strfmon_l (s, maxsize, locale, format,
                               args[0], args[1], args[2], args[3], args[4],
diff --git a/lib/strftime.c b/lib/strftime.c
index fde7e6f7da..b78901f5fd 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -1020,8 +1020,7 @@ underlying_strftime (timezone_t tz, char *ubuf, size_t ubufsize,
                 {
                   /* The last word has length >= 3.  */
                   bool found_letter = false;
-                  const char *p;
-                  for (p = space + 1; *p != '\0'; p++)
+                  for (const char *p = space + 1; *p != '\0'; p++)
                     if ((*p >= 'A' && *p <= 'Z')
                         || (*p >= 'a' && *p <= 'z'))
                       {
@@ -1248,7 +1247,6 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
 #endif
   retval_t i = 0;
   STREAM_OR_CHAR_T *p = s;
-  const CHAR_T *f;
 #if DO_MULTIBYTE && !defined COMPILE_WIDE
   const char *format_end = NULL;
 #endif
@@ -1260,7 +1258,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
     if (hour12 == 0)
       hour12 = 12;
 
-  for (f = format; *f != '\0'; width = -1, f++)
+  for (const CHAR_T *f = format; *f != '\0'; width = -1, f++)
     {
       enum pad_style pad = ZERO_PAD;
       int modifier;             /* Field modifier ('E', 'O', or 0).  */
@@ -1659,8 +1657,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
                           {
                             /* The last word has length >= 3.  */
                             bool found_letter = false;
-                            const char *wp;
-                            for (wp = space + 1; *wp != '\0'; wp++)
+                            for (const char *wp = space + 1; *wp != '\0'; wp++)
                               if ((*wp >= 'A' && *wp <= 'Z')
                                   || (*wp >= 'a' && *wp <= 'z'))
                                 {
diff --git a/lib/striconveh.c b/lib/striconveh.c
index 9289591b63..3fac3f4006 100644
--- a/lib/striconveh.c
+++ b/lib/striconveh.c
@@ -148,12 +148,10 @@ iconv_carefully (iconv_t cd,
 
   do
     {
-      size_t insize;
-
       inptr_before = inptr;
       res = (size_t)(-1);
 
-      for (insize = 1; inptr + insize <= inptr_end; insize++)
+      for (size_t insize = 1; inptr + insize <= inptr_end; insize++)
         {
           res = iconv (cd,
                        (ICONV_CONST char **) &inptr, &insize,
@@ -215,9 +213,8 @@ iconv_carefully_1 (iconv_t cd,
   char *outptr = *outbuf;
   size_t outsize = *outbytesleft;
   size_t res = (size_t)(-1);
-  size_t insize;
 
-  for (insize = 1; inptr_before + insize <= inptr_end; insize++)
+  for (size_t insize = 1; inptr_before + insize <= inptr_end; insize++)
     {
       inptr = inptr_before;
       res = iconv (cd,
@@ -378,9 +375,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
 
   if (offsets != NULL)
     {
-      size_t i;
-
-      for (i = 0; i < srclen; i++)
+      for (size_t i = 0; i < srclen; i++)
         offsets[i] = (size_t)(-1);
 
       last_length = (size_t)(-1);
@@ -583,9 +578,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
      Use a conversion through UTF-8.  */
   if (offsets != NULL)
     {
-      size_t i;
-
-      for (i = 0; i < srclen; i++)
+      for (size_t i = 0; i < srclen; i++)
         offsets[i] = (size_t)(-1);
 
       last_length = (size_t)(-1);
diff --git a/lib/striconveha.c b/lib/striconveha.c
index b7dec0178b..f3e41cfc6a 100644
--- a/lib/striconveha.c
+++ b/lib/striconveha.c
@@ -155,11 +155,11 @@ mem_iconveha_notranslit (const char *src, size_t srclen,
     return retval;
   else
     {
-      struct autodetect_alias *alias;
-
       /* Unsupported from_codeset or to_codeset. Check whether the caller
          requested autodetection.  */
-      for (alias = autodetect_list; alias != NULL; alias = alias->next)
+      for (struct autodetect_alias *alias = autodetect_list;
+           alias != NULL;
+           alias = alias->next)
         if (streq (from_codeset, alias->name))
           {
             const char * const *encodings;
@@ -265,11 +265,11 @@ str_iconveha_notranslit (const char *src,
     return result;
   else
     {
-      struct autodetect_alias *alias;
-
       /* Unsupported from_codeset or to_codeset. Check whether the caller
          requested autodetection.  */
-      for (alias = autodetect_list; alias != NULL; alias = alias->next)
+      for (struct autodetect_alias *alias = autodetect_list;
+           alias != NULL;
+           alias = alias->next)
         if (streq (from_codeset, alias->name))
           {
             const char * const *encodings;
diff --git a/lib/string-desc.c b/lib/string-desc.c
index 0ff0c4db6a..2d13a866b9 100644
--- a/lib/string-desc.c
+++ b/lib/string-desc.c
@@ -94,15 +94,14 @@ _sd_c_casecmp (idx_t a_nbytes, const char *a_data,
   /* Don't use memcasecmp here, since it uses the current locale, not the
      "C" locale.  */
   idx_t n = (a_nbytes < b_nbytes ? a_nbytes : b_nbytes);
-  idx_t i;
-  for (i = 0; i < n; i++)
+  for (idx_t i = 0; i < n; i++)
     {
       int ac = c_tolower ((unsigned char) a_data[i]);
       int bc = c_tolower ((unsigned char) b_data[i]);
       if (ac != bc)
         return (UCHAR_MAX <= INT_MAX ? ac - bc : _GL_CMP (ac, bc));
     }
-  /* Here i = n = min (a_nbytes, b_nbytes).  */
+  /* Found n = min (a_nbytes, b_nbytes) equal characters.  */
   return _GL_CMP (a_nbytes, b_nbytes);
 }
 
@@ -301,15 +300,11 @@ sd_concat (rw_string_desc_t *resultp, idx_t n, /* [rw_]string_desc_t string1, */
     string_desc_t string1 = va_arg (strings, string_desc_t);
     total += string1._nbytes;
     if (n > 1)
-      {
-        idx_t i;
-
-        for (i = n - 1; i > 0; i--)
-          {
-            string_desc_t arg = va_arg (strings, string_desc_t);
-            total += arg._nbytes;
-          }
-      }
+      for (idx_t i = n - 1; i > 0; i--)
+        {
+          string_desc_t arg = va_arg (strings, string_desc_t);
+          total += arg._nbytes;
+        }
     va_end (strings);
   }
 
@@ -325,17 +320,13 @@ sd_concat (rw_string_desc_t *resultp, idx_t n, /* [rw_]string_desc_t string1, */
     memcpy (combined, string1._data, string1._nbytes);
     pos += string1._nbytes;
     if (n > 1)
-      {
-        idx_t i;
-
-        for (i = n - 1; i > 0; i--)
-          {
-            string_desc_t arg = va_arg (strings, string_desc_t);
-            if (arg._nbytes > 0)
-              memcpy (combined + pos, arg._data, arg._nbytes);
-            pos += arg._nbytes;
-          }
-      }
+      for (idx_t i = n - 1; i > 0; i--)
+        {
+          string_desc_t arg = va_arg (strings, string_desc_t);
+          if (arg._nbytes > 0)
+            memcpy (combined + pos, arg._data, arg._nbytes);
+          pos += arg._nbytes;
+        }
     va_end (strings);
   }
 
diff --git a/lib/strnlen.c b/lib/strnlen.c
index f699041576..5a03d7ec94 100644
--- a/lib/strnlen.c
+++ b/lib/strnlen.c
@@ -27,8 +27,7 @@ strnlen (const char *s, size_t maxlen)
 {
   /* Do not use memchr, because on some platforms memchr has
      undefined behavior if MAXLEN exceeds the number of bytes in S.  */
-  size_t i;
-  for (i = 0; i < maxlen && s[i]; i++)
+  for (size_t i = 0; i < maxlen && s[i]; i++)
     continue;
   return i;
 }
diff --git a/lib/strtod.c b/lib/strtod.c
index 73fe95ca03..24593e5b9e 100644
--- a/lib/strtod.c
+++ b/lib/strtod.c
@@ -283,9 +283,8 @@ parse_number (const char *nptr,
 
   /* Then, convert the digit sequence to a number.  */
   {
-    const char *dp;
     num = 0;
-    for (dp = digits_start; dp < digits_end; dp++)
+    for (const char *dp = digits_start; dp < digits_end; dp++)
       if (dp != radixchar_ptr)
         {
           int digit;
diff --git a/lib/strtol.c b/lib/strtol.c
index 0bcc6f40ec..954ba67a4a 100644
--- a/lib/strtol.c
+++ b/lib/strtol.c
@@ -217,7 +217,6 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr,
   register unsigned int cutlim;
   register unsigned LONG int i;
   register const STRING_TYPE *s;
-  register UCHAR_TYPE c;
   const STRING_TYPE *save, *end;
   int overflow;
 
@@ -307,7 +306,7 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr,
     {
       /* Find the end of the digit string and check its grouping.  */
       end = s;
-      for (c = *end; c != L_('\0'); c = *++end)
+      for (UCHAR_TYPE c = *end; c != L_('\0'); c = *++end)
         if ((wchar_t) c != thousands
             && ((wchar_t) c < L_('0') || (wchar_t) c > L_('9'))
             && (!ISALPHA (c) || (int) (TOUPPER (c) - L_('A') + 10) >= base))
@@ -326,7 +325,7 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr,
 
   overflow = 0;
   i = 0;
-  for (c = *s; c != L_('\0'); c = *++s)
+  for (UCHAR_TYPE c = *s; c != L_('\0'); c = *++s)
     {
       if (s == end)
         break;
diff --git a/lib/struniq.h b/lib/struniq.h
index 00446f6eb8..211b97a7ce 100644
--- a/lib/struniq.h
+++ b/lib/struniq.h
@@ -82,8 +82,7 @@ struniq (const char *string)
   size_t slot = hashcode % STRUNIQ_HASH_TABLE_SIZE;
   size_t size;
   struct struniq_hash_node *new_node;
-  struct struniq_hash_node *p;
-  for (p = struniq_hash_table[slot]; p != NULL; p = p->next)
+  for (struct struniq_hash_node *p = struniq_hash_table[slot]; p != NULL; p = p->next)
     if (streq (p->contents, string))
       return p->contents;
   size = strlen (string) + 1;
@@ -100,7 +99,7 @@ struniq (const char *string)
     if (mt) gl_lock_lock (struniq_lock);
     /* Check whether another thread already added the string while we were
        waiting on the lock.  */
-    for (p = struniq_hash_table[slot]; p != NULL; p = p->next)
+    for (struct struniq_hash_node *p = struniq_hash_table[slot]; p != NULL; p = p->next)
       if (streq (p->contents, string))
         {
           free (new_node);
diff --git a/lib/sys_select.in.h b/lib/sys_select.in.h
index 69c2fa9fc4..9106702deb 100644
--- a/lib/sys_select.in.h
+++ b/lib/sys_select.in.h
@@ -152,11 +152,10 @@ typedef int suseconds_t;
 static int
 rpl_fd_isset (SOCKET fd, const fd_set * set)
 {
-  u_int i;
   if (set == NULL)
     return 0;
 
-  for (i = 0; i < set->fd_count; i++)
+  for (u_int i = 0; i < set->fd_count; i++)
     if (set->fd_array[i] == fd)
       return 1;
 
diff --git a/lib/sys_socket.in.h b/lib/sys_socket.in.h
index 8632c66d0c..3d8935cda8 100644
--- a/lib/sys_socket.in.h
+++ b/lib/sys_socket.in.h
@@ -235,11 +235,10 @@ struct msghdr {
 _GL_SYS_SOCKET_INLINE int
 rpl_fd_isset (SOCKET fd, fd_set * set)
 {
-  u_int i;
   if (set == NULL)
     return 0;
 
-  for (i = 0; i < set->fd_count; i++)
+  for (u_int i = 0; i < set->fd_count; i++)
     if (set->fd_array[i] == fd)
       return 1;
 
diff --git a/lib/system-quote.c b/lib/system-quote.c
index bd963e8c72..e0c6bf04c9 100644
--- a/lib/system-quote.c
+++ b/lib/system-quote.c
@@ -79,12 +79,8 @@ windows_createprocess_quote (char *p, const char *string)
       char c = *string;
 
       if (c == '"')
-        {
-          size_t j;
-
-          for (j = backslashes + 1; j > 0; j--)
-            STORE ('\\');
-        }
+        for (size_t j = backslashes + 1; j > 0; j--)
+          STORE ('\\');
       STORE (c);
       if (c == '\\')
         backslashes++;
@@ -93,9 +89,7 @@ windows_createprocess_quote (char *p, const char *string)
     }
   if (quote_around)
     {
-      size_t j;
-
-      for (j = backslashes; j > 0; j--)
+      for (size_t j = backslashes; j > 0; j--)
         STORE ('\\');
       STORE ('"');
     }
@@ -146,17 +140,11 @@ windows_cmd_quote (char *p, const char *string)
       char c = *string;
 
       if (c == '"')
-        {
-          size_t j;
-
-          for (j = backslashes + 1; j > 0; j--)
-            STORE ('\\');
-        }
+        for (size_t j = backslashes + 1; j > 0; j--)
+          STORE ('\\');
       if (c == '%')
         {
-          size_t j;
-
-          for (j = backslashes; j > 0; j--)
+          for (size_t j = backslashes; j > 0; j--)
             STORE ('\\');
           STORE ('"');
         }
@@ -170,9 +158,7 @@ windows_cmd_quote (char *p, const char *string)
     }
   if (quote_around)
     {
-      size_t j;
-
-      for (j = backslashes; j > 0; j--)
+      for (size_t j = backslashes; j > 0; j--)
         STORE ('\\');
       STORE ('"');
     }
@@ -276,13 +262,12 @@ system_quote_argv (enum system_command_interpreter interpreter,
 {
   if (*argv != NULL)
     {
-      char * const *argp;
       size_t length;
       char *command;
       char *p;
 
       length = 0;
-      for (argp = argv; ; )
+      for (char * const *argp = argv; ; )
         {
           length += system_quote_length (interpreter, *argp) + 1;
           argp++;
@@ -293,7 +278,7 @@ system_quote_argv (enum system_command_interpreter interpreter,
       command = XNMALLOC (length, char);
 
       p = command;
-      for (argp = argv; ; )
+      for (char * const *argp = argv; ; )
         {
           p = system_quote_copy (p, interpreter, *argp);
           argp++;
diff --git a/lib/tempname.c b/lib/tempname.c
index cd6020c0f2..cd16daf333 100644
--- a/lib/tempname.c
+++ b/lib/tempname.c
@@ -191,7 +191,6 @@ try_tempname_len (char *tmpl, int suffixlen, void *args,
 {
   size_t len;
   char *XXXXXX;
-  unsigned int count;
   int fd = -1;
   int saved_errno = errno;
 
@@ -236,7 +235,7 @@ try_tempname_len (char *tmpl, int suffixlen, void *args,
   /* This is where the Xs start.  */
   XXXXXX = &tmpl[len - x_suffix_len - suffixlen];
 
-  for (count = 0; count < attempts; ++count)
+  for (unsigned int count = 0; count < attempts; ++count)
     {
       for (size_t i = 0; i < x_suffix_len; i++)
         {
diff --git a/lib/term-style-control.c b/lib/term-style-control.c
index 6307937ef3..54fdd0d140 100644
--- a/lib/term-style-control.c
+++ b/lib/term-style-control.c
@@ -555,15 +555,14 @@ init_relevant_signal_set ()
     {
       int fatal_signals[64];
       size_t num_fatal_signals;
-      size_t i;
 
       num_fatal_signals = get_fatal_signals (fatal_signals);
 
       sigemptyset (&relevant_signal_set);
-      for (i = 0; i < num_fatal_signals; i++)
+      for (size_t i = 0; i < num_fatal_signals; i++)
         sigaddset (&relevant_signal_set, fatal_signals[i]);
       #if defined SIGCONT
-      for (i = 0; i < num_job_control_signals; i++)
+      for (size_t i = 0; i < num_job_control_signals; i++)
         sigaddset (&relevant_signal_set, job_control_signals[i]);
       #endif
 
@@ -658,15 +657,13 @@ fatal_or_stopping_signal_handler (int sig)
   if (active_controller != NULL
       && active_control_data->tty_control != TTYCTL_NONE)
     {
-      unsigned int i;
-
       /* Block the relevant signals.  This is needed, because the output
          of escape sequences below (usually through tputs invocations) is
          not reentrant.  */
       block_relevant_signals ();
 
       /* Restore the terminal to the default state.  */
-      for (i = 0; i < 2; i++)
+      for (unsigned int i = 0; i < 2; i++)
         active_controller->async_restore (active_user_data);
       #if HAVE_TCGETATTR
       if (active_control_data->tty_control == TTYCTL_FULL)
@@ -735,27 +732,23 @@ continuing_signal_handler (int sigcont)
       && active_control_data->tty_control != TTYCTL_NONE)
     {
       /* Reinstall the signals handlers removed in stopping_signal_handler.  */
-      {
-        unsigned int i;
-
-        for (i = 0; i < num_job_control_signals; i++)
-          {
-            int sig = job_control_signals[i];
+      for (unsigned int i = 0; i < num_job_control_signals; i++)
+        {
+          int sig = job_control_signals[i];
 
-            if (sig != SIGCONT && !is_ignored (sig))
-              {
-                struct sigaction action;
-                action.sa_handler = &stopping_signal_handler;
-                /* If we get a stopping or continuing signal while executing
-                   stopping_signal_handler or continuing_signal_handler, enter
-                   it recursively, since it is reentrant.
-                   Hence no SA_RESETHAND.  */
-                action.sa_flags = SA_NODEFER;
-                sigemptyset (&action.sa_mask);
-                sigaction (sig, &action, NULL);
-              }
-          }
-      }
+          if (sig != SIGCONT && !is_ignored (sig))
+            {
+              struct sigaction action;
+              action.sa_handler = &stopping_signal_handler;
+              /* If we get a stopping or continuing signal while executing
+                 stopping_signal_handler or continuing_signal_handler, enter
+                 it recursively, since it is reentrant.
+                 Hence no SA_RESETHAND.  */
+              action.sa_flags = SA_NODEFER;
+              sigemptyset (&action.sa_mask);
+              sigaction (sig, &action, NULL);
+            }
+        }
 
       /* Block the relevant signals.  This is needed, because the output of
          escape sequences done inside the async_set_attributes_from_default
@@ -822,37 +815,33 @@ ensure_other_signal_handlers (void)
       #if defined SIGCONT
 
       /* Install the handlers for the stopping and continuing signals.  */
-      {
-        unsigned int i;
-
-        for (i = 0; i < num_job_control_signals; i++)
-          {
-            int sig = job_control_signals[i];
+      for (unsigned int i = 0; i < num_job_control_signals; i++)
+        {
+          int sig = job_control_signals[i];
 
-            if (sig == SIGCONT)
-              /* Already handled in ensure_continuing_signal_handler.  */
-              ;
-            else if (!is_ignored (sig))
-              {
-                struct sigaction action;
-                action.sa_handler = &stopping_signal_handler;
-                /* If we get a stopping or continuing signal while executing
-                   stopping_signal_handler, enter it recursively, since it is
-                   reentrant.  Hence no SA_RESETHAND.  */
-                action.sa_flags = SA_NODEFER;
-                sigemptyset (&action.sa_mask);
-                sigaction (sig, &action, NULL);
-              }
-            #if DEBUG_SIGNALS
-            else
-              {
-                fprintf (stderr, "Signal %d is ignored. Not installing a handler!\n",
-                         sig);
-                fflush (stderr);
-              }
-            #endif
-          }
-      }
+          if (sig == SIGCONT)
+            /* Already handled in ensure_continuing_signal_handler.  */
+            ;
+          else if (!is_ignored (sig))
+            {
+              struct sigaction action;
+              action.sa_handler = &stopping_signal_handler;
+              /* If we get a stopping or continuing signal while executing
+                 stopping_signal_handler, enter it recursively, since it is
+                 reentrant.  Hence no SA_RESETHAND.  */
+              action.sa_flags = SA_NODEFER;
+              sigemptyset (&action.sa_mask);
+              sigaction (sig, &action, NULL);
+            }
+          #if DEBUG_SIGNALS
+          else
+            {
+              fprintf (stderr, "Signal %d is ignored. Not installing a handler!\n",
+                       sig);
+              fflush (stderr);
+            }
+          #endif
+        }
 
       #endif
 
diff --git a/lib/tsearch.c b/lib/tsearch.c
index e5afbda283..4f180467f3 100644
--- a/lib/tsearch.c
+++ b/lib/tsearch.c
@@ -154,11 +154,10 @@ static void
 check_tree (node root)
 {
   int cnt = 0;
-  node p;
   if (root == NULL)
     return;
   root->red = 0;
-  for (p = root->left; p; p = p->left)
+  for (node p = root->left; p; p = p->left)
     cnt += !p->red;
   check_tree_recurse (root, 0, cnt);
 }
diff --git a/lib/unicase/u-casemap.h b/lib/unicase/u-casemap.h
index fba36655a9..7af1375c3e 100644
--- a/lib/unicase/u-casemap.h
+++ b/lib/unicase/u-casemap.h
@@ -281,15 +281,65 @@ FUNC (const UNIT *s, size_t n,
 
        found_mapping:
         /* Found the mapping: uc maps to mapped_uc[0..mapped_count-1].  */
-        {
-          unsigned int i;
+        for (unsigned int i = 0; i < mapped_count; i++)
+          {
+            ucs4_t muc = mapped_uc[i];
 
-          for (i = 0; i < mapped_count; i++)
+            /* Append muc to the result accumulator.  */
+            if (length < allocated)
+              {
+                int ret = U_UCTOMB (result + length, muc, allocated - length);
+                if (ret == -1)
+                  {
+                    errno = EINVAL;
+                    goto fail;
+                  }
+                if (ret >= 0)
+                  {
+                    length += ret;
+                    goto done_appending;
+                  }
+              }
             {
-              ucs4_t muc = mapped_uc[i];
-
-              /* Append muc to the result accumulator.  */
-              if (length < allocated)
+              size_t old_allocated = allocated;
+              size_t new_allocated = 2 * old_allocated;
+              if (new_allocated < 64)
+                new_allocated = 64;
+              if (new_allocated < old_allocated) /* integer overflow? */
+                abort ();
+              {
+                UNIT *larger_result;
+                if (result == NULL)
+                  {
+                    larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT));
+                    if (larger_result == NULL)
+                      {
+                        errno = ENOMEM;
+                        goto fail;
+                      }
+                  }
+                else if (result == resultbuf)
+                  {
+                    larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT));
+                    if (larger_result == NULL)
+                      {
+                        errno = ENOMEM;
+                        goto fail;
+                      }
+                    U_CPY (larger_result, resultbuf, length);
+                  }
+                else
+                  {
+                    larger_result =
+                      (UNIT *) realloc (result, new_allocated * sizeof (UNIT));
+                    if (larger_result == NULL)
+                      {
+                        errno = ENOMEM;
+                        goto fail;
+                      }
+                  }
+                result = larger_result;
+                allocated = new_allocated;
                 {
                   int ret = U_UCTOMB (result + length, muc, allocated - length);
                   if (ret == -1)
@@ -297,69 +347,15 @@ FUNC (const UNIT *s, size_t n,
                       errno = EINVAL;
                       goto fail;
                     }
-                  if (ret >= 0)
-                    {
-                      length += ret;
-                      goto done_appending;
-                    }
-                }
-              {
-                size_t old_allocated = allocated;
-                size_t new_allocated = 2 * old_allocated;
-                if (new_allocated < 64)
-                  new_allocated = 64;
-                if (new_allocated < old_allocated) /* integer overflow? */
-                  abort ();
-                {
-                  UNIT *larger_result;
-                  if (result == NULL)
-                    {
-                      larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT));
-                      if (larger_result == NULL)
-                        {
-                          errno = ENOMEM;
-                          goto fail;
-                        }
-                    }
-                  else if (result == resultbuf)
-                    {
-                      larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT));
-                      if (larger_result == NULL)
-                        {
-                          errno = ENOMEM;
-                          goto fail;
-                        }
-                      U_CPY (larger_result, resultbuf, length);
-                    }
-                  else
-                    {
-                      larger_result =
-                        (UNIT *) realloc (result, new_allocated * sizeof (UNIT));
-                      if (larger_result == NULL)
-                        {
-                          errno = ENOMEM;
-                          goto fail;
-                        }
-                    }
-                  result = larger_result;
-                  allocated = new_allocated;
-                  {
-                    int ret = U_UCTOMB (result + length, muc, allocated - length);
-                    if (ret == -1)
-                      {
-                        errno = EINVAL;
-                        goto fail;
-                      }
-                    if (ret < 0)
-                      abort ();
-                    length += ret;
-                    goto done_appending;
-                  }
+                  if (ret < 0)
+                    abort ();
+                  length += ret;
+                  goto done_appending;
                 }
               }
-             done_appending: ;
             }
-        }
+           done_appending: ;
+          }
 
         if (!uc_is_case_ignorable (uc))
           last_char_except_ignorable = uc;
diff --git a/lib/unicase/u-ct-totitle.h b/lib/unicase/u-ct-totitle.h
index 944287261b..dcefd0366b 100644
--- a/lib/unicase/u-ct-totitle.h
+++ b/lib/unicase/u-ct-totitle.h
@@ -357,15 +357,65 @@ FUNC (const UNIT *s, size_t n,
 
        found_mapping:
         /* Found the mapping: uc maps to mapped_uc[0..mapped_count-1].  */
-        {
-          unsigned int i;
+        for (unsigned int i = 0; i < mapped_count; i++)
+          {
+            ucs4_t muc = mapped_uc[i];
 
-          for (i = 0; i < mapped_count; i++)
+            /* Append muc to the result accumulator.  */
+            if (length < allocated)
+              {
+                int ret = U_UCTOMB (result + length, muc, allocated - length);
+                if (ret == -1)
+                  {
+                    errno = EINVAL;
+                    goto fail1;
+                  }
+                if (ret >= 0)
+                  {
+                    length += ret;
+                    goto done_appending;
+                  }
+              }
             {
-              ucs4_t muc = mapped_uc[i];
-
-              /* Append muc to the result accumulator.  */
-              if (length < allocated)
+              size_t old_allocated = allocated;
+              size_t new_allocated = 2 * old_allocated;
+              if (new_allocated < 64)
+                new_allocated = 64;
+              if (new_allocated < old_allocated) /* integer overflow? */
+                abort ();
+              {
+                UNIT *larger_result;
+                if (result == NULL)
+                  {
+                    larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT));
+                    if (larger_result == NULL)
+                      {
+                        errno = ENOMEM;
+                        goto fail1;
+                      }
+                  }
+                else if (result == resultbuf)
+                  {
+                    larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT));
+                    if (larger_result == NULL)
+                      {
+                        errno = ENOMEM;
+                        goto fail1;
+                      }
+                    U_CPY (larger_result, resultbuf, length);
+                  }
+                else
+                  {
+                    larger_result =
+                      (UNIT *) realloc (result, new_allocated * sizeof (UNIT));
+                    if (larger_result == NULL)
+                      {
+                        errno = ENOMEM;
+                        goto fail1;
+                      }
+                  }
+                result = larger_result;
+                allocated = new_allocated;
                 {
                   int ret = U_UCTOMB (result + length, muc, allocated - length);
                   if (ret == -1)
@@ -373,69 +423,15 @@ FUNC (const UNIT *s, size_t n,
                       errno = EINVAL;
                       goto fail1;
                     }
-                  if (ret >= 0)
-                    {
-                      length += ret;
-                      goto done_appending;
-                    }
-                }
-              {
-                size_t old_allocated = allocated;
-                size_t new_allocated = 2 * old_allocated;
-                if (new_allocated < 64)
-                  new_allocated = 64;
-                if (new_allocated < old_allocated) /* integer overflow? */
-                  abort ();
-                {
-                  UNIT *larger_result;
-                  if (result == NULL)
-                    {
-                      larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT));
-                      if (larger_result == NULL)
-                        {
-                          errno = ENOMEM;
-                          goto fail1;
-                        }
-                    }
-                  else if (result == resultbuf)
-                    {
-                      larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT));
-                      if (larger_result == NULL)
-                        {
-                          errno = ENOMEM;
-                          goto fail1;
-                        }
-                      U_CPY (larger_result, resultbuf, length);
-                    }
-                  else
-                    {
-                      larger_result =
-                        (UNIT *) realloc (result, new_allocated * sizeof (UNIT));
-                      if (larger_result == NULL)
-                        {
-                          errno = ENOMEM;
-                          goto fail1;
-                        }
-                    }
-                  result = larger_result;
-                  allocated = new_allocated;
-                  {
-                    int ret = U_UCTOMB (result + length, muc, allocated - length);
-                    if (ret == -1)
-                      {
-                        errno = EINVAL;
-                        goto fail1;
-                      }
-                    if (ret < 0)
-                      abort ();
-                    length += ret;
-                    goto done_appending;
-                  }
+                  if (ret < 0)
+                    abort ();
+                  length += ret;
+                  goto done_appending;
                 }
               }
-             done_appending: ;
             }
-        }
+           done_appending: ;
+          }
 
         if (!uc_is_case_ignorable (uc))
           last_char_except_ignorable = uc;
diff --git a/lib/uniconv/u-conv-from-enc.h b/lib/uniconv/u-conv-from-enc.h
index 32251c5e53..808726e0e3 100644
--- a/lib/uniconv/u-conv-from-enc.h
+++ b/lib/uniconv/u-conv-from-enc.h
@@ -40,9 +40,8 @@ FUNC (const char *fromcode,
     {
       /* Convert 'char *' offsets to 'UNIT *' offsets.  */
       size_t *offsets_end = offsets + srclen;
-      size_t *o;
 
-      for (o = offsets; o < offsets_end; o++)
+      for (size_t *o = offsets; o < offsets_end; o++)
         if (*o != (size_t)(-1))
           *o = *o / sizeof (UNIT);
     }
@@ -72,11 +71,10 @@ FUNC (const char *fromcode,
     {
       size_t length = *lengthp;
       size_t *offsets_end = offsets + srclen;
-      size_t *o;
       size_t off8 = 0;  /* offset into utf8_string */
       size_t offunit = 0;       /* offset into result */
 
-      for (o = offsets; o < offsets_end; o++)
+      for (size_t *o = offsets; o < offsets_end; o++)
         if (*o != (size_t)(-1))
           {
             while (off8 < *o)
diff --git a/lib/uniconv/u-conv-to-enc.h b/lib/uniconv/u-conv-to-enc.h
index e1a8532401..723e8207da 100644
--- a/lib/uniconv/u-conv-to-enc.h
+++ b/lib/uniconv/u-conv-to-enc.h
@@ -64,9 +64,7 @@ FUNC (const char *tocode,
     {
       /* Convert scaled_offsets[srclen * sizeof (UNIT)] to
          offsets[srclen].  */
-      size_t i;
-
-      for (i = 0; i < srclen; i++)
+      for (size_t i = 0; i < srclen; i++)
         offsets[i] = scaled_offsets[i * sizeof (UNIT)];
       free (scaled_offsets);
     }
@@ -122,12 +120,12 @@ FUNC (const char *tocode,
     }
   if (offsets != NULL)
     {
+      for (size_t iunit = 0; iunit < srclen; iunit++)
+        offsets[iunit] = (size_t)(-1);
+
       size_t iunit;     /* offset into src */
       size_t i8;        /* offset into utf8_src */
 
-      for (iunit = 0; iunit < srclen; iunit++)
-        offsets[iunit] = (size_t)(-1);
-
       iunit = 0;
       i8 = 0;
       while (iunit < srclen && i8 < utf8_srclen)
diff --git a/lib/uniconv/u8-conv-from-enc.c b/lib/uniconv/u8-conv-from-enc.c
index e292e9543f..57df9a3b60 100644
--- a/lib/uniconv/u8-conv-from-enc.c
+++ b/lib/uniconv/u8-conv-from-enc.c
@@ -48,21 +48,17 @@ u8_conv_from_encoding (const char *fromcode,
         }
 
       if (offsets != NULL)
-        {
-          size_t i;
-
-          for (i = 0; i < srclen; )
-            {
-              int count = u8_mblen ((const uint8_t *) src + i, srclen - i);
-              /* We can rely on count > 0 because of the previous u8_check.  */
-              if (count <= 0)
-                abort ();
-              offsets[i] = i;
-              i++;
-              while (--count > 0)
-                offsets[i++] = (size_t)(-1);
-            }
-        }
+        for (size_t i = 0; i < srclen; )
+          {
+            int count = u8_mblen ((const uint8_t *) src + i, srclen - i);
+            /* We can rely on count > 0 because of the previous u8_check.  */
+            if (count <= 0)
+              abort ();
+            offsets[i] = i;
+            i++;
+            while (--count > 0)
+              offsets[i++] = (size_t)(-1);
+          }
 
       /* Memory allocation.  */
       if (resultbuf != NULL && *lengthp >= srclen)
diff --git a/lib/unictype/3level.h b/lib/unictype/3level.h
index be8b9cf52a..b309253f6a 100644
--- a/lib/unictype/3level.h
+++ b/lib/unictype/3level.h
@@ -113,7 +113,7 @@ CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc, ELEMENT value)
   uint32_t index1 = wc >> (t->q + t->p);
   uint32_t index2 = (wc >> t->p) & ((1 << t->q) - 1);
   uint32_t index3 = wc & ((1 << t->p) - 1);
-  size_t i, i1, i2;
+  size_t i1, i2;
 
   if (value == CONCAT(TABLE,_get) (t, wc))
     return;
@@ -144,7 +144,7 @@ CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc, ELEMENT value)
         }
       i1 = t->level2_size << t->q;
       i2 = (t->level2_size + 1) << t->q;
-      for (i = i1; i < i2; i++)
+      for (size_t i = i1; i < i2; i++)
         t->level2[i] = EMPTY;
       t->level1[index1] = t->level2_size++;
     }
@@ -162,7 +162,7 @@ CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc, ELEMENT value)
         }
       i1 = t->level3_size << t->p;
       i2 = (t->level3_size + 1) << t->p;
-      for (i = i1; i < i2; i++)
+      for (size_t i = i1; i < i2; i++)
         t->level3[i] = DEFAULT;
       t->level2[index2] = t->level3_size++;
     }
@@ -178,22 +178,19 @@ static void
 CONCAT(TABLE,_iterate) (struct TABLE *t,
                         void (*fn) (uint32_t wc, ELEMENT value))
 {
-  uint32_t index1;
-  for (index1 = 0; index1 < t->level1_size; index1++)
+  for (uint32_t index1 = 0; index1 < t->level1_size; index1++)
     {
       uint32_t lookup1 = t->level1[index1];
       if (lookup1 != EMPTY)
         {
           uint32_t lookup1_shifted = lookup1 << t->q;
-          uint32_t index2;
-          for (index2 = 0; index2 < (1 << t->q); index2++)
+          for (uint32_t index2 = 0; index2 < (1 << t->q); index2++)
             {
               uint32_t lookup2 = t->level2[index2 + lookup1_shifted];
               if (lookup2 != EMPTY)
                 {
                   uint32_t lookup2_shifted = lookup2 << t->p;
-                  uint32_t index3;
-                  for (index3 = 0; index3 < (1 << t->p); index3++)
+                  for (uint32_t index3 = 0; index3 < (1 << t->p); index3++)
                     {
                       ELEMENT lookup3 = t->level3[index3 + lookup2_shifted];
                       if (lookup3 != DEFAULT)
@@ -212,15 +209,16 @@ CONCAT(TABLE,_iterate) (struct TABLE *t,
 static void
 CONCAT(TABLE,_finalize) (struct TABLE *t)
 {
-  size_t i, j, k;
+  size_t k;
   uint32_t reorder3[t->level3_size];
   uint32_t reorder2[t->level2_size];
   uint32_t level1_offset, level2_offset, level3_offset, last_offset;
 
   /* Uniquify level3 blocks.  */
   k = 0;
-  for (j = 0; j < t->level3_size; j++)
+  for (size_t j = 0; j < t->level3_size; j++)
     {
+      size_t i;
       for (i = 0; i < k; i++)
         if (memeq (&t->level3[i << t->p], &t->level3[j << t->p],
                    (1 << t->p) * sizeof (ELEMENT)))
@@ -237,14 +235,15 @@ CONCAT(TABLE,_finalize) (struct TABLE *t)
     }
   t->level3_size = k;
 
-  for (i = 0; i < (t->level2_size << t->q); i++)
+  for (size_t i = 0; i < (t->level2_size << t->q); i++)
     if (t->level2[i] != EMPTY)
       t->level2[i] = reorder3[t->level2[i]];
 
   /* Uniquify level2 blocks.  */
   k = 0;
-  for (j = 0; j < t->level2_size; j++)
+  for (size_t j = 0; j < t->level2_size; j++)
     {
+      size_t i;
       for (i = 0; i < k; i++)
         if (memeq (&t->level2[i << t->q], &t->level2[j << t->q],
                    (1 << t->q) * sizeof (uint32_t)))
@@ -261,7 +260,7 @@ CONCAT(TABLE,_finalize) (struct TABLE *t)
     }
   t->level2_size = k;
 
-  for (i = 0; i < t->level1_size; i++)
+  for (size_t i = 0; i < t->level1_size; i++)
     if (t->level1[i] != EMPTY)
       t->level1[i] = reorder2[t->level1[i]];
 
@@ -290,19 +289,19 @@ CONCAT(TABLE,_finalize) (struct TABLE *t)
   ((uint32_t *) t->result)[3] = (1 << t->q) - 1;
   ((uint32_t *) t->result)[4] = (1 << t->p) - 1;
 
-  for (i = 0; i < t->level1_size; i++)
+  for (size_t i = 0; i < t->level1_size; i++)
     ((uint32_t *) (t->result + level1_offset))[i] =
       (t->level1[i] == EMPTY
        ? 0
        : (t->level1[i] << t->q) * sizeof (uint32_t) + level2_offset);
 
-  for (i = 0; i < (t->level2_size << t->q); i++)
+  for (size_t i = 0; i < (t->level2_size << t->q); i++)
     ((uint32_t *) (t->result + level2_offset))[i] =
       (t->level2[i] == EMPTY
        ? 0
        : (t->level2[i] << t->p) * sizeof (ELEMENT) + level3_offset);
 
-  for (i = 0; i < (t->level3_size << t->p); i++)
+  for (size_t i = 0; i < (t->level3_size << t->p); i++)
     ((ELEMENT *) (t->result + level3_offset))[i] = t->level3[i];
 
   if (last_offset < t->result_size)
diff --git a/lib/unictype/3levelbit.h b/lib/unictype/3levelbit.h
index 981efa9699..0af9be9b71 100644
--- a/lib/unictype/3levelbit.h
+++ b/lib/unictype/3levelbit.h
@@ -112,7 +112,7 @@ CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc)
   uint32_t index2 = (wc >> (t->p + 5)) & ((1 << t->q) - 1);
   uint32_t index3 = (wc >> 5) & ((1 << t->p) - 1);
   uint32_t index4 = wc & 0x1f;
-  size_t i, i1, i2;
+  size_t i1, i2;
 
   if (index1 >= t->level1_size)
     {
@@ -140,7 +140,7 @@ CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc)
         }
       i1 = t->level2_size << t->q;
       i2 = (t->level2_size + 1) << t->q;
-      for (i = i1; i < i2; i++)
+      for (size_t i = i1; i < i2; i++)
         t->level2[i] = EMPTY;
       t->level1[index1] = t->level2_size++;
     }
@@ -158,7 +158,7 @@ CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc)
         }
       i1 = t->level3_size << t->p;
       i2 = (t->level3_size + 1) << t->p;
-      for (i = i1; i < i2; i++)
+      for (size_t i = i1; i < i2; i++)
         t->level3[i] = 0;
       t->level2[index2] = t->level3_size++;
     }
@@ -173,26 +173,22 @@ CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc)
 static void
 CONCAT(TABLE,_iterate) (struct TABLE *t, void (*fn) (uint32_t wc))
 {
-  uint32_t index1;
-  for (index1 = 0; index1 < t->level1_size; index1++)
+  for (uint32_t index1 = 0; index1 < t->level1_size; index1++)
     {
       uint32_t lookup1 = t->level1[index1];
       if (lookup1 != EMPTY)
         {
           uint32_t lookup1_shifted = lookup1 << t->q;
-          uint32_t index2;
-          for (index2 = 0; index2 < (1 << t->q); index2++)
+          for (uint32_t index2 = 0; index2 < (1 << t->q); index2++)
             {
               uint32_t lookup2 = t->level2[index2 + lookup1_shifted];
               if (lookup2 != EMPTY)
                 {
                   uint32_t lookup2_shifted = lookup2 << t->p;
-                  uint32_t index3;
-                  for (index3 = 0; index3 < (1 << t->p); index3++)
+                  for (uint32_t index3 = 0; index3 < (1 << t->p); index3++)
                     {
                       uint32_t lookup3 = t->level3[index3 + lookup2_shifted];
-                      uint32_t index4;
-                      for (index4 = 0; index4 < 32; index4++)
+                      for (uint32_t index4 = 0; index4 < 32; index4++)
                         if ((lookup3 >> index4) & 1)
                           fn ((((((index1 << t->q) + index2) << t->p) + index3) << 5) + index4);
                     }
@@ -208,15 +204,16 @@ CONCAT(TABLE,_iterate) (struct TABLE *t, void (*fn) (uint32_t wc))
 static void
 CONCAT(TABLE,_finalize) (struct TABLE *t)
 {
-  size_t i, j, k;
+  size_t k;
   uint32_t reorder3[t->level3_size];
   uint32_t reorder2[t->level2_size];
   uint32_t level1_offset, level2_offset, level3_offset;
 
   /* Uniquify level3 blocks.  */
   k = 0;
-  for (j = 0; j < t->level3_size; j++)
+  for (size_t j = 0; j < t->level3_size; j++)
     {
+      size_t i;
       for (i = 0; i < k; i++)
         if (memeq (&t->level3[i << t->p], &t->level3[j << t->p],
                    (1 << t->p) * sizeof (uint32_t)))
@@ -233,14 +230,15 @@ CONCAT(TABLE,_finalize) (struct TABLE *t)
     }
   t->level3_size = k;
 
-  for (i = 0; i < (t->level2_size << t->q); i++)
+  for (size_t i = 0; i < (t->level2_size << t->q); i++)
     if (t->level2[i] != EMPTY)
       t->level2[i] = reorder3[t->level2[i]];
 
   /* Uniquify level2 blocks.  */
   k = 0;
-  for (j = 0; j < t->level2_size; j++)
+  for (size_t j = 0; j < t->level2_size; j++)
     {
+      size_t i;
       for (i = 0; i < k; i++)
         if (memeq (&t->level2[i << t->q], &t->level2[j << t->q],
                    (1 << t->q) * sizeof (uint32_t)))
@@ -257,7 +255,7 @@ CONCAT(TABLE,_finalize) (struct TABLE *t)
     }
   t->level2_size = k;
 
-  for (i = 0; i < t->level1_size; i++)
+  for (size_t i = 0; i < t->level1_size; i++)
     if (t->level1[i] != EMPTY)
       t->level1[i] = reorder2[t->level1[i]];
 
@@ -285,19 +283,19 @@ CONCAT(TABLE,_finalize) (struct TABLE *t)
   ((uint32_t *) t->result)[3] = (1 << t->q) - 1;
   ((uint32_t *) t->result)[4] = (1 << t->p) - 1;
 
-  for (i = 0; i < t->level1_size; i++)
+  for (size_t i = 0; i < t->level1_size; i++)
     ((uint32_t *) (t->result + level1_offset))[i] =
       (t->level1[i] == EMPTY
        ? 0
        : (t->level1[i] << t->q) * sizeof (uint32_t) + level2_offset);
 
-  for (i = 0; i < (t->level2_size << t->q); i++)
+  for (size_t i = 0; i < (t->level2_size << t->q); i++)
     ((uint32_t *) (t->result + level2_offset))[i] =
       (t->level2[i] == EMPTY
        ? 0
        : (t->level2[i] << t->p) * sizeof (uint32_t) + level3_offset);
 
-  for (i = 0; i < (t->level3_size << t->p); i++)
+  for (size_t i = 0; i < (t->level3_size << t->p); i++)
     ((uint32_t *) (t->result + level3_offset))[i] = t->level3[i];
 
   if (t->level1_alloc > 0)
diff --git a/lib/unigbrk/ulc-grapheme-breaks.c b/lib/unigbrk/ulc-grapheme-breaks.c
index 779a59f023..9413bceacc 100644
--- a/lib/unigbrk/ulc-grapheme-breaks.c
+++ b/lib/unigbrk/ulc-grapheme-breaks.c
@@ -51,10 +51,8 @@ is_utf8_encoding (const char *encoding)
 static void
 ascii_grapheme_breaks (const char *s, size_t n, char *p)
 {
-  size_t i;
-
   p[0] = 1;
-  for (i = 1; i < n; i++)
+  for (size_t i = 1; i < n; i++)
     {
       bool is_ascii = c_isprint (s[i]) || c_isspace (s[i]);
       p[i] = is_ascii && (s[i] != '\n' || s[i - 1] != '\r');
@@ -103,14 +101,12 @@ ulc_grapheme_breaks (const char *s, size_t n, char *p)
 
                   if (m == 0 || q != NULL)
                     {
-                      size_t i;
-
                       /* Determine the grapheme breaks of the UTF-8 string.  */
                       u8_grapheme_breaks (t, m, q);
 
                       /* Translate the result back to the original string.  */
                       memset (p, 0, n);
-                      for (i = 0; i < n; i++)
+                      for (size_t i = 0; i < n; i++)
                         if (offsets[i] != (size_t)(-1))
                           p[i] = q[offsets[i]];
 
diff --git a/lib/unilbrk/u8-possible-linebreaks.c b/lib/unilbrk/u8-possible-linebreaks.c
index bc4796f407..e895304a0f 100644
--- a/lib/unilbrk/u8-possible-linebreaks.c
+++ b/lib/unilbrk/u8-possible-linebreaks.c
@@ -505,11 +505,10 @@ main (int argc, char * argv[])
       char *input = read_file (stdin);
       int length = strlen (input);
       char *breaks = malloc (length);
-      int i;
 
       u8_possible_linebreaks_v2 ((uint8_t *) input, length, "UTF-8", breaks);
 
-      for (i = 0; i < length; i++)
+      for (int i = 0; i < length; i++)
         {
           switch (breaks[i])
             {
diff --git a/lib/unilbrk/u8-width-linebreaks.c b/lib/unilbrk/u8-width-linebreaks.c
index 0cb18ba01e..192f2e6583 100644
--- a/lib/unilbrk/u8-width-linebreaks.c
+++ b/lib/unilbrk/u8-width-linebreaks.c
@@ -212,11 +212,10 @@ main (int argc, char * argv[])
       char *input = read_file (stdin);
       int length = strlen (input);
       char *breaks = malloc (length);
-      int i;
 
       u8_width_linebreaks_v2 ((uint8_t *) input, length, width, 0, 0, NULL, "UTF-8", breaks);
 
-      for (i = 0; i < length; i++)
+      for (int i = 0; i < length; i++)
         {
           switch (breaks[i])
             {
diff --git a/lib/unilbrk/ulc-possible-linebreaks.c b/lib/unilbrk/ulc-possible-linebreaks.c
index 0dc1ff410f..852e8ab3cf 100644
--- a/lib/unilbrk/ulc-possible-linebreaks.c
+++ b/lib/unilbrk/ulc-possible-linebreaks.c
@@ -77,15 +77,13 @@ ulc_possible_linebreaks_internal (const char *s, size_t n, const char *encoding,
 
                   if (m == 0 || q != NULL)
                     {
-                      size_t i;
-
                       /* Determine the possible line breaks of the UTF-8
                          string.  */
                       u8_possible_linebreaks_loop (t, m, encoding, cr, q);
 
                       /* Translate the result back to the original string.  */
                       memset (p, UC_BREAK_PROHIBITED, n);
-                      for (i = 0; i < n; i++)
+                      for (size_t i = 0; i < n; i++)
                         if (offsets[i] != (size_t)(-1))
                           p[i] = q[offsets[i]];
 
@@ -218,11 +216,10 @@ main (int argc, char * argv[])
       char *input = read_file (stdin);
       int length = strlen (input);
       char *breaks = malloc (length);
-      int i;
 
       ulc_possible_linebreaks_v2 (input, length, locale_charset (), breaks);
 
-      for (i = 0; i < length; i++)
+      for (int i = 0; i < length; i++)
         {
           switch (breaks[i])
             {
diff --git a/lib/unilbrk/ulc-width-linebreaks.c b/lib/unilbrk/ulc-width-linebreaks.c
index ee3a394a9b..dcce0c774d 100644
--- a/lib/unilbrk/ulc-width-linebreaks.c
+++ b/lib/unilbrk/ulc-width-linebreaks.c
@@ -83,13 +83,12 @@ ulc_width_linebreaks_internal (const char *s, size_t n,
                       char *q = (char *) memory;
                       char *o8 = (o != NULL ? (char *) (q + m) : NULL);
                       int res_column;
-                      size_t i;
 
                       /* Translate the overrides to the UTF-8 string.  */
                       if (o != NULL)
                         {
                           memset (o8, UC_BREAK_UNDEFINED, m);
-                          for (i = 0; i < n; i++)
+                          for (size_t i = 0; i < n; i++)
                             if (offsets[i] != (size_t)(-1))
                               o8[offsets[i]] = o[i];
                         }
@@ -100,7 +99,7 @@ ulc_width_linebreaks_internal (const char *s, size_t n,
 
                       /* Translate the result back to the original string.  */
                       memset (p, UC_BREAK_PROHIBITED, n);
-                      for (i = 0; i < n; i++)
+                      for (size_t i = 0; i < n; i++)
                         if (offsets[i] != (size_t)(-1))
                           p[i] = q[offsets[i]];
 
@@ -245,11 +244,10 @@ main (int argc, char * argv[])
       char *input = read_file (stdin);
       int length = strlen (input);
       char *breaks = malloc (length);
-      int i;
 
       ulc_width_linebreaks_v2 (input, length, width, 0, 0, NULL, locale_charset (), breaks);
 
-      for (i = 0; i < length; i++)
+      for (int i = 0; i < length; i++)
         {
           switch (breaks[i])
             {
diff --git a/lib/uniname/uniname.c b/lib/uniname/uniname.c
index 953b70df06..0a4157ed0c 100644
--- a/lib/uniname/uniname.c
+++ b/lib/uniname/uniname.c
@@ -272,13 +272,12 @@ unicode_character_name (ucs4_t c, char *buf)
       /* Special case for CJK compatibility ideographs. Keeps the tables
          small.  */
       char *ptr;
-      int i;
 
       /* buf needs to have at least 28 + 5 + 1 bytes here.  */
       memcpy (buf, "CJK COMPATIBILITY IDEOGRAPH-", 28);
       ptr = buf + 28;
 
-      for (i = (c < 0x10000 ? 12 : 16); i >= 0; i -= 4)
+      for (int i = (c < 0x10000 ? 12 : 16); i >= 0; i -= 4)
         {
           unsigned int x = (c >> i) & 0xf;
           *ptr++ = (x < 10 ? '0' : 'A' - 10) + x;
@@ -482,21 +481,15 @@ unicode_name_character (const char *name)
 
                           if (n1 <= 2 && (n2 >= 1 && n2 <= 3) && n3 <= 2)
                             {
-                              unsigned int index1;
-
-                              for (index1 = 0; index1 < 19; index1++)
+                              for (unsigned int index1 = 0; index1 < 19; index1++)
                                 if (memeq (jamo_initial_short_name[index1], p1, n1)
                                     && jamo_initial_short_name[index1][n1] == '\0')
                                   {
-                                    unsigned int index2;
-
-                                    for (index2 = 0; index2 < 21; index2++)
+                                    for (unsigned int index2 = 0; index2 < 21; index2++)
                                       if (memeq (jamo_medial_short_name[index2], p2, n2)
                                           && jamo_medial_short_name[index2][n2] == '\0')
                                         {
-                                          unsigned int index3;
-
-                                          for (index3 = 0; index3 < 28; index3++)
+                                          for (unsigned int index3 = 0; index3 < 28; index3++)
                                             if (memeq (jamo_final_short_name[index3], p3, n3)
                                                 && jamo_final_short_name[index3][n3] == '\0')
                                               {
diff --git a/lib/uninorm/u-normalize-internal.h b/lib/uninorm/u-normalize-internal.h
index f910f52f5d..23b36f4295 100644
--- a/lib/uninorm/u-normalize-internal.h
+++ b/lib/uninorm/u-normalize-internal.h
@@ -73,46 +73,40 @@ FUNC (uninorm_t nf, const UNIT *s, size_t n,
                the size of the decomposition tables, because for example for
                U+1FC1 the recursive canonical decomposition and the recursive
                compatibility decomposition are different.  */
-            {
-              int curr;
-
-              for (curr = 0; curr < decomposed_count; )
-                {
-                  /* Invariant: decomposed[0..curr-1] is fully decomposed, i.e.
-                     all elements are atomic.  */
-                  ucs4_t curr_decomposed[UC_DECOMPOSITION_MAX_LENGTH];
-                  int curr_decomposed_count;
-
-                  curr_decomposed_count = decomposer (decomposed[curr], curr_decomposed);
-                  if (curr_decomposed_count >= 0)
-                    {
-                      /* Move curr_decomposed[0..curr_decomposed_count-1] over
-                         decomposed[curr], making room.  It's not worth using
-                         memcpy() here, since the counts are so small.  */
-                      int shift = curr_decomposed_count - 1;
-
-                      if (shift < 0)
-                        abort ();
-                      if (shift > 0)
-                        {
-                          int j;
+            for (int curr = 0; curr < decomposed_count; )
+              {
+                /* Invariant: decomposed[0..curr-1] is fully decomposed, i.e.
+                   all elements are atomic.  */
+                ucs4_t curr_decomposed[UC_DECOMPOSITION_MAX_LENGTH];
+                int curr_decomposed_count;
 
-                          decomposed_count += shift;
-                          if (decomposed_count > UC_DECOMPOSITION_MAX_LENGTH)
-                            abort ();
-                          for (j = decomposed_count - 1 - shift; j > curr; j--)
-                            decomposed[j + shift] = decomposed[j];
-                        }
-                      for (; shift >= 0; shift--)
-                        decomposed[curr + shift] = curr_decomposed[shift];
-                    }
-                  else
-                    {
-                      /* decomposed[curr] is atomic.  */
-                      curr++;
-                    }
-                }
-            }
+                curr_decomposed_count = decomposer (decomposed[curr], curr_decomposed);
+                if (curr_decomposed_count >= 0)
+                  {
+                    /* Move curr_decomposed[0..curr_decomposed_count-1] over
+                       decomposed[curr], making room.  It's not worth using
+                       memcpy() here, since the counts are so small.  */
+                    int shift = curr_decomposed_count - 1;
+
+                    if (shift < 0)
+                      abort ();
+                    if (shift > 0)
+                      {
+                        decomposed_count += shift;
+                        if (decomposed_count > UC_DECOMPOSITION_MAX_LENGTH)
+                          abort ();
+                        for (int j = decomposed_count - 1 - shift; j > curr; j--)
+                          decomposed[j + shift] = decomposed[j];
+                      }
+                    for (; shift >= 0; shift--)
+                      decomposed[curr + shift] = curr_decomposed[shift];
+                  }
+                else
+                  {
+                    /* decomposed[curr] is atomic.  */
+                    curr++;
+                  }
+              }
           }
         else
           {
@@ -143,8 +137,6 @@ FUNC (uninorm_t nf, const UNIT *s, size_t n,
 
             if (ccc == 0)
               {
-                size_t j;
-
                 /* Apply the canonical ordering algorithm to the accumulated
                    sequence of characters.  */
                 if (sortbuf_count > 1)
@@ -175,7 +167,7 @@ FUNC (uninorm_t nf, const UNIT *s, size_t n,
                             (also a starter).  */
                     if (sortbuf_count > 0 && sortbuf[0].ccc == 0)
                       {
-                        for (j = 1; j < sortbuf_count; )
+                        for (size_t j = 1; j < sortbuf_count; )
                           {
                             if (sortbuf[j].ccc > sortbuf[j - 1].ccc)
                               {
@@ -183,11 +175,9 @@ FUNC (uninorm_t nf, const UNIT *s, size_t n,
                                   composer (sortbuf[0].code, sortbuf[j].code);
                                 if (combined)
                                   {
-                                    size_t k;
-
                                     sortbuf[0].code = combined;
                                     /* sortbuf[0].ccc = 0, still valid.  */
-                                    for (k = j + 1; k < sortbuf_count; k++)
+                                    for (size_t k = j + 1; k < sortbuf_count; k++)
                                       sortbuf[k - 1] = sortbuf[k];
                                     sortbuf_count--;
                                     continue;
@@ -212,7 +202,7 @@ FUNC (uninorm_t nf, const UNIT *s, size_t n,
                       }
                   }
 
-                for (j = 0; j < sortbuf_count; j++)
+                for (size_t j = 0; j < sortbuf_count; j++)
                   {
                     ucs4_t muc = sortbuf[j].code;
 
diff --git a/lib/uninorm/uninorm-filter.c b/lib/uninorm/uninorm-filter.c
index 542013d6be..4d39019d8e 100644
--- a/lib/uninorm/uninorm-filter.c
+++ b/lib/uninorm/uninorm-filter.c
@@ -95,55 +95,48 @@ uninorm_filter_write (struct uninorm_filter *filter, ucs4_t uc_arg)
      the size of the decomposition tables, because for example for
      U+1FC1 the recursive canonical decomposition and the recursive
      compatibility decomposition are different.  */
-  {
-    int curr;
-
-    for (curr = 0; curr < decomposed_count; )
-      {
-        /* Invariant: decomposed[0..curr-1] is fully decomposed, i.e.
-           all elements are atomic.  */
-        ucs4_t curr_decomposed[UC_DECOMPOSITION_MAX_LENGTH];
-        int curr_decomposed_count;
-
-        curr_decomposed_count =
-          filter->decomposer (decomposed[curr], curr_decomposed);
-        if (curr_decomposed_count >= 0)
-          {
-            /* Move curr_decomposed[0..curr_decomposed_count-1] over
-               decomposed[curr], making room.  It's not worth using
-               memcpy() here, since the counts are so small.  */
-            int shift = curr_decomposed_count - 1;
-
-            if (shift < 0)
-              abort ();
-            if (shift > 0)
-              {
-                int j;
-
-                decomposed_count += shift;
-                if (decomposed_count > UC_DECOMPOSITION_MAX_LENGTH)
-                  abort ();
-                for (j = decomposed_count - 1 - shift; j > curr; j--)
-                  decomposed[j + shift] = decomposed[j];
-              }
-            for (; shift >= 0; shift--)
-              decomposed[curr + shift] = curr_decomposed[shift];
-          }
-        else
-          {
-            /* decomposed[curr] is atomic.  */
-            curr++;
-          }
-      }
-  }
+  for (int curr = 0; curr < decomposed_count; )
+    {
+      /* Invariant: decomposed[0..curr-1] is fully decomposed, i.e.
+         all elements are atomic.  */
+      ucs4_t curr_decomposed[UC_DECOMPOSITION_MAX_LENGTH];
+      int curr_decomposed_count;
+
+      curr_decomposed_count =
+        filter->decomposer (decomposed[curr], curr_decomposed);
+      if (curr_decomposed_count >= 0)
+        {
+          /* Move curr_decomposed[0..curr_decomposed_count-1] over
+             decomposed[curr], making room.  It's not worth using
+             memcpy() here, since the counts are so small.  */
+          int shift = curr_decomposed_count - 1;
+
+          if (shift < 0)
+            abort ();
+          if (shift > 0)
+            {
+              decomposed_count += shift;
+              if (decomposed_count > UC_DECOMPOSITION_MAX_LENGTH)
+                abort ();
+              for (int j = decomposed_count - 1 - shift; j > curr; j--)
+                decomposed[j + shift] = decomposed[j];
+            }
+          for (; shift >= 0; shift--)
+            decomposed[curr + shift] = curr_decomposed[shift];
+        }
+      else
+        {
+          /* decomposed[curr] is atomic.  */
+          curr++;
+        }
+    }
 
   {
     /* Cache sortbuf and sortbuf_count in local register variables.  */
     struct ucs4_with_ccc *sortbuf = filter->sortbuf;
     size_t sortbuf_count = filter->sortbuf_count;
-    int i;
 
-    for (i = 0; i < decomposed_count; i++)
+    for (int i = 0; i < decomposed_count; i++)
       {
         /* Fetch the next character from the decomposition.  */
         ucs4_t uc = decomposed[i];
@@ -151,8 +144,6 @@ uninorm_filter_write (struct uninorm_filter *filter, ucs4_t uc_arg)
 
         if (ccc == 0)
           {
-            size_t j;
-
             /* Apply the canonical ordering algorithm to the accumulated
                sequence of characters.  */
             if (sortbuf_count > 1)
@@ -183,7 +174,7 @@ uninorm_filter_write (struct uninorm_filter *filter, ucs4_t uc_arg)
                         (also a starter).  */
                 if (sortbuf_count > 0 && sortbuf[0].ccc == 0)
                   {
-                    for (j = 1; j < sortbuf_count; )
+                    for (size_t j = 1; j < sortbuf_count; )
                       {
                         if (sortbuf[j].ccc > sortbuf[j - 1].ccc)
                           {
@@ -191,11 +182,9 @@ uninorm_filter_write (struct uninorm_filter *filter, ucs4_t uc_arg)
                               filter->composer (sortbuf[0].code, sortbuf[j].code);
                             if (combined)
                               {
-                                size_t k;
-
                                 sortbuf[0].code = combined;
                                 /* sortbuf[0].ccc = 0, still valid.  */
-                                for (k = j + 1; k < sortbuf_count; k++)
+                                for (size_t k = j + 1; k < sortbuf_count; k++)
                                   sortbuf[k - 1] = sortbuf[k];
                                 sortbuf_count--;
                                 continue;
@@ -220,7 +209,7 @@ uninorm_filter_write (struct uninorm_filter *filter, ucs4_t uc_arg)
                   }
               }
 
-            for (j = 0; j < sortbuf_count; j++)
+            for (size_t j = 0; j < sortbuf_count; j++)
               {
                 ucs4_t muc = sortbuf[j].code;
 
@@ -286,7 +275,6 @@ uninorm_filter_flush (struct uninorm_filter *filter)
   /* Cache sortbuf and sortbuf_count in local register variables.  */
   struct ucs4_with_ccc * const sortbuf = filter->sortbuf;
   size_t sortbuf_count = filter->sortbuf_count;
-  size_t j;
 
   /* Apply the canonical ordering algorithm to the accumulated
      sequence of characters.  */
@@ -318,7 +306,7 @@ uninorm_filter_flush (struct uninorm_filter *filter)
               (also a starter).  */
       if (sortbuf_count > 0 && sortbuf[0].ccc == 0)
         {
-          for (j = 1; j < sortbuf_count; )
+          for (size_t j = 1; j < sortbuf_count; )
             {
               if (sortbuf[j].ccc > sortbuf[j - 1].ccc)
                 {
@@ -326,11 +314,9 @@ uninorm_filter_flush (struct uninorm_filter *filter)
                     filter->composer (sortbuf[0].code, sortbuf[j].code);
                   if (combined)
                     {
-                      size_t k;
-
                       sortbuf[0].code = combined;
                       /* sortbuf[0].ccc = 0, still valid.  */
-                      for (k = j + 1; k < sortbuf_count; k++)
+                      for (size_t k = j + 1; k < sortbuf_count; k++)
                         sortbuf[k - 1] = sortbuf[k];
                       sortbuf_count--;
                       continue;
@@ -341,7 +327,7 @@ uninorm_filter_flush (struct uninorm_filter *filter)
         }
     }
 
-  for (j = 0; j < sortbuf_count; j++)
+  for (size_t j = 0; j < sortbuf_count; j++)
     {
       ucs4_t muc = sortbuf[j].code;
 
diff --git a/lib/uniwbrk/u8-wordbreaks.c b/lib/uniwbrk/u8-wordbreaks.c
index a5c3d2edeb..5d8d04084f 100644
--- a/lib/uniwbrk/u8-wordbreaks.c
+++ b/lib/uniwbrk/u8-wordbreaks.c
@@ -102,11 +102,10 @@ main (int argc, char * argv[])
       char *input = read_file (stdin);
       int length = strlen (input);
       char *breaks = malloc (length);
-      int i;
 
       u8_wordbreaks ((uint8_t *) input, length, breaks);
 
-      for (i = 0; i < length; i++)
+      for (int i = 0; i < length; i++)
         {
           switch (breaks[i])
             {
diff --git a/lib/uniwbrk/ulc-wordbreaks.c b/lib/uniwbrk/ulc-wordbreaks.c
index d73bd4578c..006bea067d 100644
--- a/lib/uniwbrk/ulc-wordbreaks.c
+++ b/lib/uniwbrk/ulc-wordbreaks.c
@@ -77,14 +77,12 @@ ulc_wordbreaks (const char *s, size_t n, char *p)
 
                   if (m == 0 || q != NULL)
                     {
-                      size_t i;
-
                       /* Determine the word breaks of the UTF-8 string.  */
                       u8_wordbreaks (t, m, q);
 
                       /* Translate the result back to the original string.  */
                       memset (p, 0, n);
-                      for (i = 0; i < n; i++)
+                      for (size_t i = 0; i < n; i++)
                         if (offsets[i] != (size_t)(-1))
                           p[i] = q[offsets[i]];
 
@@ -179,11 +177,10 @@ main (int argc, char * argv[])
       char *input = read_file (stdin);
       int length = strlen (input);
       char *breaks = malloc (length);
-      int i;
 
       ulc_wordbreaks (input, length, breaks);
 
-      for (i = 0; i < length; i++)
+      for (int i = 0; i < length; i++)
         {
           switch (breaks[i])
             {
diff --git a/lib/userspec.c b/lib/userspec.c
index 7c5088eb06..79ac0cf2b8 100644
--- a/lib/userspec.c
+++ b/lib/userspec.c
@@ -301,9 +301,7 @@ parse_user_spec (char const *spec, uid_t *uid, gid_t *gid,
 int
 main (int argc, char **argv)
 {
-  int i;
-
-  for (i = 1; i < argc; i++)
+  for (int i = 1; i < argc; i++)
     {
       const char *e;
       char *username, *groupname;
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 5ca73e92a7..2b77f077c7 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -739,19 +739,18 @@ multiply (mpn_t src1, mpn_t src2, mpn_t *dest)
       /* Here 1 <= len1 <= len2.  */
       size_t dlen;
       mp_limb_t *dp;
-      size_t k, i, j;
 
       dlen = len1 + len2;
       dp = (mp_limb_t *) malloc (dlen * sizeof (mp_limb_t));
       if (dp == NULL)
         return NOMEM_PTR;
-      for (k = len2; k > 0; )
+      for (size_t k = len2; k > 0; )
         dp[--k] = 0;
-      for (i = 0; i < len1; i++)
+      for (size_t i = 0; i < len1; i++)
         {
           mp_limb_t digit1 = p1[i];
           mp_twolimb_t carry = 0;
-          for (j = 0; j < len2; j++)
+          for (size_t j = 0; j < len2; j++)
             {
               mp_limb_t digit2 = p2[j];
               carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2;
@@ -887,8 +886,7 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
         mp_limb_t remainder = 0;
         const mp_limb_t *sourceptr = a_ptr + a_len;
         mp_limb_t *destptr = q_ptr + a_len;
-        size_t count;
-        for (count = a_len; count > 0; count--)
+        for (size_t count = a_len; count > 0; count--)
           {
             mp_twolimb_t num =
               ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--sourceptr;
@@ -989,8 +987,7 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
             const mp_limb_t *sourceptr = b_ptr;
             mp_limb_t *destptr = tmp_roomptr;
             mp_twolimb_t accu = 0;
-            size_t count;
-            for (count = b_len; count > 0; count--)
+            for (size_t count = b_len; count > 0; count--)
               {
                 accu += (mp_twolimb_t) *sourceptr++ << s;
                 *destptr++ = (mp_limb_t) accu;
@@ -1017,8 +1014,7 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
           const mp_limb_t *sourceptr = a_ptr;
           mp_limb_t *destptr = r_ptr;
           mp_twolimb_t accu = 0;
-          size_t count;
-          for (count = a_len; count > 0; count--)
+          for (size_t count = a_len; count > 0; count--)
             {
               accu += (mp_twolimb_t) *sourceptr++ << s;
               *destptr++ = (mp_limb_t) accu;
@@ -1094,8 +1090,7 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
                   const mp_limb_t *sourceptr = b_ptr;
                   mp_limb_t *destptr = r_ptr + j;
                   mp_twolimb_t carry = 0;
-                  size_t count;
-                  for (count = b_len; count > 0; count--)
+                  for (size_t count = b_len; count > 0; count--)
                     {
                       /* Here 0 <= carry <= q*.  */
                       carry =
@@ -1119,8 +1114,7 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
                       const mp_limb_t *sourceptr = b_ptr;
                       mp_limb_t *destptr = r_ptr + j;
                       mp_limb_t carry = 0;
-                      size_t count;
-                      for (count = b_len; count > 0; count--)
+                      for (size_t count = b_len; count > 0; count--)
                         {
                           mp_limb_t source1 = *sourceptr++;
                           mp_limb_t source2 = *destptr;
@@ -1152,8 +1146,7 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
         {
           mp_limb_t ptr = r_ptr + r_len;
           mp_twolimb_t accu = 0;
-          size_t count;
-          for (count = r_len; count > 0; count--)
+          for (size_t count = r_len; count > 0; count--)
             {
               accu = (mp_twolimb_t) (mp_limb_t) accu << GMP_LIMB_BITS;
               accu += (mp_twolimb_t) *--ptr << (GMP_LIMB_BITS - s);
@@ -1168,29 +1161,25 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
   /* Compare r << 1 with b.  */
   if (r_len > b_len)
     goto increment_q;
-  {
-    size_t i;
-    for (i = b_len;;)
-      {
-        mp_limb_t r_i =
-          (i <= r_len && i > 0 ? r_ptr[i - 1] >> (GMP_LIMB_BITS - 1) : 0)
-          | (i < r_len ? r_ptr[i] << 1 : 0);
-        mp_limb_t b_i = (i < b_len ? b_ptr[i] : 0);
-        if (r_i > b_i)
-          goto increment_q;
-        if (r_i < b_i)
-          goto keep_q;
-        if (i == 0)
-          break;
-        i--;
-      }
-  }
+  for (size_t i = b_len;;)
+    {
+      mp_limb_t r_i =
+        (i <= r_len && i > 0 ? r_ptr[i - 1] >> (GMP_LIMB_BITS - 1) : 0)
+        | (i < r_len ? r_ptr[i] << 1 : 0);
+      mp_limb_t b_i = (i < b_len ? b_ptr[i] : 0);
+      if (r_i > b_i)
+        goto increment_q;
+      if (r_i < b_i)
+        goto keep_q;
+      if (i == 0)
+        break;
+      i--;
+    }
   if (q_len > 0 && ((q_ptr[0] & 1) != 0))
     /* q is odd.  */
     increment_q:
     {
-      size_t i;
-      for (i = 0; i < q_len; i++)
+      for (size_t i = 0; i < q_len; i++)
         if (++(q_ptr[i]) != 0)
           goto keep_q;
       q_ptr[q_len++] = 1;
@@ -1236,8 +1225,7 @@ convert_to_decimal (mpn_t a, size_t extra_zeroes)
           /* Divide a by 10^9, in-place.  */
           mp_limb_t remainder = 0;
           mp_limb_t *ptr = a_ptr + a_len;
-          size_t count;
-          for (count = a_len; count > 0; count--)
+          for (size_t count = a_len; count > 0; count--)
             {
               mp_twolimb_t num =
                 ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--ptr;
@@ -1245,7 +1233,7 @@ convert_to_decimal (mpn_t a, size_t extra_zeroes)
               remainder = num % 1000000000;
             }
           /* Store the remainder as 9 decimal digits.  */
-          for (count = 9; count > 0; count--)
+          for (size_t count = 9; count > 0; count--)
             {
               *d_ptr++ = '0' + (remainder % 10);
               remainder = remainder / 10;
@@ -1282,7 +1270,6 @@ decode_long_double (long double x, int *ep, mpn_t *mp)
   mpn_t m;
   int exp;
   long double y;
-  size_t i;
 
   /* Allocate memory for result.  */
   m.nlimbs = (LDBL_MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS;
@@ -1328,7 +1315,7 @@ decode_long_double (long double x, int *ep, mpn_t *mp)
     }
 #   endif
 #  endif
-  for (i = LDBL_MANT_BIT / GMP_LIMB_BITS; i > 0; )
+  for (size_t i = LDBL_MANT_BIT / GMP_LIMB_BITS; i > 0; )
     {
       mp_limb_t hi, lo;
       y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
@@ -1370,7 +1357,6 @@ decode_double (double x, int *ep, mpn_t *mp)
   mpn_t m;
   int exp;
   double y;
-  size_t i;
 
   /* Allocate memory for result.  */
   m.nlimbs = (DBL_MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS;
@@ -1416,7 +1402,7 @@ decode_double (double x, int *ep, mpn_t *mp)
     }
 #   endif
 #  endif
-  for (i = DBL_MANT_BIT / GMP_LIMB_BITS; i > 0; )
+  for (size_t i = DBL_MANT_BIT / GMP_LIMB_BITS; i > 0; )
     {
       mp_limb_t hi, lo;
       y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
@@ -1502,13 +1488,11 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
           1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625,
           48828125, 244140625, 1220703125
         };
-      unsigned int n13;
-      for (n13 = 0; n13 <= abs_n; n13 += 13)
+      for (unsigned int n13 = 0; n13 <= abs_n; n13 += 13)
         {
           mp_limb_t digit1 = small_pow5[n13 + 13 <= abs_n ? 13 : abs_n - n13];
-          size_t j;
           mp_twolimb_t carry = 0;
-          for (j = 0; j < pow5_len; j++)
+          for (size_t j = 0; j < pow5_len; j++)
             {
               mp_limb_t digit2 = pow5_ptr[j];
               carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2;
@@ -1528,8 +1512,7 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
         {
           mp_limb_t *ptr = pow5_ptr;
           mp_twolimb_t accu = 0;
-          size_t count;
-          for (count = pow5_len; count > 0; count--)
+          for (size_t count = pow5_len; count > 0; count--)
             {
               accu += (mp_twolimb_t) *ptr << s_bits;
               *ptr++ = (mp_limb_t) accu;
@@ -1543,13 +1526,12 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
         }
       if (s_limbs > 0)
         {
-          size_t count;
-          for (count = pow5_len; count > 0;)
+          for (size_t count = pow5_len; count > 0;)
             {
               count--;
               pow5_ptr[s_limbs + count] = pow5_ptr[count];
             }
-          for (count = s_limbs; count > 0;)
+          for (size_t count = s_limbs; count > 0;)
             {
               count--;
               pow5_ptr[count] = 0;
@@ -1590,8 +1572,7 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
           /* Construct 2^|s|.  */
           {
             mp_limb_t *ptr = pow5_ptr + pow5_len;
-            size_t i;
-            for (i = 0; i < s_limbs; i++)
+            for (size_t i = 0; i < s_limbs; i++)
               ptr[i] = 0;
             ptr[s_limbs] = (mp_limb_t) 1 << s_bits;
             denominator.limbs = ptr;
@@ -1616,17 +1597,13 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
             }
           {
             mp_limb_t *destptr = num_ptr;
-            {
-              size_t i;
-              for (i = 0; i < s_limbs; i++)
-                *destptr++ = 0;
-            }
+            for (size_t i = 0; i < s_limbs; i++)
+              *destptr++ = 0;
             if (s_bits > 0)
               {
                 const mp_limb_t *sourceptr = m.limbs;
                 mp_twolimb_t accu = 0;
-                size_t count;
-                for (count = m.nlimbs; count > 0; count--)
+                for (size_t count = m.nlimbs; count > 0; count--)
                   {
                     accu += (mp_twolimb_t) *sourceptr++ << s_bits;
                     *destptr++ = (mp_limb_t) accu;
@@ -1638,8 +1615,7 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
             else
               {
                 const mp_limb_t *sourceptr = m.limbs;
-                size_t count;
-                for (count = m.nlimbs; count > 0; count--)
+                for (size_t count = m.nlimbs; count > 0; count--)
                   *destptr++ = *sourceptr++;
               }
             numerator.limbs = num_ptr;
@@ -3563,13 +3539,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                   if (has_precision || has_width)
                     {
                       /* We know the number of wide characters in advance.  */
-                      size_t remaining;
 #  if HAVE_MBRTOWC
                       mbstate_t state;
                       mbszero (&state);
 #  endif
                       ENSURE_ALLOCATION (xsum (length, characters));
-                      for (remaining = characters; remaining > 0; remaining--)
+                      for (size_t remaining = characters; remaining > 0; remaining--)
                         {
                           wchar_t wc;
                           int count;
@@ -3735,12 +3710,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       goto out_of_memory;
                     {
                       TCHAR_T *tmpptr = tmpsrc;
-                      size_t remaining;
 #   if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
                       mbstate_t state;
                       mbszero (&state);
 #   endif
-                      for (remaining = bytes; remaining > 0; )
+                      for (size_t remaining = bytes; remaining > 0; )
                         {
                           char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
                           int count;
@@ -3814,13 +3788,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                   if (has_precision || has_width)
                     {
                       /* We know the number of bytes in advance.  */
-                      size_t remaining;
 #   if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
                       mbstate_t state;
                       mbszero (&state);
 #   endif
                       ENSURE_ALLOCATION (xsum (length, bytes));
-                      for (remaining = bytes; remaining > 0; )
+                      for (size_t remaining = bytes; remaining > 0; )
                         {
                           char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
                           int count;
@@ -4679,9 +4652,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                               {
                                 /* Round the mantissa.  */
                                 long double tail = mantissa;
-                                size_t q;
 
-                                for (q = precision; ; q--)
+                                for (size_t q = precision; ; q--)
                                   {
                                     int digit = (int) tail;
                                     tail -= digit;
@@ -4696,7 +4668,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                                     tail *= 16.0L;
                                   }
                                 if (tail != 0.0L)
-                                  for (q = precision; q > 0; q--)
+                                  for (size_t q = precision; q > 0; q--)
                                     tail *= 0.0625L;
                                 mantissa += tail;
                               }
@@ -4754,9 +4726,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                               else
                                 {
                                   char expbuf[6 + 1];
-                                  const char *ep;
                                   sprintf (expbuf, "%+d", exponent);
-                                  for (ep = expbuf; (*p = *ep) != '\0'; ep++)
+                                  for (const char *ep = expbuf; (*p = *ep) != '\0'; ep++)
                                     p++;
                                 }
 #  endif
@@ -4830,9 +4801,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                               {
                                 /* Round the mantissa.  */
                                 double tail = mantissa;
-                                size_t q;
 
-                                for (q = precision; ; q--)
+                                for (size_t q = precision; ; q--)
                                   {
                                     int digit = (int) tail;
                                     tail -= digit;
@@ -4847,7 +4817,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                                     tail *= 16.0;
                                   }
                                 if (tail != 0.0)
-                                  for (q = precision; q > 0; q--)
+                                  for (size_t q = precision; q > 0; q--)
                                     tail *= 0.0625;
                                 mantissa += tail;
                               }
@@ -4905,9 +4875,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                               else
                                 {
                                   char expbuf[6 + 1];
-                                  const char *ep;
                                   sprintf (expbuf, "%+d", exponent);
-                                  for (ep = expbuf; (*p = *ep) != '\0'; ep++)
+                                  for (const char *ep = expbuf; (*p = *ep) != '\0'; ep++)
                                     p++;
                                 }
 #  endif
@@ -5451,9 +5420,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                                 else
                                   {
                                     char expbuf[6 + 1];
-                                    const char *ep;
                                     sprintf (expbuf, "%+.2d", exponent);
-                                    for (ep = expbuf; (*p = *ep) != '\0'; ep++)
+                                    for (const char *ep = expbuf; (*p = *ep) != '\0'; ep++)
                                       p++;
                                   }
 #   endif
@@ -5706,9 +5674,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                                         else
                                           {
                                             char expbuf[6 + 1];
-                                            const char *ep;
                                             sprintf (expbuf, "%+.2d", exponent);
-                                            for (ep = expbuf; (*p = *ep) != '\0'; ep++)
+                                            for (const char *ep = expbuf; (*p = *ep) != '\0'; ep++)
                                               p++;
                                           }
 #   endif
@@ -6070,9 +6037,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                                   else
                                     {
                                       char expbuf[6 + 1];
-                                      const char *ep;
                                       sprintf (expbuf, decimal_format, exponent);
-                                      for (ep = expbuf; (*p = *ep) != '\0'; ep++)
+                                      for (const char *ep = expbuf; (*p = *ep) != '\0'; ep++)
                                         p++;
                                     }
                                 }
@@ -6337,9 +6303,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                                           else
                                             {
                                               char expbuf[6 + 1];
-                                              const char *ep;
                                               sprintf (expbuf, decimal_format, exponent);
-                                              for (ep = expbuf; (*p = *ep) != '\0'; ep++)
+                                              for (const char *ep = expbuf; (*p = *ep) != '\0'; ep++)
                                                 p++;
                                             }
                                         }
@@ -7747,7 +7712,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                           {
                             const TCHAR_T *tmpsrc;
                             DCHAR_T *tmpdst;
-                            size_t n;
 
 # if USE_SNPRINTF
                             if (result == resultbuf)
@@ -7772,7 +7736,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                             /* Copy backwards, because of overlapping.  */
                             tmpsrc += count;
                             tmpdst += count;
-                            for (n = count; n > 0; n--)
+                            for (size_t n = count; n > 0; n--)
                               *--tmpdst = *--tmpsrc;
                           }
                       }
@@ -7957,8 +7921,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       {
                         /* Convert the %f result to upper case for %F.  */
                         DCHAR_T *rp = result + length;
-                        size_t rc;
-                        for (rc = count; rc > 0; rc--, rp++)
+                        for (size_t rc = count; rc > 0; rc--, rp++)
                           if (*rp >= 'a' && *rp <= 'z')
                             *rp = *rp - 'a' + 'A';
                       }
diff --git a/lib/vma-iter.c b/lib/vma-iter.c
index 009835f60c..9b59f50ec3 100644
--- a/lib/vma-iter.c
+++ b/lib/vma-iter.c
@@ -1114,58 +1114,55 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
           vma_t *vmas = (vma_t *) auxmap;
 
           vma_t *vp = vmas;
-          {
-            prmap_t* mp;
-            for (mp = maps;;)
-              {
-                unsigned long start, end;
+          for (prmap_t *mp = maps;;)
+            {
+              unsigned long start, end;
 
-                start = (unsigned long) mp->pr_vaddr;
-                end = start + mp->pr_size;
-                if (start == 0 && end == 0 && mp->pr_mflags == 0)
-                  break;
-                /* Discard empty VMAs and kernel VMAs.  */
-                if (start < end && (mp->pr_mflags & MA_KERNTEXT) == 0)
-                  {
-                    unsigned int flags;
-                    flags = 0;
-                    if (mp->pr_mflags & MA_READ)
-                      flags |= VMA_PROT_READ;
-                    if (mp->pr_mflags & MA_WRITE)
-                      flags |= VMA_PROT_WRITE;
-                    if (mp->pr_mflags & MA_EXEC)
-                      flags |= VMA_PROT_EXECUTE;
-
-                    if (start <= auxmap_start && auxmap_end - 1 <= end - 1)
-                      {
-                        /* Consider [start,end-1] \ [auxmap_start,auxmap_end-1]
-                           = [start,auxmap_start-1] u [auxmap_end,end-1].  */
-                        if (start < auxmap_start)
-                          {
-                            vp->start = start;
-                            vp->end = auxmap_start;
-                            vp->flags = flags;
-                            vp++;
-                          }
-                        if (auxmap_end - 1 < end - 1)
-                          {
-                            vp->start = auxmap_end;
-                            vp->end = end;
-                            vp->flags = flags;
-                            vp++;
-                          }
-                      }
-                    else
-                      {
-                        vp->start = start;
-                        vp->end = end;
-                        vp->flags = flags;
-                        vp++;
-                      }
-                  }
-                mp++;
-              }
-          }
+              start = (unsigned long) mp->pr_vaddr;
+              end = start + mp->pr_size;
+              if (start == 0 && end == 0 && mp->pr_mflags == 0)
+                break;
+              /* Discard empty VMAs and kernel VMAs.  */
+              if (start < end && (mp->pr_mflags & MA_KERNTEXT) == 0)
+                {
+                  unsigned int flags;
+                  flags = 0;
+                  if (mp->pr_mflags & MA_READ)
+                    flags |= VMA_PROT_READ;
+                  if (mp->pr_mflags & MA_WRITE)
+                    flags |= VMA_PROT_WRITE;
+                  if (mp->pr_mflags & MA_EXEC)
+                    flags |= VMA_PROT_EXECUTE;
+
+                  if (start <= auxmap_start && auxmap_end - 1 <= end - 1)
+                    {
+                      /* Consider [start,end-1] \ [auxmap_start,auxmap_end-1]
+                         = [start,auxmap_start-1] u [auxmap_end,end-1].  */
+                      if (start < auxmap_start)
+                        {
+                          vp->start = start;
+                          vp->end = auxmap_start;
+                          vp->flags = flags;
+                          vp++;
+                        }
+                      if (auxmap_end - 1 < end - 1)
+                        {
+                          vp->start = auxmap_end;
+                          vp->end = end;
+                          vp->flags = flags;
+                          vp++;
+                        }
+                    }
+                  else
+                    {
+                      vp->start = start;
+                      vp->end = end;
+                      vp->flags = flags;
+                      vp++;
+                    }
+                }
+              mp++;
+            }
 
           size_t nvmas = vp - vmas;
           /* Sort the array in ascending order.
@@ -1173,32 +1170,25 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
              Insertion-sort is OK in this case, despite its worst-case running
              time of O(N²), since the number of VMAs will rarely be larger than
              1000.  */
-          {
-            size_t i;
-            for (i = 1; i < nvmas; i++)
-              {
-                /* Invariant: Here vmas[0..i-1] is sorted.  */
-                size_t j;
-                for (j = i; j > 0 && vmas[j - 1].start > vmas[j].start; j--)
-                  {
-                    vma_t tmp = vmas[j - 1];
-                    vmas[j - 1] = vmas[j];
-                    vmas[j] = tmp;
-                  }
-                /* Invariant: Here vmas[0..i] is sorted.  */
-              }
-          }
+          for (size_t i = 1; i < nvmas; i++)
+            {
+              /* Invariant: Here vmas[0..i-1] is sorted.  */
+              for (size_t j = i; j > 0 && vmas[j - 1].start > vmas[j].start; j--)
+                {
+                  vma_t tmp = vmas[j - 1];
+                  vmas[j - 1] = vmas[j];
+                  vmas[j] = tmp;
+                }
+              /* Invariant: Here vmas[0..i] is sorted.  */
+            }
 
           /* Invoke the callback.  */
-          {
-            size_t i;
-            for (i = 0; i < nvmas; i++)
-              {
-                vma_t *vpi = &vmas[i];
-                if (callback (data, vpi->start, vpi->end, vpi->flags))
-                  break;
-              }
-          }
+          for (size_t i = 0; i < nvmas; i++)
+            {
+              vma_t *vpi = &vmas[i];
+              if (callback (data, vpi->start, vpi->end, vpi->flags))
+                break;
+            }
 
           munmap (auxmap, memneed);
           break;
@@ -1233,7 +1223,6 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
   unsigned long auxmap_start;
   unsigned long auxmap_end;
   prmap_t* maps;
-  prmap_t* mp;
 
   pagesize = getpagesize ();
 
@@ -1274,7 +1263,7 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
   if (ioctl (fd, PIOCMAP, maps) < 0)
     goto fail1;
 
-  for (mp = maps;;)
+  for (prmap_t *mp = maps;;)
     {
       unsigned long start, end;
       unsigned int flags;
@@ -1337,7 +1326,6 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
   unsigned long auxmap_end;
   prmap_t* maps;
   prmap_t* maps_end;
-  prmap_t* mp;
 
   pagesize = getpagesize ();
 
@@ -1407,7 +1395,7 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
     maps_end = maps + nmaps;
   }
 
-  for (mp = maps; mp < maps_end; mp++)
+  for (prmap_t *mp = maps; mp < maps_end; mp++)
     {
       unsigned long start, end;
       unsigned int flags;
@@ -1453,9 +1441,8 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
 #elif HAVE_PSTAT_GETPROCVM /* HP-UX */
 
   unsigned long pagesize = getpagesize ();
-  int i;
 
-  for (i = 0; ; i++)
+  for (int i = 0; ; i++)
     {
       struct pst_vm_status info;
       int ret = pstat_getprocvm (&info, sizeof (info), 0, i);
@@ -1482,10 +1469,9 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
 #elif defined __APPLE__ && defined __MACH__ /* Mac OS X */
 
   task_t task = mach_task_self ();
-  vm_address_t address;
   vm_size_t size;
 
-  for (address = VM_MIN_ADDRESS;; address += size)
+  for (vm_address_t address = VM_MIN_ADDRESS;; address += size)
     {
       int more;
       mach_port_t object_name;
@@ -1550,10 +1536,9 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
      https://www.gnu.org/software/hurd/gnumach-doc/Memory-Attributes.html */
 
   task_t task = mach_task_self ();
-  vm_address_t address;
   vm_size_t size;
 
-  for (address = 0;; address += size)
+  for (vm_address_t address = 0;; address += size)
     {
       vm_prot_t protection;
       vm_prot_t max_protection;
diff --git a/lib/windows-cond.c b/lib/windows-cond.c
index c6c6088d92..327ba406cd 100644
--- a/lib/windows-cond.c
+++ b/lib/windows-cond.c
@@ -134,9 +134,7 @@ glwthread_waitqueue_notify_first (glwthread_waitqueue_t *wq)
 static void
 glwthread_waitqueue_notify_all (glwthread_waitqueue_t *wq)
 {
-  struct glwthread_waitqueue_link *l;
-
-  for (l = wq->wq_list.wql_next; l != &wq->wq_list; )
+  for (struct glwthread_waitqueue_link *l = wq->wq_list.wql_next; l != &wq->wq_list; )
     {
       struct glwthread_waitqueue_element *elt =
         (struct glwthread_waitqueue_element *) l;
diff --git a/lib/windows-path.c b/lib/windows-path.c
index b1b3a29bee..cb8e1af5bc 100644
--- a/lib/windows-path.c
+++ b/lib/windows-path.c
@@ -35,11 +35,8 @@ extended_PATH (const char * const *dll_dirs)
   size_t size;
   {
     size = 5;
-    {
-      size_t i;
-      for (i = 0; dll_dirs[i] != NULL; i++)
-        size += strlen (dll_dirs[i]) + 1;
-    }
+    for (size_t i = 0; dll_dirs[i] != NULL; i++)
+      size += strlen (dll_dirs[i]) + 1;
     size += strlen (old_PATH) + 1;
   }
   char *new_PATH = (char *) malloc (size);
@@ -51,20 +48,17 @@ extended_PATH (const char * const *dll_dirs)
       memcpy (p, "PATH=", 5);
       p += 5;
     }
-    {
-      size_t i;
-      for (i = 0; dll_dirs[i] != NULL; i++)
-        {
-          size_t l = strlen (dll_dirs[i]);
-          memcpy (p, dll_dirs[i], l);
-          p += l;
+    for (size_t i = 0; dll_dirs[i] != NULL; i++)
+      {
+        size_t l = strlen (dll_dirs[i]);
+        memcpy (p, dll_dirs[i], l);
+        p += l;
 #if defined _WIN32 && !defined __CYGWIN__
-          *p++ = ';';
+        *p++ = ';';
 #else
-          *p++ = ':';
+        *p++ = ':';
 #endif
-        }
-    }
+      }
     {
       size_t l = strlen (old_PATH);
       memcpy (p, old_PATH, l);
@@ -102,9 +96,8 @@ extended_environ (const char * const *dll_dirs)
        The guess will be exact if other threads don't make modifications.  */
     size_t size = 0;
     {
-      char **ep;
       char *p;
-      for (ep = envp; (p = *ep) != NULL; ep++)
+      for (char **ep = envp; (p = *ep) != NULL; ep++)
         if (strncmp (p, "PATH=", 5) != 0)
           size += 1;
     }
@@ -119,9 +112,8 @@ extended_environ (const char * const *dll_dirs)
     *nep++ = child_PATH;
     {
       size_t i = 0;
-      char **ep;
       char *p;
-      for (ep = envp; (p = *ep) != NULL; ep++)
+      for (char **ep = envp; (p = *ep) != NULL; ep++)
         if (strncmp (p, "PATH=", 5) != 0)
           {
             if (i == size)
diff --git a/lib/windows-rwlock.c b/lib/windows-rwlock.c
index 313f14ca20..0ac90657aa 100644
--- a/lib/windows-rwlock.c
+++ b/lib/windows-rwlock.c
@@ -64,14 +64,13 @@ glwthread_waitqueue_add (glwthread_waitqueue_t *wq)
           unsigned int old_count = wq->count;
           unsigned int old_alloc = wq->alloc;
           unsigned int old_offset = wq->offset;
-          unsigned int i;
           if (old_offset + old_count > old_alloc)
             {
               unsigned int limit = old_offset + old_count - old_alloc;
-              for (i = 0; i < limit; i++)
+              for (unsigned int i = 0; i < limit; i++)
                 new_array[old_alloc + i] = new_array[i];
             }
-          for (i = 0; i < old_count; i++)
+          for (unsigned int i = 0; i < old_count; i++)
             new_array[i] = new_array[old_offset + i];
           wq->offset = 0;
         }
@@ -107,9 +106,7 @@ glwthread_waitqueue_notify_first (glwthread_waitqueue_t *wq)
 static void
 glwthread_waitqueue_notify_all (glwthread_waitqueue_t *wq)
 {
-  unsigned int i;
-
-  for (i = 0; i < wq->count; i++)
+  for (unsigned int i = 0; i < wq->count; i++)
     {
       unsigned int index = wq->offset + i;
       if (index >= wq->alloc)
diff --git a/lib/windows-spawn.c b/lib/windows-spawn.c
index dccd40e112..0d752d6360 100644
--- a/lib/windows-spawn.c
+++ b/lib/windows-spawn.c
@@ -56,13 +56,12 @@ quoted_arg_length (const char *string)
   bool quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
   size_t length;
   unsigned int backslashes;
-  const char *s;
 
   length = 0;
   backslashes = 0;
   if (quote_around)
     length++;
-  for (s = string; *s != '\0'; s++)
+  for (const char *s = string; *s != '\0'; s++)
     {
       char c = *s;
       if (c == '"')
@@ -89,21 +88,17 @@ quoted_arg_string (const char *string, char *mem)
   bool quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
   char *p;
   unsigned int backslashes;
-  const char *s;
 
   p = mem;
   backslashes = 0;
   if (quote_around)
     *p++ = '"';
-  for (s = string; *s != '\0'; s++)
+  for (const char *s = string; *s != '\0'; s++)
     {
       char c = *s;
       if (c == '"')
-        {
-          unsigned int j;
-          for (j = backslashes + 1; j > 0; j--)
-            *p++ = '\\';
-        }
+        for (unsigned int j = backslashes + 1; j > 0; j--)
+          *p++ = '\\';
       *p++ = c;
       if (c == '\\')
         backslashes++;
@@ -112,8 +107,7 @@ quoted_arg_string (const char *string, char *mem)
     }
   if (quote_around)
     {
-      unsigned int j;
-      for (j = backslashes; j > 0; j--)
+      for (unsigned int j = backslashes; j > 0; j--)
         *p++ = '\\';
       *p++ = '"';
     }
@@ -127,7 +121,6 @@ prepare_spawn (const char * const *argv, char **mem_to_free)
 {
   size_t argc;
   const char **new_argv;
-  size_t i;
 
   /* Count number of arguments.  */
   for (argc = 0; argv[argc] != NULL; argc++)
@@ -146,7 +139,7 @@ prepare_spawn (const char * const *argv, char **mem_to_free)
 
   /* Put quoted arguments into the new argument vector.  */
   size_t needed_size = 0;
-  for (i = 0; i < argc; i++)
+  for (size_t i = 0; i < argc; i++)
     {
       const char *string = argv[i];
       size_t length;
@@ -176,7 +169,7 @@ prepare_spawn (const char * const *argv, char **mem_to_free)
     }
   *mem_to_free = mem;
 
-  for (i = 0; i < argc; i++)
+  for (size_t i = 0; i < argc; i++)
     {
       const char *string = argv[i];
 
@@ -211,9 +204,8 @@ compose_command (const char * const *argv)
 
   /* Determine the size of the needed block of memory.  */
   size_t total_size = 0;
-  const char * const *ap;
   const char *p;
-  for (ap = argv; (p = *ap) != NULL; ap++)
+  for (const char * const *ap = argv; (p = *ap) != NULL; ap++)
     total_size += strlen (p) + 1;
   size_t command_size = (total_size > 0 ? total_size : 1);
 
@@ -229,7 +221,7 @@ compose_command (const char * const *argv)
   if (total_size > 0)
     {
       char *cp = command;
-      for (ap = argv; (p = *ap) != NULL; ap++)
+      for (const char * const *ap = argv; (p = *ap) != NULL; ap++)
         {
           size_t size = strlen (p) + 1;
           memcpy (cp, p, size - 1);
@@ -256,11 +248,10 @@ compose_envblock (const char * const *envp, const char *new_PATH)
     /* Guess the size of the needed block of memory.
        The guess will be exact if other threads don't make modifications.  */
     size_t total_size = 0;
-    const char * const *ep;
     const char *p;
     if (new_PATH != NULL)
       total_size += strlen (new_PATH) + 1;
-    for (ep = envp; (p = *ep) != NULL; ep++)
+    for (const char * const *ep = envp; (p = *ep) != NULL; ep++)
       if (!(new_PATH != NULL && strncmp (p, "PATH=", 5) == 0))
         total_size += strlen (p) + 1;
     size_t envblock_size = total_size;
@@ -279,7 +270,7 @@ compose_envblock (const char * const *envp, const char *new_PATH)
         memcpy (envblock + envblock_used, new_PATH, size);
         envblock_used += size;
       }
-    for (ep = envp; (p = *ep) != NULL; ep++)
+    for (const char * const *ep = envp; (p = *ep) != NULL; ep++)
       if (!(new_PATH != NULL && strncmp (p, "PATH=", 5) == 0))
         {
           size_t size = strlen (p) + 1;
@@ -370,8 +361,7 @@ init_inheritable_handles (struct inheritable_handles *inh_handles,
   /* Fill in the array.  */
   {
     HANDLE curr_process = (duplicate ? GetCurrentProcess () : INVALID_HANDLE_VALUE);
-    unsigned int fd;
-    for (fd = 0; fd < handles_count; fd++)
+    for (unsigned int fd = 0; fd < handles_count; fd++)
       {
         ih[fd].handle = INVALID_HANDLE_VALUE;
         /* _get_osfhandle
@@ -400,8 +390,7 @@ init_inheritable_handles (struct inheritable_handles *inh_handles,
                                               curr_process, &ih[fd].handle,
                                               0, TRUE, DUPLICATE_SAME_ACCESS))
                           {
-                            unsigned int i;
-                            for (i = 0; i < fd; i++)
+                            for (unsigned int i = 0; i < fd; i++)
                               if (ih[i].handle != INVALID_HANDLE_VALUE
                                   && !(ih[i].flags & KEEP_OPEN_IN_PARENT))
                                 CloseHandle (ih[i].handle);
@@ -486,53 +475,50 @@ compose_handles_block (const struct inheritable_handles *inh_handles,
                 & - (uintptr_t) sizeof (HANDLE));
 
   * (unsigned int *) hblock = handles_count;
-  {
-    unsigned int fd;
-    for (fd = 0; fd < handles_count; fd++)
-      {
-        handles_aligned[fd] = INVALID_HANDLE_VALUE;
-        flags[fd] = 0;
-
-        HANDLE handle = inh_handles->ih[fd].handle;
-        if (handle != INVALID_HANDLE_VALUE
-            /* The first three are possibly already passed above.
-               But they need to passed here as well, if they have some flags.  */
-            && (fd >= 3 || (unsigned char) inh_handles->ih[fd].flags != 0))
-          {
-            DWORD hflags;
-            /* GetHandleInformation
-               <https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-gethandleinformation>  */
-            if (GetHandleInformation (handle, &hflags))
-              {
-                if ((hflags & HANDLE_FLAG_INHERIT) != 0)
-                  {
-                    /* fd denotes an inheritable descriptor.  */
-                    handles_aligned[fd] = handle;
-                    /* On Microsoft Windows, it would be sufficient to set
-                       flags[fd] = 1.  But on ReactOS or Wine, adding the bit
-                       that indicates the handle type may be necessary.  So,
-                       just do it everywhere.  */
-                    flags[fd] = 1 | (unsigned char) inh_handles->ih[fd].flags;
-                    switch (GetFileType (handle))
-                      {
-                      case FILE_TYPE_CHAR:
-                        flags[fd] |= 64;
-                        break;
-                      case FILE_TYPE_PIPE:
-                        flags[fd] |= 8;
-                        break;
-                      default:
-                        break;
-                      }
-                  }
-                else
-                  /* We shouldn't have any non-inheritable handles in
-                     inh_handles->handles.  */
-                  abort ();
-              }
-          }
-      }
-  }
+  for (unsigned int fd = 0; fd < handles_count; fd++)
+    {
+      handles_aligned[fd] = INVALID_HANDLE_VALUE;
+      flags[fd] = 0;
+
+      HANDLE handle = inh_handles->ih[fd].handle;
+      if (handle != INVALID_HANDLE_VALUE
+          /* The first three are possibly already passed above.
+             But they need to passed here as well, if they have some flags.  */
+          && (fd >= 3 || (unsigned char) inh_handles->ih[fd].flags != 0))
+        {
+          DWORD hflags;
+          /* GetHandleInformation
+             <https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-gethandleinformation>  */
+          if (GetHandleInformation (handle, &hflags))
+            {
+              if ((hflags & HANDLE_FLAG_INHERIT) != 0)
+                {
+                  /* fd denotes an inheritable descriptor.  */
+                  handles_aligned[fd] = handle;
+                  /* On Microsoft Windows, it would be sufficient to set
+                     flags[fd] = 1.  But on ReactOS or Wine, adding the bit
+                     that indicates the handle type may be necessary.  So,
+                     just do it everywhere.  */
+                  flags[fd] = 1 | (unsigned char) inh_handles->ih[fd].flags;
+                  switch (GetFileType (handle))
+                    {
+                    case FILE_TYPE_CHAR:
+                      flags[fd] |= 64;
+                      break;
+                    case FILE_TYPE_PIPE:
+                      flags[fd] |= 8;
+                      break;
+                    default:
+                      break;
+                    }
+                }
+              else
+                /* We shouldn't have any non-inheritable handles in
+                   inh_handles->handles.  */
+                abort ();
+            }
+        }
+    }
   if (handles != (char *) handles_aligned)
     memmove (handles, (char *) handles_aligned, handles_count * sizeof (HANDLE));
 
diff --git a/lib/windows-timedrwlock.c b/lib/windows-timedrwlock.c
index 379b10032b..418eb9f37b 100644
--- a/lib/windows-timedrwlock.c
+++ b/lib/windows-timedrwlock.c
@@ -137,9 +137,7 @@ glwthread_waitqueue_notify_first (glwthread_waitqueue_t *wq)
 static void
 glwthread_waitqueue_notify_all (glwthread_waitqueue_t *wq)
 {
-  struct glwthread_waitqueue_link *l;
-
-  for (l = wq->wq_list.wql_next; l != &wq->wq_list; )
+  for (struct glwthread_waitqueue_link *l = wq->wq_list.wql_next; l != &wq->wq_list; )
     {
       struct glwthread_waitqueue_element *elt =
         (struct glwthread_waitqueue_element *) l;
diff --git a/lib/windows-tls.c b/lib/windows-tls.c
index 0085243370..db0edf7f6f 100644
--- a/lib/windows-tls.c
+++ b/lib/windows-tls.c
@@ -128,8 +128,6 @@ dtor_table_shrink_used (void)
 void
 glwthread_tls_process_destructors (void)
 {
-  unsigned int repeat;
-
   dtor_table_ensure_initialized ();
 
   EnterCriticalSection (&dtor_table_lock);
@@ -141,7 +139,7 @@ glwthread_tls_process_destructors (void)
     }
   dtor_processing_threads++;
 
-  for (repeat = GLWTHREAD_DESTRUCTOR_ITERATIONS; repeat > 0; repeat--)
+  for (unsigned int repeat = GLWTHREAD_DESTRUCTOR_ITERATIONS; repeat > 0; repeat--)
     {
       unsigned int destructors_run = 0;
 
@@ -157,9 +155,8 @@ glwthread_tls_process_destructors (void)
              entry as inactive, but it will not otherwise change dtors_used nor
              the contents of the first dtors_used entries of dtor_table.  */
       unsigned int i_limit = dtors_used;
-      unsigned int i;
 
-      for (i = 0; i < i_limit; i++)
+      for (unsigned int i = 0; i < i_limit; i++)
         {
           struct dtor current = dtor_table[i];
           if (current.destructor != NULL)
@@ -299,9 +296,8 @@ glwthread_tls_key_delete (glwthread_tls_key_t key)
       /* Find the key in dtor_table.  */
       {
         unsigned int i_limit = dtors_used;
-        unsigned int i;
 
-        for (i = 0; i < i_limit; i++)
+        for (unsigned int i = 0; i < i_limit; i++)
           if (dtor_table[i].key == key)
             {
               if (i < dtors_used - 1)
@@ -317,9 +313,8 @@ glwthread_tls_key_delete (glwthread_tls_key_t key)
       /* Be careful not to disturb the glwthread_tls_process_destructors
          invocations that are executing in other threads.  */
       unsigned int i_limit = dtors_used;
-      unsigned int i;
 
-      for (i = 0; i < i_limit; i++)
+      for (unsigned int i = 0; i < i_limit; i++)
         if (dtor_table[i].destructor != NULL /* skip inactive entries */
             && dtor_table[i].key == key)
           {
diff --git a/lib/xstring-desc.c b/lib/xstring-desc.c
index c44d8bc3b4..c212c2e76a 100644
--- a/lib/xstring-desc.c
+++ b/lib/xstring-desc.c
@@ -35,15 +35,11 @@ xsd_concat (idx_t n, /* [rw_]string_desc_t string1, */ ...)
     string_desc_t string1 = va_arg (strings, string_desc_t);
     total += string1._nbytes;
     if (n > 1)
-      {
-        idx_t i;
-
-        for (i = n - 1; i > 0; i--)
-          {
-            string_desc_t arg = va_arg (strings, string_desc_t);
-            total += arg._nbytes;
-          }
-      }
+      for (idx_t i = n - 1; i > 0; i--)
+        {
+          string_desc_t arg = va_arg (strings, string_desc_t);
+          total += arg._nbytes;
+        }
     va_end (strings);
   }
 
@@ -58,17 +54,13 @@ xsd_concat (idx_t n, /* [rw_]string_desc_t string1, */ ...)
     memcpy (combined, string1._data, string1._nbytes);
     pos += string1._nbytes;
     if (n > 1)
-      {
-        idx_t i;
-
-        for (i = n - 1; i > 0; i--)
-          {
-            string_desc_t arg = va_arg (strings, string_desc_t);
-            if (arg._nbytes > 0)
-              memcpy (combined + pos, arg._data, arg._nbytes);
-            pos += arg._nbytes;
-          }
-      }
+      for (idx_t i = n - 1; i > 0; i--)
+        {
+          string_desc_t arg = va_arg (strings, string_desc_t);
+          if (arg._nbytes > 0)
+            memcpy (combined + pos, arg._data, arg._nbytes);
+          pos += arg._nbytes;
+        }
     va_end (strings);
   }
 
diff --git a/lib/xvasprintf.c b/lib/xvasprintf.c
index a12753c4ed..a71d5aac53 100644
--- a/lib/xvasprintf.c
+++ b/lib/xvasprintf.c
@@ -36,13 +36,12 @@ xstrcat (size_t argcount, va_list args)
   char *result;
   va_list ap;
   size_t totalsize;
-  size_t i;
   char *p;
 
   /* Determine the total size.  */
   totalsize = 0;
   va_copy (ap, args);
-  for (i = argcount; i > 0; i--)
+  for (size_t i = argcount; i > 0; i--)
     {
       const char *next = va_arg (ap, const char *);
       totalsize = xsum (totalsize, strlen (next));
@@ -57,7 +56,7 @@ xstrcat (size_t argcount, va_list args)
   /* Allocate and fill the result string.  */
   result = XNMALLOC (totalsize + 1, char);
   p = result;
-  for (i = argcount; i > 0; i--)
+  for (size_t i = argcount; i > 0; i--)
     {
       const char *next = va_arg (args, const char *);
       size_t len = strlen (next);
@@ -79,9 +78,8 @@ xvasprintf (const char *format, va_list args)
      have a separate function xstrcat() for this purpose.  */
   {
     size_t argcount = 0;
-    const char *f;
 
-    for (f = format;;)
+    for (const char *f = format;;)
       {
         if (*f == '\0')
           /* Recognized the special case of string concatenation.  */
-- 
2.51.0

