]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
lib: Reduce scope of local variables.
authorBruno Haible <bruno@clisp.org>
Tue, 9 Dec 2025 23:23:48 +0000 (00:23 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 9 Dec 2025 23:23:48 +0000 (00:23 +0100)
M = Move variable declaration to its initialization.
R = Reduce scope.
S = Split scope, create separate variables from one variable.
B = Insert braces, creating a block scope.
O = Change order of initializations.

* lib/accept4.c (accept4): M.
* lib/acl-internal.c (acl_ace_nontrivial): R.
* lib/acosl.c (acosl): MS.
* lib/af_alg.c (afalg_stream): B.
* lib/alignalloc.h (alignalloc): R.
* lib/alloca.c (find_stack_direction): M.
(alloca): M.
* lib/amemxfrm.c (amemxfrm): MR.
* lib/arcfour.c (arcfour_stream): MB.
(arcfour_setkey): MB.
* lib/arctwo.c (arctwo_encrypt): M.
(arctwo_decrypt): M.
(arctwo_setkey_ekb): M.
* lib/areadlink-with-size.c (areadlink_with_size): MR.
* lib/areadlinkat-with-size.c (areadlinkat_with_size): MR.
* lib/argmatch.c (argmatch): MO.
(main): RBO.
* lib/argp-fmtstream.c (__argp_make_fmtstream): M.
(__argp_fmtstream_update): M.
(__argp_fmtstream_ensure): R.
(__argp_fmtstream_printf): R.
* lib/argp-fmtstream.h (__argp_fmtstream_set_lmargin): M.
(__argp_fmtstream_set_rmargin): M.
(__argp_fmtstream_set_wmargin): M.
* lib/argp-help.c (validate_uparams): M.
(fill_in_uparams): MR.
(make_hol): MRSO.
(hol_entry_short_iterate): R.
(hol_entry_long_iterate): R.
(hol_entry_first_long): Rename 'num' to 'nopts'.
(canon_doc_option): M.
(hol_append): MR.
(argp_hol): O.
(hol_entry_help): RSBO.
(hol_help): RB.
(usage_argful_short_opt): R.
(usage_long_opt): R.
(hol_usage): SB.
(argp_args_levels): R.
(argp_args_usage): MRB.
(argp_doc): RBO.
(_help): MR.
(__argp_error): R.
* lib/argp-parse.c (group_parse): M.
(parser_init): MRB.
(parser_finalize): MS.
(parser_parse_next): R.
(__argp_parse): MR.
(__argp_input): M.
* lib/argz.c (argz_add_sep): M.
(argz_create_sep): M.
(argz_create): R.
(argz_replace): RB.
* lib/asinl.c (asinl): MRS.
* lib/asnprintf.c (asnprintf): M.
* lib/asnwprintf.c (asnwprintf): M.
* lib/asprintf.c (asprintf): M.
* lib/astrxfrm.c (astrxfrm): MR.
* lib/aszprintf.c (aszprintf): M.
* lib/at-func.c (AT_FUNC_NAME): MR.
* lib/at-func2.c (at_func2): MRS.
* lib/atanl.c (atanl): MRS.
* lib/backupfile.c (numbered_backup): R.
* lib/base32.c (decode_8): R.
(base32_decode_ctx): R.
* lib/base64.c (decode_4): R.
(base64_decode_ctx): R.
* lib/basename-lgpl.c (last_component): R.
(base_len): RO.
* lib/bitset.c (bitset_copy_): R.
* lib/bitset/list.c (lbitset_prune): MR.
(lbitset_weed): MR.
(lbitset_list): SB.
* lib/bitset/table.c (tbitset_list): SB.
* lib/boot-time-aux.h (get_windows_boot_time_fallback): R.
* lib/btoc32.c (btoc32): R.
* lib/c-asprintf.c (c_asprintf): M.
* lib/c-aszprintf.c (c_aszprintf): M.
* lib/c-snprintf.c (c_snprintf): M.
* lib/c-snzprintf.c (c_snzprintf): M.
* lib/c-strcasecmp.c (c_strcasecmp): R.
* lib/c-strcasestr.c (c_strcasestr): MRSB.
* lib/c-strncasecmp.c (c_strncasecmp): R.
* lib/c-strtod.c (C_STRTOD): R.
* lib/c-vsnzprintf.c (c_vsnzprintf): M.
* lib/c-xasprintf.c (c_xasprintf): M.
* lib/c32tob.c (c32tob): R.
* lib/canon-host.c (canon_host_r): MR.
* lib/canonicalize.c (canonicalize_filename_mode_stk): R.
* lib/canonicalize-lgpl.c (realpath_stk): R.
* lib/cbrt.c (cbrt): M.
* lib/cbrtf.c (cbrtf): M.
* lib/cbrtl.c (cbrtl): MR.
* lib/chdir-long.c (chdir_long): M.
(main): MR.
* lib/classpath.c (new_classpath): MB.
* lib/clean-temp.c (create_temp_dir): M.
(unregister_temp_file): M.
(unregister_temp_subdir): M.
(cleanup_temp_file): M.
(cleanup_temp_subdir): M.
(cleanup_temp_dir_contents): MSB.
(open_temp): R.
(fopen_temp): R.
(close_temp): RB.
(fclose_variant_temp): RB.
* lib/clean-temp-simple.c (cleanup_action): MSB.
(cleanup_temporary_file): M.
* lib/copy-file.c (copy_file_internal): MRB.
* lib/cosl.c (cosl): MR.
* lib/crc-generate-table.c (make_crc_table): M.
* lib/crc-x86_64-pclmul.c (crc32_update_no_xor_pclmul): MRSB.
* lib/crc.c (crc32_update_no_xor_slice_by_8): S.
(crc32_update_no_xor_slice_by_n): M.
(crc32_update_no_xor): MR.
* lib/csharpcomp.c (compile_csharp_using_mono): MRB.
(compile_csharp_using_dotnet): MRSB.
(compile_csharp_using_sscli): MRB.
* lib/csharpexec.c (execute_csharp_using_mono): MO.
(execute_csharp_using_dotnet): MO.
(execute_csharp_using_sscli): MO.
(execute_csharp_program): R.
* lib/cygpath.c (execute_and_read_line): M.
* lib/des.c (gl_des_is_weak_key): M.
(gl_3des_ecb_crypt): MO.
* lib/dfa.c (closure): B.
(dfamust): MRB.
* lib/di-set.c (map_device): M.
(di_set_insert): M.
(di_set_lookup): M.
* lib/dirname-lgpl.c (dir_len): R.
* lib/dprintf.c (dprintf): M.
* lib/dup.c (dup_nothrow): R.
* lib/dup2.c (ms_windows_dup2): M.
(klibc_dup2dirfd): M.
(klibc_dup2): MR.
(rpl_dup2): M.
* lib/dup3.c (dup3): M.
* lib/duplocale.c (duplocale): MRSB.
* lib/dzprintf.c (dzprintf): M.
* lib/euidaccess.c (euidaccess): MR.
(main): M.
* lib/exclude.c (add_exclude): R.
* lib/execl.c (execl): SB.
* lib/execle.c (execle): SB.
* lib/execlp.c (execlp): SB.
* lib/execute.c (execute): R.
* lib/fchdir.c (ensure_dirs_slot): M.
(get_name): M.
(_gl_register_fd): R.
* lib/fclose.c (rpl_fclose): MR.
* lib/fcntl.c (dupfd): RO.
(fcntl): R.
(klibc_dupdirfd): M.
(klibc_fcntl): MRSB.
* lib/fdopen.c (rpl_fdopen): M.
* lib/file-has-acl.c (get_aclinfo): R.
(fdfile_has_aclinfo): MR.
* lib/file-remote.c (main): M.
* lib/file-set.c (record_file): M.
(seen_file): R.
* lib/findprog.c (find_in_path): MR.
* lib/findprog-in.c (find_in_given_path): MR.
* lib/flock.c (do_lock): MR.
(do_unlock): M.
(flock): MR.
* lib/fma.c (decode): M.
* lib/fopen.c (rpl_fopen): MR.
* lib/forkpty.c (forkpty): M.
* lib/fprintf.c (fprintf): M.
* lib/freadseek.c (freadseek): MR.
* lib/freopen.c (rpl_freopen): M.
* lib/freopen-safer.c (freopen_safer): M.
* lib/frexp.c (FUNC): MR.
* lib/fseterr.c (fseterr): M.
* lib/fstatat.c (rpl_fstatat): M.
* lib/fstrcmp.c (fstrcmp_free_resources): M.
(fstrcmp_bounded): MR.
* lib/fsusage.c (statvfs_works): R.
* lib/fsync.c (fsync): M.
* lib/ftello.c (ftello): M.
* lib/ftruncate.c (SetFileSize): M.
* lib/fts.c (fts_open): MR.
(fts_load): M.
(fts_close): MR.
(filesystem_type): MRO.
(fts_read): MB.
(fts_children): M.
(fts_build): MR.
(fts_cross_check): RO.
(fd_ring_print): RO.
(fts_stat): RO.
(fts_sort): R.
(fts_alloc): M.
(fts_lfree): R.
(fts_palloc): M.
(fts_padjust): MS.
(fts_maxarglen): M.
(fts_safe_changedir): MR.
* lib/fts-cycle.c (enter_dir): MRO.
(leave_dir): M.
* lib/fzprintf.c (fzprintf): M.
* lib/gc-gnulib.c (gc_cipher_open): MR.
(gc_cipher_setkey): MSB.
(gc_cipher_setiv): M.
(gc_cipher_encrypt_inline): M.
(gc_cipher_decrypt_inline): M.
(gc_hash_open): MR.
(gc_hash_clone): M.
* lib/gc-libgcrypt.c (gc_init): Remove local variable 'err'.
(gc_cipher_open): MR.
(gc_cipher_setkey): M.
(gc_cipher_setiv): M.
(gc_hash_open): MR.
(gc_hash_clone): M.
(gc_md4): MR.
(gc_md5): MR.
(gc_sha1): MR.
(gc_sha256): MR.
(gc_sha512): MR.
(gc_sm3): MR.
(gc_hmac_md5): MR. Remove local variable 'err'.
(gc_hmac_sha1): MR. Remove local variable 'err'.
(gc_hmac_sha256): MR. Remove local variable 'err'.
(gc_hmac_sha512): MR. Remove local variable 'err'.
* lib/gc-pbkdf2.c (gc_pbkdf2_prf): MR.
* lib/gen-uni-tables.c (fill_attributes): M.
(debug_output_predicate): M.
(output_predicate_test): M.
(output_predicate): MR.
(output_category): MR.
(output_combclass): MR.
(output_bidi_category): MR.
(output_decimal_digit_test): M.
(output_decimal_digit): MR.
(output_digit_test): M.
(output_digit): MR.
(output_numeric_test): M.
(output_numeric): MR.
(fill_mirror): MR.
(get_mirror_value): M.
(output_mirror): MR.
(fill_properties): MR.
(fill_property30): MR.
(output_indic_conjunct_break_test): M.
(output_indic_conjunct_break): MR.
(fill_arabicshaping): MR.
(output_joining_type_test): M.
(output_joining_type): MR.
(output_joining_group_test): M.
(output_joining_group): MR.
(fill_scripts): MR.
(output_scripts): MR.
(output_scripts_byname): M.
(fill_blocks): MR.
(output_blocks): M.
(output_ident_category): MR.
(output_charclass): MR.
(output_charmap): MR.
(output_tables): M.
(fill_width): MR.
(output_nonspacing_property): MR.
(output_width_property_test): M.
(debug_output_lbrk_tables): M.
(fill_org_lbp): MR.
(debug_output_org_lbrk_tables): M.
(output_lbpea): M.
(output_lbrk_tables): R.
(output_lbrk_rules_as_tables): M.
(debug_output_wbrk_tables): M.
(fill_org_wbp): MR.
(debug_output_org_wbrk_tables): M.
(output_wbp): M.
(output_wbrk_tables): M.
(output_gbp_test): MR.
(output_gbp_table): MR.
(fill_org_gbp): MR.
(get_decomposition): MR.
(output_decomposition): M.
(output_decomposition_tables): R.
(fill_composition_exclusions): MR.
(debug_output_composition_tables): M.
(output_composition_tables): MSB.
(output_simple_mapping_test): M.
(output_simple_mapping): MR.
(fill_casing_rules): MR.
(fill_casefolding_rules): MR.
(output_casing_rules): M.
(output_version): MR.
* lib/get-rusage-as.c (get_rusage_as_via_setrlimit): R.
(get_rusage_as): M.
* lib/get-rusage-data.c (get_rusage_data_via_setrlimit): R.
(get_rusage_data): M.
* lib/get_ppid_of.c (get_ppid_of): M.
* lib/get_progname_of.c (get_progname_of): MR.
* lib/getaddrinfo.c (use_win32_p): M.
(getaddrinfo): MR.
(freeaddrinfo): M.
* lib/getcwd.c (__getcwd_generic): MRSBO.
* lib/getcwd-lgpl.c (rpl_getcwd): MS.
* lib/getdelim.c (getdelim): MR.
* lib/getdomainname.c (getdomainname): M.
* lib/getentropy.c (getentropy): R.
* lib/getgroups.c (rpl_getgroups): MR.
* lib/gethostname.c (rpl_gethostname): M.
* lib/getloadavg.c (getloadavg): MRB.
* lib/getlocalename_l-unsafe.c (newlocale): MR.
(duplocale): MR.
(freelocale): M.
* lib/getlogin_r.c (getlogin_r): M.
* lib/getndelim2.c (getndelim2): MR.
* lib/getopt.c (exchange): MS.
(process_long_option): MRB.
(_getopt_internal_r): MR.
(_getopt_internal): M.
(main): M.
* lib/getopt1.c (main): M.
* lib/getpass.c (getpass): MRB.
* lib/getprogname.c (getprogname): M.
* lib/getrusage.c (getrusage): M.
* lib/getsockopt.c (rpl_getsockopt): M.
* lib/getsubopt.c (getsubopt): M.
* lib/gettext.h (dcpgettext_expr): M.
(dcnpgettext_expr): M.
* lib/gettimeofday.c (gettimeofday): R.
* lib/getugroups.c (getugroups): MR.
* lib/getumask.c (getumask): R.
* lib/gl_anyavltree_list2.h (rebalance): MR.
(gl_tree_remove_node_from_tree): MR.
(gl_tree_nx_add_before): R.
(gl_tree_nx_add_after): R.
* lib/gl_anyhash2.h (hash_resize): M.
* lib/gl_anylinked_list2.h (gl_linked_get_at): R.
(gl_linked_nx_set_at): R.
(gl_linked_search_from_to): R.
(gl_linked_indexof_from_to): MR.
(gl_linked_nx_add_at): M.
(gl_linked_remove_node): M.
(gl_linked_remove_at): MR.
(gl_linked_iterator_from_to): M.
(gl_linked_sortedlist_search_from_to): R.
(gl_linked_sortedlist_indexof_from_to): R.
* lib/gl_anyrbtree_list2.h (rebalance_after_add): MR.
(gl_tree_remove_node_from_tree): M.
* lib/gl_anytree_list2.h (gl_tree_iterator): MB.
(gl_tree_sortedlist_indexof_from_to): R.
* lib/gl_anytree_omap.h (gl_tree_nx_getput): M.
(gl_tree_iterator): MB.
* lib/gl_anytree_oset.h (gl_tree_nx_add): M.
(gl_tree_update): M.
(gl_tree_iterator): MB.
* lib/gl_anytreehash_list1.h (add_to_bucket): M.
* lib/gl_array_list.c (grow): M.
(gl_array_nx_add_first): M.
(gl_array_nx_add_before): M.
(gl_array_nx_add_after): M.
(gl_array_nx_add_at): M.
(gl_array_remove_node): M.
(gl_array_remove_at): M.
* lib/gl_array_map.c (grow): M.
(gl_array_nx_getput): M.
(gl_array_remove_at): M.
* lib/gl_array_omap.c (grow): M.
(gl_array_nx_add_at): M.
(gl_array_remove_at): M.
* lib/gl_array_oset.c (grow): M.
(gl_array_nx_add_at): M.
(gl_array_remove_at): M.
* lib/gl_array_set.c (grow): M.
* lib/gl_avltree_ordered.h (rebalance): M.
(gl_tree_add_node_before): R.
(gl_tree_add_node_after): R.
(gl_tree_remove_node_no_free): M.
* lib/gl_carray_list.c (gl_carray_node_value): M.
(gl_carray_node_nx_set_value): M.
(gl_carray_get_at): M.
(gl_carray_nx_set_at): M.
(gl_carray_indexof_from_to): M.
(grow): M.
(gl_carray_nx_add_last): M.
(gl_carray_nx_add_at): M.
(gl_carray_remove_at): M.
(gl_carray_iterator_from_to): R.
(gl_carray_sortedlist_indexof_from_to): M.
(gl_carray_sortedlist_nx_add): M.
* lib/gl_rbtree_ordered.h (rebalance_after_add): M.
(gl_tree_remove_node_no_free): M.
* lib/gl_sublist.c (gl_sublist_sortedlist_search_from_to): M.
(gl_sublist_sortedlist_indexof_from_to): M.
* lib/glob.c (__glob): MR.
* lib/globfree.c (globfree): M.
* lib/glthread/lock.c (glthread_rwlock_init_for_glibc): M.
(glthread_rwlock_init_multithreaded): M.
(glthread_rwlock_rdlock_multithreaded): M.
(glthread_rwlock_wrlock_multithreaded): M.
(glthread_rwlock_destroy_multithreaded): M.
(glthread_rwlock_init_multithreaded): M.
(glthread_rwlock_rdlock_multithreaded): M.
(glthread_rwlock_wrlock_multithreaded): M.
(glthread_rwlock_unlock_multithreaded): M.
(glthread_rwlock_destroy_multithreaded): M.
(glthread_recursive_lock_init_multithreaded): M.
(glthread_recursive_lock_lock_multithreaded): M.
(glthread_recursive_lock_destroy_multithreaded): M.
(glthread_recursive_lock_init_multithreaded): M.
(glthread_recursive_lock_lock_multithreaded): M.
* lib/glthread/thread.c (gl_thread_create): M.
* lib/group-member.c (group_member): M.
(main): M.
* lib/hash.c (hash_get_next): MB.
(check_tuning): M.
(hash_initialize): M.
(hash_clear): M.
(hash_free): MS.
(transfer_entries): M.
(hash_rehash): MR.
(hash_insert_if_absent): MR.
(hash_remove): MR.
(hash_print): M.
* lib/hasmntopt.c (hasmntopt): M.
* lib/hmac.c (hmac_hash): R.
(GL_HMAC_FN): R.
* lib/human.c (group_number): MRO.
(human_readable): MR.
(humblock): M.
* lib/hypot.c (hypot): M.
* lib/hypotl.c (hypotl): M.
* lib/i-ring.c (i_ring_pop): M.
* lib/iconv_open.c (rpl_iconv_open): R.
* lib/idcache.c (getuidbyname): M.
(getgidbyname): M.
* lib/inet_ntop.c (inet_ntop4): M.
(inet_ntop6): R.
* lib/inet_pton.c (inet_pton4): MRBO.
(inet_pton6): MRBO.
* lib/ino-map.c (ino_map_insert): M.
* lib/integer_length.c (integer_length): M.
* lib/ioctl.c (rpl_ioctl): M.
(ioctl): M.
* lib/is_l-impl.h (FUNC): M.
* lib/isatty.c (IsCygwinConsoleHandle): R.
* lib/isnan.c (FUNC): MR.
* lib/javacomp.c (compile_using_envjavac): MRB.
(compile_using_javac): MB.
(execute_and_read_line): M.
(write_temp_file): M.
(get_classfile_version): MR.
(is_envjavac_usable): MR.
(is_javac_present): M.
(is_javac_usable): MR.
(compile_java_class): MR.
* lib/javaexec.c (execute_java_class): MRBO.
* lib/javaversion.c (execute_and_read_line): M.
(javaexec_version): R.
* lib/kwset.c (treefails): M.
(kwsprep): MRSB.
(bmexec_trans): MRSO.
(acexec_trans): MRS.
* lib/lchown.c (rpl_lchown): R.
* lib/linebuffer.c (readlinebuffer_delim): RO.
* lib/link.c (link): MRBO.
(rpl_link): M.
* lib/linkat.c (link_immediate): R.
(link_follow): M.
(linkat_follow): M.
* lib/localcharset.c (locale_charset): MR.
* lib/localeinfo.c (is_using_utf8): R. Rename 'mbs' to 'state'.
(init_localeinfo): Rename 's' to 'state'.
* lib/localename.c (gl_locale_name): MSB.
* lib/localename-environ.c (gl_locale_name_environ): MSB.
* lib/localename-unsafe.c (gl_locale_name_canonicalize): MSB.
(gl_locale_name_from_win32_LANGID): M.
(gl_locale_name_from_win32_LCID): M.
(enum_locales_fn): R.
(gl_locale_name_unsafe): MSB.
* lib/log2.c (log2): M.
* lib/log2f.c (log2f): M.
* lib/log2l.c (log2l): M.
* lib/login_tty.c (login_tty): M.
* lib/logl.c (logl): MR.
* lib/long-options.c (parse_long_options): MR.
(parse_gnu_standard_options_only): M.
* lib/mbfile.h (mbfile_multi_getc): MR.
* lib/mbmemcasecoll.c (apply_c32tolower): M.
(mbmemcasecoll): MR.
* lib/mbrtoc32.c (mbrtoc32): R.
* lib/mbrtowc.c (rpl_mbrtowc): MRS.
* lib/mbrtowc-impl.h: MRB.
* lib/mbscasestr.c (knuth_morris_pratt_multibyte): MR.
(mbscasestr): R.
* lib/mbscspn.c (mbscspn): MR.
* lib/mbsnrtowcs-impl.h (FUNC): M.
* lib/mbspbrk.c (mbspbrk): MR.
* lib/mbsrtowcs-impl.h (FUNC): M.
* lib/mbsspn.c (mbsspn): MR.
* lib/mbsstr.c (knuth_morris_pratt_multibyte): MR.
(mbsstr): MR.
* lib/mbswidth.c (mbsnwidth): M.
* lib/mbtowc-impl.h (mbtowc): MR.
* lib/mbtowc-lock.h (mbtowc_with_lock): M.
* lib/mcel.h: MR in comments.
* lib/md2.c (md2_finish_ctx): M.
(md2_process_bytes): M.
(md2_update_chksum): M.
(md2_compress): M.
* lib/md2-stream.c (md2_stream): MR.
* lib/md4.c (md4_finish_ctx): M.
(md4_process_block): MR.
* lib/md4-stream.c (md4_stream): MR.
* lib/md5-stream.c (md5_stream): MR.
* lib/mem-hash-map.c (compute_hashval): M.
(lookup): M.
* lib/memchr.c (__memchr): MRB.
* lib/memchr2.c (memchr2): MRB.
* lib/memrchr.c (__memrchr): MRB.
* lib/mgetgroups.c (mgetgroups): MRS.
* lib/mkancesdirs.c (mkancesdirs): M.
* lib/mkdir.c (rpl_mkdir): MR.
* lib/mkdir-p.c (make_dir_parents): R.
* lib/modechange.c (mode_compile): R.
* lib/mountlist.c (fstype_to_string): M.
(dev_from_mount_options): MR.
(read_file_system_list): MR.
* lib/mpsort.c (mpsort_into_tmp): M.
(mpsort_with_tmp): M.
* lib/msvc-inval.h (TRY_MSVC_INVAL): M.
* lib/mtx.c (mtx_init): MSB.
* lib/nanosleep.c (nanosleep): M.
* lib/nl_langinfo.c (ctype_codeset): MR.
(nl_langinfo_with_lock): M.
* lib/nonblocking.c (get_nonblocking_flag): M.
(set_nonblocking_flag): M.
* lib/nproc.c (num_processors_via_affinity_mask): M.
(cgroup2_mount): MR.
(get_cgroup2_cpu_quota): M.
(parse_omp_threads): Remove variable 'ret'.
(num_processors): M.
* lib/obstack.c (_obstack_newchunk): M.
(_obstack_allocated_p): M.
(__obstack_free): M.
* lib/obstack_printf.c (OBSTACK_PRINTF): M.
(OBSTACK_VPRINTF): M.
* lib/omp-init.c (parse_omp_threads): Remove variable 'ret'.
* lib/openat-proc.c (openat_proc_name): R.
* lib/openat2.c (do_openat2): R.
(openat2): MSB.
* lib/opendir.c (opendir): MR.
* lib/openpty.c (openpty): M.
* lib/os2-spawn.c (prepare_spawn): M.
(spawnpvech): R.
* lib/pagealign_alloc.c (pagealign_alloc): MR.
(pagealign_xalloc): M.
(pagealign_free): M.
* lib/parse-duration.c (parse_scaled_value): M.
(parse_year_month_day): M.
(parse_yearmonthday): MR.
(parse_YMWD): SB.
(parse_hour_minute_second): M.
(parse_hourminutesecond): MR.
(parse_HMS): SB.
(parse_time): M.
(parse_period): MR.
(parse_non_iso8601): M.
* lib/passfd.c (sendfd): MRO.
(recvfd): MRO.
* lib/perror.c (perror): M.
* lib/physmem.c (physmem_total): M.
(physmem_claimable): M.
* lib/pipe-filter-gi.c (filter_loop): MRB.
(pipe_filter_gi_create): M.
(pipe_filter_gi_close): M.
* lib/pipe-filter-ii.c (_beginthreadex): M.
(WaitForMultipleObjects): MR.
(pipe_filter_ii_execute): MRB.
* lib/poll.c (IsSocketHandle): R.
(windows_compute_revents): MRB.
(windows_compute_revents_socket): M.
(poll): MRB. Remove variable 'bRet'.
* lib/popen.c (rpl_popen): MB.
* lib/posix_openpt.c (posix_openpt): M.
* lib/posixtm.c (posix_time_parse): R.
(posixtime): R.
* lib/pread.c (pread): M.
* lib/printf.c (printf): M.
* lib/printf-frexp.c (FUNC): R.
* lib/printf-parse.c (PRINTF_PARSE): MR.
* lib/progreloc.c (maybe_executable): R.
(find_executable): MRSB.
(prepare_relocate): M.
* lib/propername.c (mbsstr_trimmed_wordbounded): RSB.
(proper_name_utf8): M.
* lib/pselect.c (pselect): MR.
* lib/pt_chown.c (do_pt_chown): MR.
* lib/pthread-cond.c (pthread_cond_timedwait): R.
* lib/pthread-rwlock.c (pthread_rwlockattr_init): MSB.
(pthread_rwlock_init): MSB.
(pthread_rwlock_rdlock): MSB.
(pthread_rwlock_wrlock): MSB.
(pthread_rwlock_tryrdlock): MB.
(pthread_rwlock_trywrlock): MB.
(pthread_rwlock_timedrdlock): MSB.
(pthread_rwlock_timedwrlock): MSB.
(pthread_rwlock_unlock): MSB.
(pthread_rwlock_destroy): MSB.
(pthread_rwlock_init): MSB.
(pthread_rwlock_timedrdlock): MRB.
(pthread_rwlock_timedwrlock): MRB.
* lib/pthread_mutex_timedlock.c (pthread_mutex_timedlock): MRB.
* lib/pthread_sigmask.c (pthread_sigmask): MR.
* lib/ptsname_r.c (ptsname_r): MR.
* lib/putenv.c (putenv): M.
* lib/pwrite.c (pwrite): M.
* lib/qcopy-acl.c (qcopy_acl): Remove a use of variable 'ret'.
* lib/qset-acl.c (qset_acl): M.
* lib/qsort.c (_quicksort): MR.
* lib/quotearg.c (set_quoting_flags): M.
(quotearg_buffer_restyled): MRSB.
* lib/random.c (__initstate): M.
(__setstate): M.
(__random): R.
* lib/random_r.c (__srandom_r): M.
(__setstate_r): MO.
(__random_r): M.
* lib/rawmemchr.c (rawmemchr): RB.
* lib/read-file.c (fread_file): M.
(read_file): M.
* lib/readdir.c (readdir): MR.
* lib/readline.c (readline): R.
* lib/readtokens.c (readtoken): R.
(readtokens): M.
* lib/regex-quote.c (regex_quote_spec_gnu): MB.
(regex_quote_spec_pcre): MB.
(regex_quote_length): MR.
(regex_quote): MB.
* lib/relocatable.c (set_this_relocation_prefix): M.
(compute_curr_prefix): MR.
(find_shared_library_fullname): MRS.
(relocate): M.
* lib/relocwrapper.c (activate_libdirs): MB.
(main): M.
* lib/rename.c (rpl_rename): MRBO.
* lib/renameatu.c (renameatu): MRB.
* lib/rijndael-alg-fst.c (rijndaelKeySetupEnc): MSB.
(rijndaelKeySetupDec): MRSB.
(rijndaelEncrypt): MSB.
(rijndaelDecrypt): MSB.
* lib/rijndael-api-fst.c (rijndaelMakeKey): MRSB.
(rijndaelCipherInit): MSB.
(rijndaelBlockEncrypt): MRSB.
(rijndaelPadEncrypt): MRSB.
(rijndaelBlockDecrypt): MRSB.
(rijndaelPadDecrypt): MRSB.
* lib/rmdir.c (rpl_rmdir): M.
* lib/rpmatch.c (localized_pattern): MS.
(try): M.
(rpmatch): MSB.
* lib/same.c (same_nameat): R. Remove variable 'flags'.
* lib/savedir.c (streamsavedir): MRB.
* lib/scandir.c (SCANDIR): MR.
* lib/select.c (IsSocketHandle): R.
(windows_poll_handle): MRSB. Remove variable 'bRet'.
(rpl_select): MR. Remove variable 'bRet'.
* lib/set-permissions.c (set_acls_from_mode): R.
(context_acl_from_mode): R.
(context_aclv_from_mode): M.
(set_acls_from_mode): MR.
(context_acl_from_mode): M.
(set_acls): R.
(set_permissions): MS.
* lib/setenv.c (__add_to_environ): M.
(rpl_setenv): M.
* lib/sethostname.c (sethostname): MR.
* lib/setlocale.c (setlocale_unixlike): MR.
(langcmp): R.
(setlocale_improved): MR.
* lib/setlocale_null.c (setlocale_null_r_with_lock): M.
(setlocale_null): M.
* lib/setsockopt.c (rpl_setsockopt): R.
* lib/sh-quote.c (shell_quote_argv): MB.
* lib/sha1.c (sha1_process_block): R.
* lib/sha1-stream.c (sha1_stream): M.
* lib/sha256.c (sha256_process_block): MR.
* lib/sha256-stream.c (shaxxx_stream): M.
* lib/sha3.c (sha3_read_ctx): R.
(sha3_process_block): R.
* lib/sha3-stream.c (sha3_xxx_stream): M.
* lib/sha512-stream.c (shaxxx_stream): M.
* lib/sig2str.c (str2signum): RS.
(sig2str): MR.
* lib/sigaction.c (sigaction_handler): MR.
(sigaction): MRB.
* lib/sigprocmask.c (sigprocmask): M.
* lib/sigsegv.c (sigsegv_handler): MR.
* lib/sincosl.c (kernel_sinl): MRS.
(kernel_cosl): MRS.
* lib/sinl.c (sinl): MR.
* lib/sleep.c (rpl_sleep): M.
* lib/sm3.c (sm3_process_block): MR.
* lib/sm3-stream.c (sm3_stream): MR.
* lib/snprintf.c (snprintf): M.
* lib/snzprintf.c (snzprintf): M.
* lib/socket.c (rpl_socket): M.
* lib/sockets.c (close_fd_maybe_socket): MR.
(ioctl_fd_maybe_socket): MR.
(gl_sockets_startup): M.
(gl_sockets_cleanup): M.
* lib/spawn-pipe.c (create_pipe): MR.
* lib/spawni.c (__spawni): Split variable declaration.
* lib/sprintf.c (sprintf): M.
* lib/sqrtl.c (sqrtl): MR.
* lib/ssfmalloc.h (allocate_block_from_pool): MSB.
* lib/stackvma.c (rof_open): M.
(vma_iterate_proc): RSB.
(vma_iterate_bsd): MB.
(mapped_range_start): M.
(mapped_range_end): M.
(is_unmapped): MR.
(mapped_range_start): M.
(mapped_range_end): M.
(vma_iterate): MR.
* lib/stat-w32.c (_gl_convert_FILETIME_to_timespec): R.
* lib/stdio-consolesafe.c (gl_consolesafe_fprintf): R.
(gl_consolesafe_printf): R.
* lib/stdio-read.c (CALL_WITH_ERRNO_FIX): M.
(scanf): M.
(fscanf): M.
* lib/stdio-write.c (CALL_WITH_SIGPIPE_EMULATION): M.
(printf): M.
(fprintf): M.
* lib/stpncpy.c (__stpncpy): MSB.
* lib/str-kmp.h (knuth_morris_pratt): M.
* lib/str-two-way.h (critical_factorization): MSB.
(two_way_short_needle): MS.
(two_way_long_needle): MRS.
* lib/strcasecmp.c (strcasecmp): R.
* lib/strcasecmp_l.c (strcasecmp_l): MR.
* lib/strcasestr.c (strcasestr): MRSB.
* lib/strchrnul.c (strchrnul): MRB.
* lib/strerror.c (strerror): M.
* lib/strerror_l.c (strerror_l_r): R.
* lib/strerror_r.c (local_snprintf): M.
(strerror_r): M.
* lib/strfmon_l.c (rpl_strfmon_l): MR.
* lib/strftime.c (__strftime_internal): MR.
* lib/striconv.c (mem_cd_iconv): MR.
(str_cd_iconv): MR.
(str_iconv): M.
* lib/striconveh.c (iconveh_open): MR.
(utf8conv_carefully): M.
(mem_cd_iconveh_internal): MR.
(mem_iconveh): M.
(str_iconveh): M.
* lib/striconveha.c (uniconv_register_autodetect): MRSB.
(mem_iconveha_notranslit): MS.
(mem_iconveha): M.
(str_iconveha_notranslit): MS.
(str_iconveha): M.
* lib/string-buffer-printf.c (sb_appendvf): R.
(sb_appendf): R.
* lib/string-buffer-reversed-printf.c (sbr_prependvf): R.
(sbr_prependf): R.
* lib/string-desc.c (sd_new): R.
* lib/stripslash.c (strip_trailing_slashes): M.
* lib/strncasecmp.c (strncasecmp): R.
* lib/strncasecmp_l.c (strncasecmp_l): MR.
* lib/strptime.c (__strptime_internal): RSB.
* lib/strsep.c (strsep): R.
* lib/strsignal.c (strsignal): R.
* lib/strstr.c (strstr): MRSB.
* lib/strtod.c (parse_number): MR.
(STRTOD): MR.
* lib/strtok_r.c (__strtok_r): M.
* lib/strtol.c (strtol): MR.
* lib/struniq.h (struniq): M.
* lib/supersede.c (open_supersede): R.
* lib/system-quote.c (system_quote_argv): MB.
* lib/szprintf.c (szprintf): M.
* lib/tanl.c (kernel_tanl): MRS.
(tanl): MR.
* lib/tempname.c (try_tempname_len): M.
* lib/term-style-control.c (sprintf_integer): MR.
* lib/textstyle.in.h (ostream_printf): MR.
* lib/time.c (time): M.
* lib/times.c (filetime2clock): M.
* lib/timespec-add.c (timespec_add): R.
* lib/timespec-sub.c (timespec_sub): R.
* lib/tmpdir.c (path_search): MR.
* lib/tmpfile.c (tmpfile): M.
* lib/to_l-impl.h (FUNC): M.
* lib/tparm.c (tparm): MRB.
* lib/trigl.c (ieee754_rem_pio2l): MRS.
(kernel_rem_pio2): MRS.
* lib/trim.c (trim2): MR.
* lib/tsearch.c (check_tree): R.
(maybe_split_for_insert): M.
(__tsearch): MR.
(__tfind): M.
(__tdelete): MRB.
* lib/ttyname_r.c (ttyname_r): M.
* lib/uname.c (uname): MR.
* lib/unicase/locale-language.c (uc_locale_language): M.
* lib/unicase/u-casecmp.h (FUNC): MR.
* lib/unicase/u-casecoll.h (FUNC): MR.
* lib/unicase/u-casemap.h (FUNC): MR.
* lib/unicase/u-casexfrm.h (FUNC): MR.
* lib/unicase/u-ct-casefold.h (FUNC): MR.
* lib/unicase/u-ct-totitle.h (FUNC): MR.
* lib/unicase/u-is-cased.h (FUNC): MR.
* lib/unicase/u-is-invariant.h (FUNC): MR.
* lib/unicase/u8-casefold.c (read_file): M.
* lib/unicase/u8-tolower.c (read_file): M.
* lib/unicase/u8-totitle.c (read_file): M.
* lib/unicase/u8-toupper.c (read_file): M.
* lib/unicase/ulc-casecmp.c (ulc_u8_casefold): MR.
* lib/unicase/ulc-casexfrm.c (ulc_casexfrm): MR.
* lib/unicodeio.c (unicode_to_mb): MR.
* lib/uniconv/u-conv-from-enc.h (FUNC): M.
* lib/uniconv/u-conv-to-enc.h (FUNC): MR.
* lib/uniconv/u-strconv-from-enc.h (FUNC): M.
* lib/uniconv/u-strconv-to-enc.h (FUNC): M.
* lib/uniconv/u16-conv-to-enc.c (FUNC): MR.
* lib/uniconv/u8-conv-from-enc.c (u8_conv_from_encoding): R.
* lib/uniconv/u8-conv-to-enc.c (u8_conv_to_encoding): R.
* lib/uniconv/u8-strconv-to-enc.c (u8_strconv_to_encoding): MS.
* lib/unictype/3level.h (CONCAT(TABLE,_add)): M.
(CONCAT(TABLE,_finalize)): MRB.
* lib/unictype/3levelbit.h (CONCAT(TABLE,_add)): M.
(CONCAT(TABLE,_finalize)): MRB.
* lib/unictype/bidi_byname.c (uc_bidi_class_byname): M.
* lib/unictype/categ_and.c (uc_general_category_and): MR.
* lib/unictype/categ_and_not.c (uc_general_category_and_not): MR.
* lib/unictype/categ_byname.c (uc_general_category_byname): M.
* lib/unictype/categ_of.c (uc_general_category): R.
* lib/unictype/categ_or.c (uc_general_category_or): MR.
* lib/unictype/combiningclass_byname.c (uc_combining_class_byname): M.
* lib/unictype/incb_byname.c (uc_indic_conjunct_break_byname): M.
* lib/unictype/joininggroup_byname.c (uc_joining_group_byname): M.
* lib/unictype/joiningtype_byname.c (uc_joining_type_byname): M.
* lib/unictype/pr_byname.c (uc_property_byname): MRB.
* lib/unictype/scripts.c (uc_script_byname): M.
* lib/unigbrk/u-grapheme-prev.h
(ends_with_incb_consonant_extended_linker_extended): M.
(ends_with_emoji_modifier_sequence): M.
(ends_with_ri_count): M.
(FUNC): M.
* lib/unigbrk/uc-is-grapheme-break.c (uc_is_grapheme_break): M.
* lib/unigbrk/ulc-grapheme-breaks.c (ulc_grapheme_breaks): M.
* lib/unilbrk/u16-width-linebreaks.c (u16_width_linebreaks_internal): M.
* lib/unilbrk/u32-width-linebreaks.c (u32_width_linebreaks_internal): M.
* lib/unilbrk/u8-possible-linebreaks.c (read_file): M.
* lib/unilbrk/u8-width-linebreaks.c (u8_width_linebreaks_internal): M.
(read_file): M.
* lib/unilbrk/ulc-possible-linebreaks.c
(ulc_possible_linebreaks_internal): M.
(read_file): M.
* lib/unilbrk/ulc-width-linebreaks.c (ulc_width_linebreaks_internal): M.
(read_file): M.
* lib/uniname/uniname.c (unicode_name_word): MR.
(unicode_character_name): M.
(unicode_name_character): MR.
* lib/uninorm/canonical-decomposition.c (uc_canonical_decomposition): M.
* lib/uninorm/composition.c (uc_composition): M.
* lib/uninorm/decomposition.c (uc_decomposition): M.
* lib/uninorm/u-normalize-internal.h (FUNC): MR.
* lib/uninorm/u-normcmp.h (FUNC): MR.
* lib/uninorm/u-normcoll.h (FUNC): MR.
* lib/uninorm/u-normxfrm.h (FUNC): MR.
* lib/uninorm/uninorm-filter.c (uninorm_filter_write): M.
* lib/unistdio/u-asnprintf.h (ASNPRINTF): M.
* lib/unistdio/u-asprintf.h (ASPRINTF): M.
* lib/unistdio/u-snprintf.h (SNPRINTF): M.
* lib/unistdio/u-sprintf.h (SPRINTF): M.
* lib/unistdio/u-vsnprintf.h (VSNPRINTF): M.
* lib/unistdio/u-vsprintf.h (VSPRINTF): M.
* lib/unistdio/ulc-fprintf.c (ulc_fprintf): M.
* lib/unistdio/ulc-vfprintf.c (ulc_vfprintf): M.
* lib/unistr/u16-chr.c (u16_chr): R.
* lib/unistr/u16-mbsnlen.c (u16_mbsnlen): M.
* lib/unistr/u16-next.c (u16_next): M.
* lib/unistr/u16-strchr.c (u16_strchr): R.
* lib/unistr/u16-strrchr.c (u16_strrchr): R.
* lib/unistr/u16-to-u32.c (FUNC): MR.
* lib/unistr/u16-to-u8.c (FUNC): MR.
* lib/unistr/u32-next.c (u32_next): M.
* lib/unistr/u32-to-u16.c (FUNC): MR.
* lib/unistr/u32-to-u8.c (FUNC): MR.
* lib/unistr/u8-chr.c (u8_chr): M.
* lib/unistr/u8-mbsnlen.c (u8_mbsnlen): M.
* lib/unistr/u8-next.c (u8_next): M.
* lib/unistr/u8-strchr.c (u8_strchr): R.
* lib/unistr/u8-strrchr.c (u8_strrchr): R.
* lib/unistr/u8-to-u16.c (FUNC): MR.
* lib/unistr/u8-to-u32.c (FUNC): MR.
* lib/uniwbrk/u8-wordbreaks.c (read_file): M.
* lib/uniwbrk/ulc-wordbreaks.c (ulc_wordbreaks): M.
(read_file): M.
* lib/uniwidth/u16-width.c (u16_width): M.
* lib/uniwidth/u32-width.c (u32_width): M.
* lib/uniwidth/u8-width.c (u8_width): M.
* lib/unlinkat.c (rpl_unlinkat): MR.
* lib/unsetenv.c (unsetenv): M.
(rpl_unsetenv): R.
* lib/userspec.c (parse_with_separator): MRS.
(main): MR.
* lib/utime.c (_gl_utimens_windows): M.
* lib/utimecmp.c (utimecmpat): R.
* lib/utimens.c (validate_timespec): R.
(fdutimens): MR.
(lutimens): MR.
* lib/utimensat.c (rpl_utimensat): M.
* lib/vasnprintf.c (divide): M.
(decode_long_double): MR.
(decode_double): MR.
(scale10_round_decimal_decoded): MR.
(floorlog10l): MR.
(floorlog10): MR.
(VASNPRINTF): MR.
* lib/vc-mtime.c (is_git_present): MR.
(git_vc_controlled): MR.
(git_unmodified): M.
(git_mtime): MR.
(abs_git_checkout): MR.
(max_vc_mtime): MR.
* lib/vdzprintf.c (vdzprintf): M.
* lib/vfzprintf.c (vfzprintf): M.
* lib/vma-iter.c (rof_open): M.
(vma_iterate_proc): MRSB.
(vma_iterate_bsd): MB.
(vma_iterate): MR.
* lib/vsnzprintf.c (vsnzprintf): M.
* lib/vszprintf.c (vszprintf): M.
* lib/wait-process.c (klibc_waitpid): M.
(wait_subprocess): MR.
* lib/wcs-two-way.h (critical_factorization): MSB.
(two_way_short_needle): MS.
* lib/wcsstr-impl.h (FUNC): MRSB.
* lib/wcswidth-impl.h (FUNC): B.
* lib/wcsxfrm-impl.h (wcsxfrm): MR.
* lib/wctomb-impl.h (wctomb): M.
* lib/wgetcwd-lgpl.c (wgetcwd): MRS.
* lib/windows-cond.c (glwthread_waitqueue_add): M.
(glwthread_waitqueue_notify_first): M.
(glwthread_waitqueue_notify_all): M.
(glwthread_cond_wait): M.
(glwthread_cond_timedwait): MRS.
* lib/windows-cygpath.c (execute_and_read_line): MR.
* lib/windows-rwlock.c (glwthread_waitqueue_add): M.
(glwthread_rwlock_rdlock): M.
(glwthread_rwlock_wrlock): M.
* lib/windows-spawn.c (quoted_arg_length): M.
(quoted_arg_string): M.
(prepare_spawn): MR.
(compose_command): MRB.
(compose_envblock): RSB.
* lib/windows-thread.c (glwthread_thread_self): M.
(glwthread_thread_create): M.
* lib/windows-timedmutex.c (glwthread_timedmutex_timedlock): MR.
* lib/windows-timedrecmutex.c (glwthread_timedrecmutex_timedlock): MR.
* lib/windows-timedrwlock.c (glwthread_waitqueue_add): M.
(glwthread_waitqueue_notify_first): M.
(glwthread_waitqueue_notify_all): M.
(glwthread_timedrwlock_rdlock): M.
(glwthread_timedrwlock_wrlock): M.
(glwthread_timedrwlock_timedrdlock): MR.
(glwthread_timedrwlock_timedwrlock): MR.
* lib/xasprintf.c (xasprintf): M.
* lib/xconcat-filename.c (xconcatenated_filename): M.
* lib/xmalloc.c (xpalloc): R.
* lib/xmalloca.c (xmmalloca): M.
* lib/xprintf.c (xprintf): M.
(xfprintf): M.
* lib/xstring-buffer-printf.c (sb_xappendf): M.
* lib/xstring-buffer-reversed-printf.c (sbr_xprependf): M.
* lib/xstrtod.c (XSTRTOD): MR.
* lib/xstrtol.c (__xstrtol): R.
* lib/xstrtol-error.c (xstrtol_error): R.
* lib/xvasprintf.c (xstrcat): MB.
(xvasprintf): R.
* lib/zprintf.c (zprintf): M.

514 files changed:
ChangeLog
lib/accept4.c
lib/acl-internal.c
lib/acosl.c
lib/af_alg.c
lib/alignalloc.h
lib/alloca.c
lib/amemxfrm.c
lib/arcfour.c
lib/arctwo.c
lib/areadlink-with-size.c
lib/areadlinkat-with-size.c
lib/argmatch.c
lib/argp-fmtstream.c
lib/argp-fmtstream.h
lib/argp-help.c
lib/argp-parse.c
lib/argz.c
lib/asinl.c
lib/asnprintf.c
lib/asnwprintf.c
lib/asprintf.c
lib/astrxfrm.c
lib/aszprintf.c
lib/at-func.c
lib/at-func2.c
lib/atanl.c
lib/backupfile.c
lib/base32.c
lib/base64.c
lib/basename-lgpl.c
lib/bitset.c
lib/bitset/list.c
lib/bitset/table.c
lib/boot-time-aux.h
lib/btoc32.c
lib/c-asprintf.c
lib/c-aszprintf.c
lib/c-snprintf.c
lib/c-snzprintf.c
lib/c-strcasecmp.c
lib/c-strcasestr.c
lib/c-strncasecmp.c
lib/c-strtod.c
lib/c-vsnzprintf.c
lib/c-xasprintf.c
lib/c32stombs.c
lib/c32tob.c
lib/canon-host.c
lib/canonicalize-lgpl.c
lib/canonicalize.c
lib/cbrt.c
lib/cbrtf.c
lib/cbrtl.c
lib/chdir-long.c
lib/classpath.c
lib/clean-temp-simple.c
lib/clean-temp.c
lib/copy-file.c
lib/cosl.c
lib/crc-generate-table.c
lib/crc-x86_64-pclmul.c
lib/crc.c
lib/csharpcomp.c
lib/csharpexec.c
lib/cygpath.c
lib/des.c
lib/dfa.c
lib/di-set.c
lib/dirname-lgpl.c
lib/dprintf.c
lib/dup.c
lib/dup2.c
lib/dup3.c
lib/duplocale.c
lib/dzprintf.c
lib/euidaccess.c
lib/exclude.c
lib/execl.c
lib/execle.c
lib/execlp.c
lib/execute.c
lib/fchdir.c
lib/fclose.c
lib/fcntl.c
lib/fdopen.c
lib/file-has-acl.c
lib/file-remote.c
lib/file-set.c
lib/findprog-in.c
lib/findprog.c
lib/flock.c
lib/fma.c
lib/fopen.c
lib/forkpty.c
lib/fprintf.c
lib/freadseek.c
lib/freopen-safer.c
lib/freopen.c
lib/frexp.c
lib/fseterr.c
lib/fstatat.c
lib/fstrcmp.c
lib/fsusage.c
lib/fsync.c
lib/ftello.c
lib/ftruncate.c
lib/fts-cycle.c
lib/fts.c
lib/fzprintf.c
lib/gc-gnulib.c
lib/gc-libgcrypt.c
lib/gc-pbkdf2.c
lib/gen-uni-tables.c
lib/get-rusage-as.c
lib/get-rusage-data.c
lib/get_ppid_of.c
lib/get_progname_of.c
lib/getaddrinfo.c
lib/getcwd-lgpl.c
lib/getcwd.c
lib/getdelim.c
lib/getdomainname.c
lib/getentropy.c
lib/getgroups.c
lib/gethostname.c
lib/getloadavg.c
lib/getlocalename_l-unsafe.c
lib/getlogin_r.c
lib/getndelim2.c
lib/getopt.c
lib/getopt1.c
lib/getpass.c
lib/getprogname.c
lib/getrusage.c
lib/getsockopt.c
lib/getsubopt.c
lib/gettext.h
lib/gettimeofday.c
lib/getugroups.c
lib/getumask.c
lib/gl_anyavltree_list2.h
lib/gl_anyhash2.h
lib/gl_anylinked_list2.h
lib/gl_anyrbtree_list2.h
lib/gl_anytree_list2.h
lib/gl_anytree_omap.h
lib/gl_anytree_oset.h
lib/gl_anytreehash_list1.h
lib/gl_array_list.c
lib/gl_array_map.c
lib/gl_array_omap.c
lib/gl_array_oset.c
lib/gl_array_set.c
lib/gl_avltree_ordered.h
lib/gl_carray_list.c
lib/gl_rbtree_ordered.h
lib/gl_sublist.c
lib/glob.c
lib/globfree.c
lib/glthread/lock.c
lib/glthread/thread.c
lib/group-member.c
lib/hash.c
lib/hasmntopt.c
lib/hmac.c
lib/human.c
lib/hypot.c
lib/hypotl.c
lib/i-ring.c
lib/iconv_open.c
lib/idcache.c
lib/inet_ntop.c
lib/inet_pton.c
lib/ino-map.c
lib/integer_length.c
lib/ioctl.c
lib/is_l-impl.h
lib/isapipe.c
lib/isatty.c
lib/isnan.c
lib/javacomp.c
lib/javaexec.c
lib/javaversion.c
lib/kwset.c
lib/lchown.c
lib/linebuffer.c
lib/link.c
lib/linkat.c
lib/localcharset.c
lib/localeinfo.c
lib/localename-environ.c
lib/localename-unsafe.c
lib/localename.c
lib/log2.c
lib/log2f.c
lib/log2l.c
lib/login_tty.c
lib/logl.c
lib/long-options.c
lib/mbfile.h
lib/mbmemcasecoll.c
lib/mbrtoc32.c
lib/mbrtowc-impl.h
lib/mbrtowc.c
lib/mbscasestr.c
lib/mbscspn.c
lib/mbsnrtowcs-impl.h
lib/mbspbrk.c
lib/mbsrtowcs-impl.h
lib/mbsspn.c
lib/mbsstr.c
lib/mbstoc32s.c
lib/mbstowcs.c
lib/mbswidth.c
lib/mbtowc-impl.h
lib/mbtowc-lock.h
lib/mcel.h
lib/md2-stream.c
lib/md2.c
lib/md4-stream.c
lib/md4.c
lib/md5-stream.c
lib/mem-hash-map.c
lib/memchr.c
lib/memchr2.c
lib/memrchr.c
lib/mgetgroups.c
lib/mkancesdirs.c
lib/mkdir-p.c
lib/mkdir.c
lib/modechange.c
lib/mountlist.c
lib/mpsort.c
lib/msvc-inval.h
lib/mtx.c
lib/nanosleep.c
lib/nl_langinfo.c
lib/nonblocking.c
lib/nproc.c
lib/obstack.c
lib/obstack_printf.c
lib/omp-init.c
lib/openat-proc.c
lib/openat2.c
lib/opendir.c
lib/openpty.c
lib/os2-spawn.c
lib/pagealign_alloc.c
lib/parse-duration.c
lib/passfd.c
lib/perror.c
lib/physmem.c
lib/pipe-filter-gi.c
lib/pipe-filter-ii.c
lib/poll.c
lib/popen.c
lib/posix_openpt.c
lib/posixtm.c
lib/pread.c
lib/printf-frexp.c
lib/printf-parse.c
lib/printf.c
lib/progreloc.c
lib/propername.c
lib/pselect.c
lib/pt_chown.c
lib/pthread-cond.c
lib/pthread-rwlock.c
lib/pthread_mutex_timedlock.c
lib/pthread_sigmask.c
lib/ptsname_r.c
lib/putenv.c
lib/pwrite.c
lib/qcopy-acl.c
lib/qset-acl.c
lib/qsort.c
lib/quotearg.c
lib/random.c
lib/random_r.c
lib/rawmemchr.c
lib/read-file.c
lib/readdir.c
lib/readline.c
lib/readtokens.c
lib/regex-quote.c
lib/relocatable.c
lib/relocwrapper.c
lib/rename.c
lib/renameatu.c
lib/rijndael-alg-fst.c
lib/rijndael-api-fst.c
lib/rmdir.c
lib/rpmatch.c
lib/same.c
lib/savedir.c
lib/scandir.c
lib/select.c
lib/set-permissions.c
lib/setenv.c
lib/sethostname.c
lib/setlocale.c
lib/setlocale_null.c
lib/setsockopt.c
lib/sh-quote.c
lib/sha1-stream.c
lib/sha1.c
lib/sha256-stream.c
lib/sha256.c
lib/sha3-stream.c
lib/sha3.c
lib/sha512-stream.c
lib/sig2str.c
lib/sigaction.c
lib/sigprocmask.c
lib/sigsegv.c
lib/sincosl.c
lib/sinl.c
lib/sleep.c
lib/sm3-stream.c
lib/sm3.c
lib/snprintf.c
lib/snzprintf.c
lib/socket.c
lib/sockets.c
lib/spawn-pipe.c
lib/spawni.c
lib/sprintf.c
lib/sqrtl.c
lib/ssfmalloc.h
lib/stackvma.c
lib/stat-w32.c
lib/stdio-consolesafe.c
lib/stdio-read.c
lib/stdio-write.c
lib/stpncpy.c
lib/str-kmp.h
lib/str-two-way.h
lib/strcasecmp.c
lib/strcasecmp_l.c
lib/strcasestr.c
lib/strchrnul.c
lib/strerror.c
lib/strerror_l.c
lib/strerror_r.c
lib/strfmon_l.c
lib/strftime.c
lib/striconv.c
lib/striconveh.c
lib/striconveha.c
lib/string-buffer-printf.c
lib/string-buffer-reversed-printf.c
lib/string-desc.c
lib/stripslash.c
lib/strncasecmp.c
lib/strncasecmp_l.c
lib/strptime.c
lib/strsep.c
lib/strsignal.c
lib/strstr.c
lib/strtod.c
lib/strtok_r.c
lib/strtol.c
lib/struniq.h
lib/supersede.c
lib/system-quote.c
lib/szprintf.c
lib/tanl.c
lib/tempname.c
lib/term-style-control.c
lib/textstyle.in.h
lib/time.c
lib/times.c
lib/timespec-add.c
lib/timespec-sub.c
lib/tmpdir.c
lib/tmpfile.c
lib/to_l-impl.h
lib/tparm.c
lib/trigl.c
lib/trim.c
lib/tsearch.c
lib/ttyname_r.c
lib/uname.c
lib/unicase/locale-language.c
lib/unicase/u-casecmp.h
lib/unicase/u-casecoll.h
lib/unicase/u-casemap.h
lib/unicase/u-casexfrm.h
lib/unicase/u-ct-casefold.h
lib/unicase/u-ct-totitle.h
lib/unicase/u-is-cased.h
lib/unicase/u-is-invariant.h
lib/unicase/u8-casefold.c
lib/unicase/u8-tolower.c
lib/unicase/u8-totitle.c
lib/unicase/u8-toupper.c
lib/unicase/ulc-casecmp.c
lib/unicase/ulc-casexfrm.c
lib/unicodeio.c
lib/uniconv/u-conv-from-enc.h
lib/uniconv/u-conv-to-enc.h
lib/uniconv/u-strconv-from-enc.h
lib/uniconv/u-strconv-to-enc.h
lib/uniconv/u16-conv-to-enc.c
lib/uniconv/u8-conv-from-enc.c
lib/uniconv/u8-conv-to-enc.c
lib/uniconv/u8-strconv-to-enc.c
lib/unictype/3level.h
lib/unictype/3levelbit.h
lib/unictype/bidi_byname.c
lib/unictype/categ_and.c
lib/unictype/categ_and_not.c
lib/unictype/categ_byname.c
lib/unictype/categ_of.c
lib/unictype/categ_or.c
lib/unictype/combiningclass_byname.c
lib/unictype/combiningclass_longname.c
lib/unictype/combiningclass_name.c
lib/unictype/incb_byname.c
lib/unictype/joininggroup_byname.c
lib/unictype/joiningtype_byname.c
lib/unictype/pr_byname.c
lib/unictype/scripts.c
lib/unigbrk/u-grapheme-prev.h
lib/unigbrk/uc-is-grapheme-break.c
lib/unigbrk/ulc-grapheme-breaks.c
lib/unilbrk/u16-width-linebreaks.c
lib/unilbrk/u32-width-linebreaks.c
lib/unilbrk/u8-possible-linebreaks.c
lib/unilbrk/u8-width-linebreaks.c
lib/unilbrk/ulc-possible-linebreaks.c
lib/unilbrk/ulc-width-linebreaks.c
lib/uniname/uniname.c
lib/uninorm/canonical-decomposition.c
lib/uninorm/composition.c
lib/uninorm/decomposition.c
lib/uninorm/u-normalize-internal.h
lib/uninorm/u-normcmp.h
lib/uninorm/u-normcoll.h
lib/uninorm/u-normxfrm.h
lib/uninorm/uninorm-filter.c
lib/unistdio/u-asnprintf.h
lib/unistdio/u-asprintf.h
lib/unistdio/u-snprintf.h
lib/unistdio/u-sprintf.h
lib/unistdio/u-vsnprintf.h
lib/unistdio/u-vsprintf.h
lib/unistdio/ulc-fprintf.c
lib/unistdio/ulc-vfprintf.c
lib/unistr/u16-chr.c
lib/unistr/u16-mbsnlen.c
lib/unistr/u16-next.c
lib/unistr/u16-strchr.c
lib/unistr/u16-strrchr.c
lib/unistr/u16-to-u32.c
lib/unistr/u16-to-u8.c
lib/unistr/u32-next.c
lib/unistr/u32-to-u16.c
lib/unistr/u32-to-u8.c
lib/unistr/u8-chr.c
lib/unistr/u8-mbsnlen.c
lib/unistr/u8-next.c
lib/unistr/u8-strchr.c
lib/unistr/u8-strrchr.c
lib/unistr/u8-to-u16.c
lib/unistr/u8-to-u32.c
lib/uniwbrk/u8-wordbreaks.c
lib/uniwbrk/ulc-wordbreaks.c
lib/uniwidth/u16-width.c
lib/uniwidth/u32-width.c
lib/uniwidth/u8-width.c
lib/unlinkat.c
lib/unsetenv.c
lib/userspec.c
lib/utime.c
lib/utimecmp.c
lib/utimens.c
lib/utimensat.c
lib/vasnprintf.c
lib/vc-mtime.c
lib/vdzprintf.c
lib/version-etc.c
lib/vfzprintf.c
lib/vma-iter.c
lib/vsnzprintf.c
lib/vszprintf.c
lib/wait-process.c
lib/wcs-two-way.h
lib/wcsstr-impl.h
lib/wcswidth-impl.h
lib/wcsxfrm-impl.h
lib/wctomb-impl.h
lib/wgetcwd-lgpl.c
lib/windows-cond.c
lib/windows-cygpath.c
lib/windows-rwlock.c
lib/windows-spawn.c
lib/windows-thread.c
lib/windows-timedmutex.c
lib/windows-timedrecmutex.c
lib/windows-timedrwlock.c
lib/xasprintf.c
lib/xconcat-filename.c
lib/xmalloc.c
lib/xmalloca.c
lib/xprintf.c
lib/xstring-buffer-printf.c
lib/xstring-buffer-reversed-printf.c
lib/xstrtod.c
lib/xstrtol-error.c
lib/xstrtol.c
lib/xvasprintf.c
lib/zprintf.c

index f5097cb454c7570c34e334b2f575130d70062e0d..233cdec768648ed50c8cee3b339915b0ea69bd93 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,991 @@
+2025-12-09  Bruno Haible  <bruno@clisp.org>
+
+       lib: Reduce scope of local variables.
+       M = Move variable declaration to its initialization.
+       R = Reduce scope.
+       S = Split scope, create separate variables from one variable.
+       B = Insert braces, creating a block scope.
+       O = Change order of initializations.
+       * lib/accept4.c (accept4): M.
+       * lib/acl-internal.c (acl_ace_nontrivial): R.
+       * lib/acosl.c (acosl): MS.
+       * lib/af_alg.c (afalg_stream): B.
+       * lib/alignalloc.h (alignalloc): R.
+       * lib/alloca.c (find_stack_direction): M.
+       (alloca): M.
+       * lib/amemxfrm.c (amemxfrm): MR.
+       * lib/arcfour.c (arcfour_stream): MB.
+       (arcfour_setkey): MB.
+       * lib/arctwo.c (arctwo_encrypt): M.
+       (arctwo_decrypt): M.
+       (arctwo_setkey_ekb): M.
+       * lib/areadlink-with-size.c (areadlink_with_size): MR.
+       * lib/areadlinkat-with-size.c (areadlinkat_with_size): MR.
+       * lib/argmatch.c (argmatch): MO.
+       (main): RBO.
+       * lib/argp-fmtstream.c (__argp_make_fmtstream): M.
+       (__argp_fmtstream_update): M.
+       (__argp_fmtstream_ensure): R.
+       (__argp_fmtstream_printf): R.
+       * lib/argp-fmtstream.h (__argp_fmtstream_set_lmargin): M.
+       (__argp_fmtstream_set_rmargin): M.
+       (__argp_fmtstream_set_wmargin): M.
+       * lib/argp-help.c (validate_uparams): M.
+       (fill_in_uparams): MR.
+       (make_hol): MRSO.
+       (hol_entry_short_iterate): R.
+       (hol_entry_long_iterate): R.
+       (hol_entry_first_long): Rename 'num' to 'nopts'.
+       (canon_doc_option): M.
+       (hol_append): MR.
+       (argp_hol): O.
+       (hol_entry_help): RSBO.
+       (hol_help): RB.
+       (usage_argful_short_opt): R.
+       (usage_long_opt): R.
+       (hol_usage): SB.
+       (argp_args_levels): R.
+       (argp_args_usage): MRB.
+       (argp_doc): RBO.
+       (_help): MR.
+       (__argp_error): R.
+       * lib/argp-parse.c (group_parse): M.
+       (parser_init): MRB.
+       (parser_finalize): MS.
+       (parser_parse_next): R.
+       (__argp_parse): MR.
+       (__argp_input): M.
+       * lib/argz.c (argz_add_sep): M.
+       (argz_create_sep): M.
+       (argz_create): R.
+       (argz_replace): RB.
+       * lib/asinl.c (asinl): MRS.
+       * lib/asnprintf.c (asnprintf): M.
+       * lib/asnwprintf.c (asnwprintf): M.
+       * lib/asprintf.c (asprintf): M.
+       * lib/astrxfrm.c (astrxfrm): MR.
+       * lib/aszprintf.c (aszprintf): M.
+       * lib/at-func.c (AT_FUNC_NAME): MR.
+       * lib/at-func2.c (at_func2): MRS.
+       * lib/atanl.c (atanl): MRS.
+       * lib/backupfile.c (numbered_backup): R.
+       * lib/base32.c (decode_8): R.
+       (base32_decode_ctx): R.
+       * lib/base64.c (decode_4): R.
+       (base64_decode_ctx): R.
+       * lib/basename-lgpl.c (last_component): R.
+       (base_len): RO.
+       * lib/bitset.c (bitset_copy_): R.
+       * lib/bitset/list.c (lbitset_prune): MR.
+       (lbitset_weed): MR.
+       (lbitset_list): SB.
+       * lib/bitset/table.c (tbitset_list): SB.
+       * lib/boot-time-aux.h (get_windows_boot_time_fallback): R.
+       * lib/btoc32.c (btoc32): R.
+       * lib/c-asprintf.c (c_asprintf): M.
+       * lib/c-aszprintf.c (c_aszprintf): M.
+       * lib/c-snprintf.c (c_snprintf): M.
+       * lib/c-snzprintf.c (c_snzprintf): M.
+       * lib/c-strcasecmp.c (c_strcasecmp): R.
+       * lib/c-strcasestr.c (c_strcasestr): MRSB.
+       * lib/c-strncasecmp.c (c_strncasecmp): R.
+       * lib/c-strtod.c (C_STRTOD): R.
+       * lib/c-vsnzprintf.c (c_vsnzprintf): M.
+       * lib/c-xasprintf.c (c_xasprintf): M.
+       * lib/c32tob.c (c32tob): R.
+       * lib/canon-host.c (canon_host_r): MR.
+       * lib/canonicalize.c (canonicalize_filename_mode_stk): R.
+       * lib/canonicalize-lgpl.c (realpath_stk): R.
+       * lib/cbrt.c (cbrt): M.
+       * lib/cbrtf.c (cbrtf): M.
+       * lib/cbrtl.c (cbrtl): MR.
+       * lib/chdir-long.c (chdir_long): M.
+       (main): MR.
+       * lib/classpath.c (new_classpath): MB.
+       * lib/clean-temp.c (create_temp_dir): M.
+       (unregister_temp_file): M.
+       (unregister_temp_subdir): M.
+       (cleanup_temp_file): M.
+       (cleanup_temp_subdir): M.
+       (cleanup_temp_dir_contents): MSB.
+       (open_temp): R.
+       (fopen_temp): R.
+       (close_temp): RB.
+       (fclose_variant_temp): RB.
+       * lib/clean-temp-simple.c (cleanup_action): MSB.
+       (cleanup_temporary_file): M.
+       * lib/copy-file.c (copy_file_internal): MRB.
+       * lib/cosl.c (cosl): MR.
+       * lib/crc-generate-table.c (make_crc_table): M.
+       * lib/crc-x86_64-pclmul.c (crc32_update_no_xor_pclmul): MRSB.
+       * lib/crc.c (crc32_update_no_xor_slice_by_8): S.
+       (crc32_update_no_xor_slice_by_n): M.
+       (crc32_update_no_xor): MR.
+       * lib/csharpcomp.c (compile_csharp_using_mono): MRB.
+       (compile_csharp_using_dotnet): MRSB.
+       (compile_csharp_using_sscli): MRB.
+       * lib/csharpexec.c (execute_csharp_using_mono): MO.
+       (execute_csharp_using_dotnet): MO.
+       (execute_csharp_using_sscli): MO.
+       (execute_csharp_program): R.
+       * lib/cygpath.c (execute_and_read_line): M.
+       * lib/des.c (gl_des_is_weak_key): M.
+       (gl_3des_ecb_crypt): MO.
+       * lib/dfa.c (closure): B.
+       (dfamust): MRB.
+       * lib/di-set.c (map_device): M.
+       (di_set_insert): M.
+       (di_set_lookup): M.
+       * lib/dirname-lgpl.c (dir_len): R.
+       * lib/dprintf.c (dprintf): M.
+       * lib/dup.c (dup_nothrow): R.
+       * lib/dup2.c (ms_windows_dup2): M.
+       (klibc_dup2dirfd): M.
+       (klibc_dup2): MR.
+       (rpl_dup2): M.
+       * lib/dup3.c (dup3): M.
+       * lib/duplocale.c (duplocale): MRSB.
+       * lib/dzprintf.c (dzprintf): M.
+       * lib/euidaccess.c (euidaccess): MR.
+       (main): M.
+       * lib/exclude.c (add_exclude): R.
+       * lib/execl.c (execl): SB.
+       * lib/execle.c (execle): SB.
+       * lib/execlp.c (execlp): SB.
+       * lib/execute.c (execute): R.
+       * lib/fchdir.c (ensure_dirs_slot): M.
+       (get_name): M.
+       (_gl_register_fd): R.
+       * lib/fclose.c (rpl_fclose): MR.
+       * lib/fcntl.c (dupfd): RO.
+       (fcntl): R.
+       (klibc_dupdirfd): M.
+       (klibc_fcntl): MRSB.
+       * lib/fdopen.c (rpl_fdopen): M.
+       * lib/file-has-acl.c (get_aclinfo): R.
+       (fdfile_has_aclinfo): MR.
+       * lib/file-remote.c (main): M.
+       * lib/file-set.c (record_file): M.
+       (seen_file): R.
+       * lib/findprog.c (find_in_path): MR.
+       * lib/findprog-in.c (find_in_given_path): MR.
+       * lib/flock.c (do_lock): MR.
+       (do_unlock): M.
+       (flock): MR.
+       * lib/fma.c (decode): M.
+       * lib/fopen.c (rpl_fopen): MR.
+       * lib/forkpty.c (forkpty): M.
+       * lib/fprintf.c (fprintf): M.
+       * lib/freadseek.c (freadseek): MR.
+       * lib/freopen.c (rpl_freopen): M.
+       * lib/freopen-safer.c (freopen_safer): M.
+       * lib/frexp.c (FUNC): MR.
+       * lib/fseterr.c (fseterr): M.
+       * lib/fstatat.c (rpl_fstatat): M.
+       * lib/fstrcmp.c (fstrcmp_free_resources): M.
+       (fstrcmp_bounded): MR.
+       * lib/fsusage.c (statvfs_works): R.
+       * lib/fsync.c (fsync): M.
+       * lib/ftello.c (ftello): M.
+       * lib/ftruncate.c (SetFileSize): M.
+       * lib/fts.c (fts_open): MR.
+       (fts_load): M.
+       (fts_close): MR.
+       (filesystem_type): MRO.
+       (fts_read): MB.
+       (fts_children): M.
+       (fts_build): MR.
+       (fts_cross_check): RO.
+       (fd_ring_print): RO.
+       (fts_stat): RO.
+       (fts_sort): R.
+       (fts_alloc): M.
+       (fts_lfree): R.
+       (fts_palloc): M.
+       (fts_padjust): MS.
+       (fts_maxarglen): M.
+       (fts_safe_changedir): MR.
+       * lib/fts-cycle.c (enter_dir): MRO.
+       (leave_dir): M.
+       * lib/fzprintf.c (fzprintf): M.
+       * lib/gc-gnulib.c (gc_cipher_open): MR.
+       (gc_cipher_setkey): MSB.
+       (gc_cipher_setiv): M.
+       (gc_cipher_encrypt_inline): M.
+       (gc_cipher_decrypt_inline): M.
+       (gc_hash_open): MR.
+       (gc_hash_clone): M.
+       * lib/gc-libgcrypt.c (gc_init): Remove local variable 'err'.
+       (gc_cipher_open): MR.
+       (gc_cipher_setkey): M.
+       (gc_cipher_setiv): M.
+       (gc_hash_open): MR.
+       (gc_hash_clone): M.
+       (gc_md4): MR.
+       (gc_md5): MR.
+       (gc_sha1): MR.
+       (gc_sha256): MR.
+       (gc_sha512): MR.
+       (gc_sm3): MR.
+       (gc_hmac_md5): MR. Remove local variable 'err'.
+       (gc_hmac_sha1): MR. Remove local variable 'err'.
+       (gc_hmac_sha256): MR. Remove local variable 'err'.
+       (gc_hmac_sha512): MR. Remove local variable 'err'.
+       * lib/gc-pbkdf2.c (gc_pbkdf2_prf): MR.
+       * lib/gen-uni-tables.c (fill_attributes): M.
+       (debug_output_predicate): M.
+       (output_predicate_test): M.
+       (output_predicate): MR.
+       (output_category): MR.
+       (output_combclass): MR.
+       (output_bidi_category): MR.
+       (output_decimal_digit_test): M.
+       (output_decimal_digit): MR.
+       (output_digit_test): M.
+       (output_digit): MR.
+       (output_numeric_test): M.
+       (output_numeric): MR.
+       (fill_mirror): MR.
+       (get_mirror_value): M.
+       (output_mirror): MR.
+       (fill_properties): MR.
+       (fill_property30): MR.
+       (output_indic_conjunct_break_test): M.
+       (output_indic_conjunct_break): MR.
+       (fill_arabicshaping): MR.
+       (output_joining_type_test): M.
+       (output_joining_type): MR.
+       (output_joining_group_test): M.
+       (output_joining_group): MR.
+       (fill_scripts): MR.
+       (output_scripts): MR.
+       (output_scripts_byname): M.
+       (fill_blocks): MR.
+       (output_blocks): M.
+       (output_ident_category): MR.
+       (output_charclass): MR.
+       (output_charmap): MR.
+       (output_tables): M.
+       (fill_width): MR.
+       (output_nonspacing_property): MR.
+       (output_width_property_test): M.
+       (debug_output_lbrk_tables): M.
+       (fill_org_lbp): MR.
+       (debug_output_org_lbrk_tables): M.
+       (output_lbpea): M.
+       (output_lbrk_tables): R.
+       (output_lbrk_rules_as_tables): M.
+       (debug_output_wbrk_tables): M.
+       (fill_org_wbp): MR.
+       (debug_output_org_wbrk_tables): M.
+       (output_wbp): M.
+       (output_wbrk_tables): M.
+       (output_gbp_test): MR.
+       (output_gbp_table): MR.
+       (fill_org_gbp): MR.
+       (get_decomposition): MR.
+       (output_decomposition): M.
+       (output_decomposition_tables): R.
+       (fill_composition_exclusions): MR.
+       (debug_output_composition_tables): M.
+       (output_composition_tables): MSB.
+       (output_simple_mapping_test): M.
+       (output_simple_mapping): MR.
+       (fill_casing_rules): MR.
+       (fill_casefolding_rules): MR.
+       (output_casing_rules): M.
+       (output_version): MR.
+       * lib/get-rusage-as.c (get_rusage_as_via_setrlimit): R.
+       (get_rusage_as): M.
+       * lib/get-rusage-data.c (get_rusage_data_via_setrlimit): R.
+       (get_rusage_data): M.
+       * lib/get_ppid_of.c (get_ppid_of): M.
+       * lib/get_progname_of.c (get_progname_of): MR.
+       * lib/getaddrinfo.c (use_win32_p): M.
+       (getaddrinfo): MR.
+       (freeaddrinfo): M.
+       * lib/getcwd.c (__getcwd_generic): MRSBO.
+       * lib/getcwd-lgpl.c (rpl_getcwd): MS.
+       * lib/getdelim.c (getdelim): MR.
+       * lib/getdomainname.c (getdomainname): M.
+       * lib/getentropy.c (getentropy): R.
+       * lib/getgroups.c (rpl_getgroups): MR.
+       * lib/gethostname.c (rpl_gethostname): M.
+       * lib/getloadavg.c (getloadavg): MRB.
+       * lib/getlocalename_l-unsafe.c (newlocale): MR.
+       (duplocale): MR.
+       (freelocale): M.
+       * lib/getlogin_r.c (getlogin_r): M.
+       * lib/getndelim2.c (getndelim2): MR.
+       * lib/getopt.c (exchange): MS.
+       (process_long_option): MRB.
+       (_getopt_internal_r): MR.
+       (_getopt_internal): M.
+       (main): M.
+       * lib/getopt1.c (main): M.
+       * lib/getpass.c (getpass): MRB.
+       * lib/getprogname.c (getprogname): M.
+       * lib/getrusage.c (getrusage): M.
+       * lib/getsockopt.c (rpl_getsockopt): M.
+       * lib/getsubopt.c (getsubopt): M.
+       * lib/gettext.h (dcpgettext_expr): M.
+       (dcnpgettext_expr): M.
+       * lib/gettimeofday.c (gettimeofday): R.
+       * lib/getugroups.c (getugroups): MR.
+       * lib/getumask.c (getumask): R.
+       * lib/gl_anyavltree_list2.h (rebalance): MR.
+       (gl_tree_remove_node_from_tree): MR.
+       (gl_tree_nx_add_before): R.
+       (gl_tree_nx_add_after): R.
+       * lib/gl_anyhash2.h (hash_resize): M.
+       * lib/gl_anylinked_list2.h (gl_linked_get_at): R.
+       (gl_linked_nx_set_at): R.
+       (gl_linked_search_from_to): R.
+       (gl_linked_indexof_from_to): MR.
+       (gl_linked_nx_add_at): M.
+       (gl_linked_remove_node): M.
+       (gl_linked_remove_at): MR.
+       (gl_linked_iterator_from_to): M.
+       (gl_linked_sortedlist_search_from_to): R.
+       (gl_linked_sortedlist_indexof_from_to): R.
+       * lib/gl_anyrbtree_list2.h (rebalance_after_add): MR.
+       (gl_tree_remove_node_from_tree): M.
+       * lib/gl_anytree_list2.h (gl_tree_iterator): MB.
+       (gl_tree_sortedlist_indexof_from_to): R.
+       * lib/gl_anytree_omap.h (gl_tree_nx_getput): M.
+       (gl_tree_iterator): MB.
+       * lib/gl_anytree_oset.h (gl_tree_nx_add): M.
+       (gl_tree_update): M.
+       (gl_tree_iterator): MB.
+       * lib/gl_anytreehash_list1.h (add_to_bucket): M.
+       * lib/gl_array_list.c (grow): M.
+       (gl_array_nx_add_first): M.
+       (gl_array_nx_add_before): M.
+       (gl_array_nx_add_after): M.
+       (gl_array_nx_add_at): M.
+       (gl_array_remove_node): M.
+       (gl_array_remove_at): M.
+       * lib/gl_array_map.c (grow): M.
+       (gl_array_nx_getput): M.
+       (gl_array_remove_at): M.
+       * lib/gl_array_omap.c (grow): M.
+       (gl_array_nx_add_at): M.
+       (gl_array_remove_at): M.
+       * lib/gl_array_oset.c (grow): M.
+       (gl_array_nx_add_at): M.
+       (gl_array_remove_at): M.
+       * lib/gl_array_set.c (grow): M.
+       * lib/gl_avltree_ordered.h (rebalance): M.
+       (gl_tree_add_node_before): R.
+       (gl_tree_add_node_after): R.
+       (gl_tree_remove_node_no_free): M.
+       * lib/gl_carray_list.c (gl_carray_node_value): M.
+       (gl_carray_node_nx_set_value): M.
+       (gl_carray_get_at): M.
+       (gl_carray_nx_set_at): M.
+       (gl_carray_indexof_from_to): M.
+       (grow): M.
+       (gl_carray_nx_add_last): M.
+       (gl_carray_nx_add_at): M.
+       (gl_carray_remove_at): M.
+       (gl_carray_iterator_from_to): R.
+       (gl_carray_sortedlist_indexof_from_to): M.
+       (gl_carray_sortedlist_nx_add): M.
+       * lib/gl_rbtree_ordered.h (rebalance_after_add): M.
+       (gl_tree_remove_node_no_free): M.
+       * lib/gl_sublist.c (gl_sublist_sortedlist_search_from_to): M.
+       (gl_sublist_sortedlist_indexof_from_to): M.
+       * lib/glob.c (__glob): MR.
+       * lib/globfree.c (globfree): M.
+       * lib/glthread/lock.c (glthread_rwlock_init_for_glibc): M.
+       (glthread_rwlock_init_multithreaded): M.
+       (glthread_rwlock_rdlock_multithreaded): M.
+       (glthread_rwlock_wrlock_multithreaded): M.
+       (glthread_rwlock_destroy_multithreaded): M.
+       (glthread_rwlock_init_multithreaded): M.
+       (glthread_rwlock_rdlock_multithreaded): M.
+       (glthread_rwlock_wrlock_multithreaded): M.
+       (glthread_rwlock_unlock_multithreaded): M.
+       (glthread_rwlock_destroy_multithreaded): M.
+       (glthread_recursive_lock_init_multithreaded): M.
+       (glthread_recursive_lock_lock_multithreaded): M.
+       (glthread_recursive_lock_destroy_multithreaded): M.
+       (glthread_recursive_lock_init_multithreaded): M.
+       (glthread_recursive_lock_lock_multithreaded): M.
+       * lib/glthread/thread.c (gl_thread_create): M.
+       * lib/group-member.c (group_member): M.
+       (main): M.
+       * lib/hash.c (hash_get_next): MB.
+       (check_tuning): M.
+       (hash_initialize): M.
+       (hash_clear): M.
+       (hash_free): MS.
+       (transfer_entries): M.
+       (hash_rehash): MR.
+       (hash_insert_if_absent): MR.
+       (hash_remove): MR.
+       (hash_print): M.
+       * lib/hasmntopt.c (hasmntopt): M.
+       * lib/hmac.c (hmac_hash): R.
+       (GL_HMAC_FN): R.
+       * lib/human.c (group_number): MRO.
+       (human_readable): MR.
+       (humblock): M.
+       * lib/hypot.c (hypot): M.
+       * lib/hypotl.c (hypotl): M.
+       * lib/i-ring.c (i_ring_pop): M.
+       * lib/iconv_open.c (rpl_iconv_open): R.
+       * lib/idcache.c (getuidbyname): M.
+       (getgidbyname): M.
+       * lib/inet_ntop.c (inet_ntop4): M.
+       (inet_ntop6): R.
+       * lib/inet_pton.c (inet_pton4): MRBO.
+       (inet_pton6): MRBO.
+       * lib/ino-map.c (ino_map_insert): M.
+       * lib/integer_length.c (integer_length): M.
+       * lib/ioctl.c (rpl_ioctl): M.
+       (ioctl): M.
+       * lib/is_l-impl.h (FUNC): M.
+       * lib/isatty.c (IsCygwinConsoleHandle): R.
+       * lib/isnan.c (FUNC): MR.
+       * lib/javacomp.c (compile_using_envjavac): MRB.
+       (compile_using_javac): MB.
+       (execute_and_read_line): M.
+       (write_temp_file): M.
+       (get_classfile_version): MR.
+       (is_envjavac_usable): MR.
+       (is_javac_present): M.
+       (is_javac_usable): MR.
+       (compile_java_class): MR.
+       * lib/javaexec.c (execute_java_class): MRBO.
+       * lib/javaversion.c (execute_and_read_line): M.
+       (javaexec_version): R.
+       * lib/kwset.c (treefails): M.
+       (kwsprep): MRSB.
+       (bmexec_trans): MRSO.
+       (acexec_trans): MRS.
+       * lib/lchown.c (rpl_lchown): R.
+       * lib/linebuffer.c (readlinebuffer_delim): RO.
+       * lib/link.c (link): MRBO.
+       (rpl_link): M.
+       * lib/linkat.c (link_immediate): R.
+       (link_follow): M.
+       (linkat_follow): M.
+       * lib/localcharset.c (locale_charset): MR.
+       * lib/localeinfo.c (is_using_utf8): R. Rename 'mbs' to 'state'.
+       (init_localeinfo): Rename 's' to 'state'.
+       * lib/localename.c (gl_locale_name): MSB.
+       * lib/localename-environ.c (gl_locale_name_environ): MSB.
+       * lib/localename-unsafe.c (gl_locale_name_canonicalize): MSB.
+       (gl_locale_name_from_win32_LANGID): M.
+       (gl_locale_name_from_win32_LCID): M.
+       (enum_locales_fn): R.
+       (gl_locale_name_unsafe): MSB.
+       * lib/log2.c (log2): M.
+       * lib/log2f.c (log2f): M.
+       * lib/log2l.c (log2l): M.
+       * lib/login_tty.c (login_tty): M.
+       * lib/logl.c (logl): MR.
+       * lib/long-options.c (parse_long_options): MR.
+       (parse_gnu_standard_options_only): M.
+       * lib/mbfile.h (mbfile_multi_getc): MR.
+       * lib/mbmemcasecoll.c (apply_c32tolower): M.
+       (mbmemcasecoll): MR.
+       * lib/mbrtoc32.c (mbrtoc32): R.
+       * lib/mbrtowc.c (rpl_mbrtowc): MRS.
+       * lib/mbrtowc-impl.h: MRB.
+       * lib/mbscasestr.c (knuth_morris_pratt_multibyte): MR.
+       (mbscasestr): R.
+       * lib/mbscspn.c (mbscspn): MR.
+       * lib/mbsnrtowcs-impl.h (FUNC): M.
+       * lib/mbspbrk.c (mbspbrk): MR.
+       * lib/mbsrtowcs-impl.h (FUNC): M.
+       * lib/mbsspn.c (mbsspn): MR.
+       * lib/mbsstr.c (knuth_morris_pratt_multibyte): MR.
+       (mbsstr): MR.
+       * lib/mbswidth.c (mbsnwidth): M.
+       * lib/mbtowc-impl.h (mbtowc): MR.
+       * lib/mbtowc-lock.h (mbtowc_with_lock): M.
+       * lib/mcel.h: MR in comments.
+       * lib/md2.c (md2_finish_ctx): M.
+       (md2_process_bytes): M.
+       (md2_update_chksum): M.
+       (md2_compress): M.
+       * lib/md2-stream.c (md2_stream): MR.
+       * lib/md4.c (md4_finish_ctx): M.
+       (md4_process_block): MR.
+       * lib/md4-stream.c (md4_stream): MR.
+       * lib/md5-stream.c (md5_stream): MR.
+       * lib/mem-hash-map.c (compute_hashval): M.
+       (lookup): M.
+       * lib/memchr.c (__memchr): MRB.
+       * lib/memchr2.c (memchr2): MRB.
+       * lib/memrchr.c (__memrchr): MRB.
+       * lib/mgetgroups.c (mgetgroups): MRS.
+       * lib/mkancesdirs.c (mkancesdirs): M.
+       * lib/mkdir.c (rpl_mkdir): MR.
+       * lib/mkdir-p.c (make_dir_parents): R.
+       * lib/modechange.c (mode_compile): R.
+       * lib/mountlist.c (fstype_to_string): M.
+       (dev_from_mount_options): MR.
+       (read_file_system_list): MR.
+       * lib/mpsort.c (mpsort_into_tmp): M.
+       (mpsort_with_tmp): M.
+       * lib/msvc-inval.h (TRY_MSVC_INVAL): M.
+       * lib/mtx.c (mtx_init): MSB.
+       * lib/nanosleep.c (nanosleep): M.
+       * lib/nl_langinfo.c (ctype_codeset): MR.
+       (nl_langinfo_with_lock): M.
+       * lib/nonblocking.c (get_nonblocking_flag): M.
+       (set_nonblocking_flag): M.
+       * lib/nproc.c (num_processors_via_affinity_mask): M.
+       (cgroup2_mount): MR.
+       (get_cgroup2_cpu_quota): M.
+       (parse_omp_threads): Remove variable 'ret'.
+       (num_processors): M.
+       * lib/obstack.c (_obstack_newchunk): M.
+       (_obstack_allocated_p): M.
+       (__obstack_free): M.
+       * lib/obstack_printf.c (OBSTACK_PRINTF): M.
+       (OBSTACK_VPRINTF): M.
+       * lib/omp-init.c (parse_omp_threads): Remove variable 'ret'.
+       * lib/openat-proc.c (openat_proc_name): R.
+       * lib/openat2.c (do_openat2): R.
+       (openat2): MSB.
+       * lib/opendir.c (opendir): MR.
+       * lib/openpty.c (openpty): M.
+       * lib/os2-spawn.c (prepare_spawn): M.
+       (spawnpvech): R.
+       * lib/pagealign_alloc.c (pagealign_alloc): MR.
+       (pagealign_xalloc): M.
+       (pagealign_free): M.
+       * lib/parse-duration.c (parse_scaled_value): M.
+       (parse_year_month_day): M.
+       (parse_yearmonthday): MR.
+       (parse_YMWD): SB.
+       (parse_hour_minute_second): M.
+       (parse_hourminutesecond): MR.
+       (parse_HMS): SB.
+       (parse_time): M.
+       (parse_period): MR.
+       (parse_non_iso8601): M.
+       * lib/passfd.c (sendfd): MRO.
+       (recvfd): MRO.
+       * lib/perror.c (perror): M.
+       * lib/physmem.c (physmem_total): M.
+       (physmem_claimable): M.
+       * lib/pipe-filter-gi.c (filter_loop): MRB.
+       (pipe_filter_gi_create): M.
+       (pipe_filter_gi_close): M.
+       * lib/pipe-filter-ii.c (_beginthreadex): M.
+       (WaitForMultipleObjects): MR.
+       (pipe_filter_ii_execute): MRB.
+       * lib/poll.c (IsSocketHandle): R.
+       (windows_compute_revents): MRB.
+       (windows_compute_revents_socket): M.
+       (poll): MRB. Remove variable 'bRet'.
+       * lib/popen.c (rpl_popen): MB.
+       * lib/posix_openpt.c (posix_openpt): M.
+       * lib/posixtm.c (posix_time_parse): R.
+       (posixtime): R.
+       * lib/pread.c (pread): M.
+       * lib/printf.c (printf): M.
+       * lib/printf-frexp.c (FUNC): R.
+       * lib/printf-parse.c (PRINTF_PARSE): MR.
+       * lib/progreloc.c (maybe_executable): R.
+       (find_executable): MRSB.
+       (prepare_relocate): M.
+       * lib/propername.c (mbsstr_trimmed_wordbounded): RSB.
+       (proper_name_utf8): M.
+       * lib/pselect.c (pselect): MR.
+       * lib/pt_chown.c (do_pt_chown): MR.
+       * lib/pthread-cond.c (pthread_cond_timedwait): R.
+       * lib/pthread-rwlock.c (pthread_rwlockattr_init): MSB.
+       (pthread_rwlock_init): MSB.
+       (pthread_rwlock_rdlock): MSB.
+       (pthread_rwlock_wrlock): MSB.
+       (pthread_rwlock_tryrdlock): MB.
+       (pthread_rwlock_trywrlock): MB.
+       (pthread_rwlock_timedrdlock): MSB.
+       (pthread_rwlock_timedwrlock): MSB.
+       (pthread_rwlock_unlock): MSB.
+       (pthread_rwlock_destroy): MSB.
+       (pthread_rwlock_init): MSB.
+       (pthread_rwlock_timedrdlock): MRB.
+       (pthread_rwlock_timedwrlock): MRB.
+       * lib/pthread_mutex_timedlock.c (pthread_mutex_timedlock): MRB.
+       * lib/pthread_sigmask.c (pthread_sigmask): MR.
+       * lib/ptsname_r.c (ptsname_r): MR.
+       * lib/putenv.c (putenv): M.
+       * lib/pwrite.c (pwrite): M.
+       * lib/qcopy-acl.c (qcopy_acl): Remove a use of variable 'ret'.
+       * lib/qset-acl.c (qset_acl): M.
+       * lib/qsort.c (_quicksort): MR.
+       * lib/quotearg.c (set_quoting_flags): M.
+       (quotearg_buffer_restyled): MRSB.
+       * lib/random.c (__initstate): M.
+       (__setstate): M.
+       (__random): R.
+       * lib/random_r.c (__srandom_r): M.
+       (__setstate_r): MO.
+       (__random_r): M.
+       * lib/rawmemchr.c (rawmemchr): RB.
+       * lib/read-file.c (fread_file): M.
+       (read_file): M.
+       * lib/readdir.c (readdir): MR.
+       * lib/readline.c (readline): R.
+       * lib/readtokens.c (readtoken): R.
+       (readtokens): M.
+       * lib/regex-quote.c (regex_quote_spec_gnu): MB.
+       (regex_quote_spec_pcre): MB.
+       (regex_quote_length): MR.
+       (regex_quote): MB.
+       * lib/relocatable.c (set_this_relocation_prefix): M.
+       (compute_curr_prefix): MR.
+       (find_shared_library_fullname): MRS.
+       (relocate): M.
+       * lib/relocwrapper.c (activate_libdirs): MB.
+       (main): M.
+       * lib/rename.c (rpl_rename): MRBO.
+       * lib/renameatu.c (renameatu): MRB.
+       * lib/rijndael-alg-fst.c (rijndaelKeySetupEnc): MSB.
+       (rijndaelKeySetupDec): MRSB.
+       (rijndaelEncrypt): MSB.
+       (rijndaelDecrypt): MSB.
+       * lib/rijndael-api-fst.c (rijndaelMakeKey): MRSB.
+       (rijndaelCipherInit): MSB.
+       (rijndaelBlockEncrypt): MRSB.
+       (rijndaelPadEncrypt): MRSB.
+       (rijndaelBlockDecrypt): MRSB.
+       (rijndaelPadDecrypt): MRSB.
+       * lib/rmdir.c (rpl_rmdir): M.
+       * lib/rpmatch.c (localized_pattern): MS.
+       (try): M.
+       (rpmatch): MSB.
+       * lib/same.c (same_nameat): R. Remove variable 'flags'.
+       * lib/savedir.c (streamsavedir): MRB.
+       * lib/scandir.c (SCANDIR): MR.
+       * lib/select.c (IsSocketHandle): R.
+       (windows_poll_handle): MRSB. Remove variable 'bRet'.
+       (rpl_select): MR. Remove variable 'bRet'.
+       * lib/set-permissions.c (set_acls_from_mode): R.
+       (context_acl_from_mode): R.
+       (context_aclv_from_mode): M.
+       (set_acls_from_mode): MR.
+       (context_acl_from_mode): M.
+       (set_acls): R.
+       (set_permissions): MS.
+       * lib/setenv.c (__add_to_environ): M.
+       (rpl_setenv): M.
+       * lib/sethostname.c (sethostname): MR.
+       * lib/setlocale.c (setlocale_unixlike): MR.
+       (langcmp): R.
+       (setlocale_improved): MR.
+       * lib/setlocale_null.c (setlocale_null_r_with_lock): M.
+       (setlocale_null): M.
+       * lib/setsockopt.c (rpl_setsockopt): R.
+       * lib/sh-quote.c (shell_quote_argv): MB.
+       * lib/sha1.c (sha1_process_block): R.
+       * lib/sha1-stream.c (sha1_stream): M.
+       * lib/sha256.c (sha256_process_block): MR.
+       * lib/sha256-stream.c (shaxxx_stream): M.
+       * lib/sha3.c (sha3_read_ctx): R.
+       (sha3_process_block): R.
+       * lib/sha3-stream.c (sha3_xxx_stream): M.
+       * lib/sha512-stream.c (shaxxx_stream): M.
+       * lib/sig2str.c (str2signum): RS.
+       (sig2str): MR.
+       * lib/sigaction.c (sigaction_handler): MR.
+       (sigaction): MRB.
+       * lib/sigprocmask.c (sigprocmask): M.
+       * lib/sigsegv.c (sigsegv_handler): MR.
+       * lib/sincosl.c (kernel_sinl): MRS.
+       (kernel_cosl): MRS.
+       * lib/sinl.c (sinl): MR.
+       * lib/sleep.c (rpl_sleep): M.
+       * lib/sm3.c (sm3_process_block): MR.
+       * lib/sm3-stream.c (sm3_stream): MR.
+       * lib/snprintf.c (snprintf): M.
+       * lib/snzprintf.c (snzprintf): M.
+       * lib/socket.c (rpl_socket): M.
+       * lib/sockets.c (close_fd_maybe_socket): MR.
+       (ioctl_fd_maybe_socket): MR.
+       (gl_sockets_startup): M.
+       (gl_sockets_cleanup): M.
+       * lib/spawn-pipe.c (create_pipe): MR.
+       * lib/spawni.c (__spawni): Split variable declaration.
+       * lib/sprintf.c (sprintf): M.
+       * lib/sqrtl.c (sqrtl): MR.
+       * lib/ssfmalloc.h (allocate_block_from_pool): MSB.
+       * lib/stackvma.c (rof_open): M.
+       (vma_iterate_proc): RSB.
+       (vma_iterate_bsd): MB.
+       (mapped_range_start): M.
+       (mapped_range_end): M.
+       (is_unmapped): MR.
+       (mapped_range_start): M.
+       (mapped_range_end): M.
+       (vma_iterate): MR.
+       * lib/stat-w32.c (_gl_convert_FILETIME_to_timespec): R.
+       * lib/stdio-consolesafe.c (gl_consolesafe_fprintf): R.
+       (gl_consolesafe_printf): R.
+       * lib/stdio-read.c (CALL_WITH_ERRNO_FIX): M.
+       (scanf): M.
+       (fscanf): M.
+       * lib/stdio-write.c (CALL_WITH_SIGPIPE_EMULATION): M.
+       (printf): M.
+       (fprintf): M.
+       * lib/stpncpy.c (__stpncpy): MSB.
+       * lib/str-kmp.h (knuth_morris_pratt): M.
+       * lib/str-two-way.h (critical_factorization): MSB.
+       (two_way_short_needle): MS.
+       (two_way_long_needle): MRS.
+       * lib/strcasecmp.c (strcasecmp): R.
+       * lib/strcasecmp_l.c (strcasecmp_l): MR.
+       * lib/strcasestr.c (strcasestr): MRSB.
+       * lib/strchrnul.c (strchrnul): MRB.
+       * lib/strerror.c (strerror): M.
+       * lib/strerror_l.c (strerror_l_r): R.
+       * lib/strerror_r.c (local_snprintf): M.
+       (strerror_r): M.
+       * lib/strfmon_l.c (rpl_strfmon_l): MR.
+       * lib/strftime.c (__strftime_internal): MR.
+       * lib/striconv.c (mem_cd_iconv): MR.
+       (str_cd_iconv): MR.
+       (str_iconv): M.
+       * lib/striconveh.c (iconveh_open): MR.
+       (utf8conv_carefully): M.
+       (mem_cd_iconveh_internal): MR.
+       (mem_iconveh): M.
+       (str_iconveh): M.
+       * lib/striconveha.c (uniconv_register_autodetect): MRSB.
+       (mem_iconveha_notranslit): MS.
+       (mem_iconveha): M.
+       (str_iconveha_notranslit): MS.
+       (str_iconveha): M.
+       * lib/string-buffer-printf.c (sb_appendvf): R.
+       (sb_appendf): R.
+       * lib/string-buffer-reversed-printf.c (sbr_prependvf): R.
+       (sbr_prependf): R.
+       * lib/string-desc.c (sd_new): R.
+       * lib/stripslash.c (strip_trailing_slashes): M.
+       * lib/strncasecmp.c (strncasecmp): R.
+       * lib/strncasecmp_l.c (strncasecmp_l): MR.
+       * lib/strptime.c (__strptime_internal): RSB.
+       * lib/strsep.c (strsep): R.
+       * lib/strsignal.c (strsignal): R.
+       * lib/strstr.c (strstr): MRSB.
+       * lib/strtod.c (parse_number): MR.
+       (STRTOD): MR.
+       * lib/strtok_r.c (__strtok_r): M.
+       * lib/strtol.c (strtol): MR.
+       * lib/struniq.h (struniq): M.
+       * lib/supersede.c (open_supersede): R.
+       * lib/system-quote.c (system_quote_argv): MB.
+       * lib/szprintf.c (szprintf): M.
+       * lib/tanl.c (kernel_tanl): MRS.
+       (tanl): MR.
+       * lib/tempname.c (try_tempname_len): M.
+       * lib/term-style-control.c (sprintf_integer): MR.
+       * lib/textstyle.in.h (ostream_printf): MR.
+       * lib/time.c (time): M.
+       * lib/times.c (filetime2clock): M.
+       * lib/timespec-add.c (timespec_add): R.
+       * lib/timespec-sub.c (timespec_sub): R.
+       * lib/tmpdir.c (path_search): MR.
+       * lib/tmpfile.c (tmpfile): M.
+       * lib/to_l-impl.h (FUNC): M.
+       * lib/tparm.c (tparm): MRB.
+       * lib/trigl.c (ieee754_rem_pio2l): MRS.
+       (kernel_rem_pio2): MRS.
+       * lib/trim.c (trim2): MR.
+       * lib/tsearch.c (check_tree): R.
+       (maybe_split_for_insert): M.
+       (__tsearch): MR.
+       (__tfind): M.
+       (__tdelete): MRB.
+       * lib/ttyname_r.c (ttyname_r): M.
+       * lib/uname.c (uname): MR.
+       * lib/unicase/locale-language.c (uc_locale_language): M.
+       * lib/unicase/u-casecmp.h (FUNC): MR.
+       * lib/unicase/u-casecoll.h (FUNC): MR.
+       * lib/unicase/u-casemap.h (FUNC): MR.
+       * lib/unicase/u-casexfrm.h (FUNC): MR.
+       * lib/unicase/u-ct-casefold.h (FUNC): MR.
+       * lib/unicase/u-ct-totitle.h (FUNC): MR.
+       * lib/unicase/u-is-cased.h (FUNC): MR.
+       * lib/unicase/u-is-invariant.h (FUNC): MR.
+       * lib/unicase/u8-casefold.c (read_file): M.
+       * lib/unicase/u8-tolower.c (read_file): M.
+       * lib/unicase/u8-totitle.c (read_file): M.
+       * lib/unicase/u8-toupper.c (read_file): M.
+       * lib/unicase/ulc-casecmp.c (ulc_u8_casefold): MR.
+       * lib/unicase/ulc-casexfrm.c (ulc_casexfrm): MR.
+       * lib/unicodeio.c (unicode_to_mb): MR.
+       * lib/uniconv/u-conv-from-enc.h (FUNC): M.
+       * lib/uniconv/u-conv-to-enc.h (FUNC): MR.
+       * lib/uniconv/u-strconv-from-enc.h (FUNC): M.
+       * lib/uniconv/u-strconv-to-enc.h (FUNC): M.
+       * lib/uniconv/u16-conv-to-enc.c (FUNC): MR.
+       * lib/uniconv/u8-conv-from-enc.c (u8_conv_from_encoding): R.
+       * lib/uniconv/u8-conv-to-enc.c (u8_conv_to_encoding): R.
+       * lib/uniconv/u8-strconv-to-enc.c (u8_strconv_to_encoding): MS.
+       * lib/unictype/3level.h (CONCAT(TABLE,_add)): M.
+       (CONCAT(TABLE,_finalize)): MRB.
+       * lib/unictype/3levelbit.h (CONCAT(TABLE,_add)): M.
+       (CONCAT(TABLE,_finalize)): MRB.
+       * lib/unictype/bidi_byname.c (uc_bidi_class_byname): M.
+       * lib/unictype/categ_and.c (uc_general_category_and): MR.
+       * lib/unictype/categ_and_not.c (uc_general_category_and_not): MR.
+       * lib/unictype/categ_byname.c (uc_general_category_byname): M.
+       * lib/unictype/categ_of.c (uc_general_category): R.
+       * lib/unictype/categ_or.c (uc_general_category_or): MR.
+       * lib/unictype/combiningclass_byname.c (uc_combining_class_byname): M.
+       * lib/unictype/incb_byname.c (uc_indic_conjunct_break_byname): M.
+       * lib/unictype/joininggroup_byname.c (uc_joining_group_byname): M.
+       * lib/unictype/joiningtype_byname.c (uc_joining_type_byname): M.
+       * lib/unictype/pr_byname.c (uc_property_byname): MRB.
+       * lib/unictype/scripts.c (uc_script_byname): M.
+       * lib/unigbrk/u-grapheme-prev.h
+       (ends_with_incb_consonant_extended_linker_extended): M.
+       (ends_with_emoji_modifier_sequence): M.
+       (ends_with_ri_count): M.
+       (FUNC): M.
+       * lib/unigbrk/uc-is-grapheme-break.c (uc_is_grapheme_break): M.
+       * lib/unigbrk/ulc-grapheme-breaks.c (ulc_grapheme_breaks): M.
+       * lib/unilbrk/u16-width-linebreaks.c (u16_width_linebreaks_internal): M.
+       * lib/unilbrk/u32-width-linebreaks.c (u32_width_linebreaks_internal): M.
+       * lib/unilbrk/u8-possible-linebreaks.c (read_file): M.
+       * lib/unilbrk/u8-width-linebreaks.c (u8_width_linebreaks_internal): M.
+       (read_file): M.
+       * lib/unilbrk/ulc-possible-linebreaks.c
+       (ulc_possible_linebreaks_internal): M.
+       (read_file): M.
+       * lib/unilbrk/ulc-width-linebreaks.c (ulc_width_linebreaks_internal): M.
+       (read_file): M.
+       * lib/uniname/uniname.c (unicode_name_word): MR.
+       (unicode_character_name): M.
+       (unicode_name_character): MR.
+       * lib/uninorm/canonical-decomposition.c (uc_canonical_decomposition): M.
+       * lib/uninorm/composition.c (uc_composition): M.
+       * lib/uninorm/decomposition.c (uc_decomposition): M.
+       * lib/uninorm/u-normalize-internal.h (FUNC): MR.
+       * lib/uninorm/u-normcmp.h (FUNC): MR.
+       * lib/uninorm/u-normcoll.h (FUNC): MR.
+       * lib/uninorm/u-normxfrm.h (FUNC): MR.
+       * lib/uninorm/uninorm-filter.c (uninorm_filter_write): M.
+       * lib/unistdio/u-asnprintf.h (ASNPRINTF): M.
+       * lib/unistdio/u-asprintf.h (ASPRINTF): M.
+       * lib/unistdio/u-snprintf.h (SNPRINTF): M.
+       * lib/unistdio/u-sprintf.h (SPRINTF): M.
+       * lib/unistdio/u-vsnprintf.h (VSNPRINTF): M.
+       * lib/unistdio/u-vsprintf.h (VSPRINTF): M.
+       * lib/unistdio/ulc-fprintf.c (ulc_fprintf): M.
+       * lib/unistdio/ulc-vfprintf.c (ulc_vfprintf): M.
+       * lib/unistr/u16-chr.c (u16_chr): R.
+       * lib/unistr/u16-mbsnlen.c (u16_mbsnlen): M.
+       * lib/unistr/u16-next.c (u16_next): M.
+       * lib/unistr/u16-strchr.c (u16_strchr): R.
+       * lib/unistr/u16-strrchr.c (u16_strrchr): R.
+       * lib/unistr/u16-to-u32.c (FUNC): MR.
+       * lib/unistr/u16-to-u8.c (FUNC): MR.
+       * lib/unistr/u32-next.c (u32_next): M.
+       * lib/unistr/u32-to-u16.c (FUNC): MR.
+       * lib/unistr/u32-to-u8.c (FUNC): MR.
+       * lib/unistr/u8-chr.c (u8_chr): M.
+       * lib/unistr/u8-mbsnlen.c (u8_mbsnlen): M.
+       * lib/unistr/u8-next.c (u8_next): M.
+       * lib/unistr/u8-strchr.c (u8_strchr): R.
+       * lib/unistr/u8-strrchr.c (u8_strrchr): R.
+       * lib/unistr/u8-to-u16.c (FUNC): MR.
+       * lib/unistr/u8-to-u32.c (FUNC): MR.
+       * lib/uniwbrk/u8-wordbreaks.c (read_file): M.
+       * lib/uniwbrk/ulc-wordbreaks.c (ulc_wordbreaks): M.
+       (read_file): M.
+       * lib/uniwidth/u16-width.c (u16_width): M.
+       * lib/uniwidth/u32-width.c (u32_width): M.
+       * lib/uniwidth/u8-width.c (u8_width): M.
+       * lib/unlinkat.c (rpl_unlinkat): MR.
+       * lib/unsetenv.c (unsetenv): M.
+       (rpl_unsetenv): R.
+       * lib/userspec.c (parse_with_separator): MRS.
+       (main): MR.
+       * lib/utime.c (_gl_utimens_windows): M.
+       * lib/utimecmp.c (utimecmpat): R.
+       * lib/utimens.c (validate_timespec): R.
+       (fdutimens): MR.
+       (lutimens): MR.
+       * lib/utimensat.c (rpl_utimensat): M.
+       * lib/vasnprintf.c (divide): M.
+       (decode_long_double): MR.
+       (decode_double): MR.
+       (scale10_round_decimal_decoded): MR.
+       (floorlog10l): MR.
+       (floorlog10): MR.
+       (VASNPRINTF): MR.
+       * lib/vc-mtime.c (is_git_present): MR.
+       (git_vc_controlled): MR.
+       (git_unmodified): M.
+       (git_mtime): MR.
+       (abs_git_checkout): MR.
+       (max_vc_mtime): MR.
+       * lib/vdzprintf.c (vdzprintf): M.
+       * lib/vfzprintf.c (vfzprintf): M.
+       * lib/vma-iter.c (rof_open): M.
+       (vma_iterate_proc): MRSB.
+       (vma_iterate_bsd): MB.
+       (vma_iterate): MR.
+       * lib/vsnzprintf.c (vsnzprintf): M.
+       * lib/vszprintf.c (vszprintf): M.
+       * lib/wait-process.c (klibc_waitpid): M.
+       (wait_subprocess): MR.
+       * lib/wcs-two-way.h (critical_factorization): MSB.
+       (two_way_short_needle): MS.
+       * lib/wcsstr-impl.h (FUNC): MRSB.
+       * lib/wcswidth-impl.h (FUNC): B.
+       * lib/wcsxfrm-impl.h (wcsxfrm): MR.
+       * lib/wctomb-impl.h (wctomb): M.
+       * lib/wgetcwd-lgpl.c (wgetcwd): MRS.
+       * lib/windows-cond.c (glwthread_waitqueue_add): M.
+       (glwthread_waitqueue_notify_first): M.
+       (glwthread_waitqueue_notify_all): M.
+       (glwthread_cond_wait): M.
+       (glwthread_cond_timedwait): MRS.
+       * lib/windows-cygpath.c (execute_and_read_line): MR.
+       * lib/windows-rwlock.c (glwthread_waitqueue_add): M.
+       (glwthread_rwlock_rdlock): M.
+       (glwthread_rwlock_wrlock): M.
+       * lib/windows-spawn.c (quoted_arg_length): M.
+       (quoted_arg_string): M.
+       (prepare_spawn): MR.
+       (compose_command): MRB.
+       (compose_envblock): RSB.
+       * lib/windows-thread.c (glwthread_thread_self): M.
+       (glwthread_thread_create): M.
+       * lib/windows-timedmutex.c (glwthread_timedmutex_timedlock): MR.
+       * lib/windows-timedrecmutex.c (glwthread_timedrecmutex_timedlock): MR.
+       * lib/windows-timedrwlock.c (glwthread_waitqueue_add): M.
+       (glwthread_waitqueue_notify_first): M.
+       (glwthread_waitqueue_notify_all): M.
+       (glwthread_timedrwlock_rdlock): M.
+       (glwthread_timedrwlock_wrlock): M.
+       (glwthread_timedrwlock_timedrdlock): MR.
+       (glwthread_timedrwlock_timedwrlock): MR.
+       * lib/xasprintf.c (xasprintf): M.
+       * lib/xconcat-filename.c (xconcatenated_filename): M.
+       * lib/xmalloc.c (xpalloc): R.
+       * lib/xmalloca.c (xmmalloca): M.
+       * lib/xprintf.c (xprintf): M.
+       (xfprintf): M.
+       * lib/xstring-buffer-printf.c (sb_xappendf): M.
+       * lib/xstring-buffer-reversed-printf.c (sbr_xprependf): M.
+       * lib/xstrtod.c (XSTRTOD): MR.
+       * lib/xstrtol.c (__xstrtol): R.
+       * lib/xstrtol-error.c (xstrtol_error): R.
+       * lib/xvasprintf.c (xstrcat): MB.
+       (xvasprintf): R.
+       * lib/zprintf.c (zprintf): M.
+
 2025-12-09  Bruno Haible  <bruno@clisp.org>
 
        Remove unnecessary variable initializations.
index d44bcb4c4333a09e62ade2f67807a87f972afaf0..16e34617cc8a50fbd7b9989788dea5603047c925 100644 (file)
@@ -38,8 +38,6 @@
 int
 accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)
 {
-  int fd;
-
 #if HAVE_DECL_ACCEPT4
 # undef accept4
   /* Try the system call first, if it exists.  (We may be running with a glibc
@@ -67,7 +65,7 @@ accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)
       return -1;
     }
 
-  fd = accept (sockfd, addr, addrlen);
+  int fd = accept (sockfd, addr, addrlen);
   if (fd < 0)
     return -1;
 
@@ -78,9 +76,8 @@ accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)
     {
       HANDLE curr_process = GetCurrentProcess ();
       HANDLE old_handle = (HANDLE) _get_osfhandle (fd);
-      HANDLE new_handle;
-      int nfd;
 
+      HANDLE new_handle;
       if (!DuplicateHandle (curr_process,           /* SourceProcessHandle */
                             old_handle,             /* SourceHandle */
                             curr_process,           /* TargetProcessHandle */
@@ -97,8 +94,8 @@ accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)
       /* Closing fd before allocating the new fd ensures that the new fd will
          have the minimum possible value.  */
       close (fd);
-      nfd = _open_osfhandle ((intptr_t) new_handle,
-                             O_NOINHERIT | (flags & (O_TEXT | O_BINARY)));
+      int nfd = _open_osfhandle ((intptr_t) new_handle,
+                                 O_NOINHERIT | (flags & (O_TEXT | O_BINARY)));
       if (nfd < 0)
         {
           CloseHandle (new_handle);
index 7d7cbb798187edd357fb3923a4aa4f2bc76a7b16..8c173bf4f1af964db453e01bb4ebb8ebf60701b4 100644 (file)
@@ -237,9 +237,8 @@ acl_ace_nontrivial (int count, ace_t *entries)
       for (int i = 0; i < count; i++)
         {
           ace_t *ace = &entries[i];
-          unsigned int index1;
-          unsigned int index2;
 
+          unsigned int index1;
           if (ace->a_type == NEW_ACE_ACCESS_ALLOWED_ACE_TYPE)
             index1 = 1;
           else if (ace->a_type == NEW_ACE_ACCESS_DENIED_ACE_TYPE)
@@ -247,6 +246,7 @@ acl_ace_nontrivial (int count, ace_t *entries)
           else
             return 1;
 
+          unsigned int index2;
           if (ace->a_flags == NEW_ACE_OWNER)
             index2 = 0;
           else if (ace->a_flags == (NEW_ACE_GROUP | NEW_ACE_IDENTIFIER_GROUP))
index 59b65d6efa974d531522cd7d93c034de6b5f1ee8..379b262c7d29faff01722d93ec9952d53db22fa5 100644 (file)
@@ -134,7 +134,7 @@ static const long double
 long double
 acosl (long double x)
 {
-  long double t, p, q;
+  long double t;
 
   if (x < 0.0L)
     {
@@ -151,34 +151,34 @@ acosl (long double x)
       return (x - x) / (x - x); /* asin(|x|>1) is NaN */
     }
 
-  else if (x < 0.5L) /* |x| < 0.5 */
+  if (x < 0.5L) /* |x| < 0.5 */
     {
       if (x < 0.000000000000000006938893903907228377647697925567626953125L) /* |x| < 2**-57 */
         /* acos(0)=+-pi/2 with inexact */
         return x * pio2_hi + x * pio2_lo;
 
       t = x * x;
-      p = (((((((((pS9 * t
-                   + pS8) * t
-                  + pS7) * t
-                 + pS6) * t
-                + pS5) * t
-               + pS4) * t
-              + pS3) * t
-             + pS2) * t
-            + pS1) * t
-           + pS0) * t;
-
-      q = (((((((( t
-                  + qS8) * t
-                 + qS7) * t
-                + qS6) * t
-               + qS5) * t
-              + qS4) * t
-             + qS3) * t
-            + qS2) * t
-           + qS1) * t
-        + qS0;
+      long double p = (((((((((pS9 * t
+                               + pS8) * t
+                              + pS7) * t
+                             + pS6) * t
+                            + pS5) * t
+                           + pS4) * t
+                          + pS3) * t
+                         + pS2) * t
+                        + pS1) * t
+                       + pS0) * t;
+
+      long double q = (((((((( t
+                              + qS8) * t
+                             + qS7) * t
+                            + qS6) * t
+                           + qS5) * t
+                          + qS4) * t
+                         + qS3) * t
+                        + qS2) * t
+                       + qS1) * t
+                    + qS0;
 
       return pio2_hi - (x + x * (p / q) - pio2_lo);
     }
@@ -186,29 +186,29 @@ acosl (long double x)
   else if (x < 0.625) /* 0.625 */
     {
       t = x - 0.5625;
-      p = ((((((((((rS10 * t
-                    + rS9) * t
-                   + rS8) * t
-                  + rS7) * t
-                 + rS6) * t
-                + rS5) * t
-               + rS4) * t
-              + rS3) * t
-             + rS2) * t
-            + rS1) * t
-           + rS0) * t;
-
-      q = ((((((((( t
-                    + sS9) * t
-                  + sS8) * t
-                 + sS7) * t
-                + sS6) * t
-               + sS5) * t
-              + sS4) * t
-             + sS3) * t
-            + sS2) * t
-           + sS1) * t
-        + sS0;
+      long double p = ((((((((((rS10 * t
+                                + rS9) * t
+                               + rS8) * t
+                              + rS7) * t
+                             + rS6) * t
+                            + rS5) * t
+                           + rS4) * t
+                          + rS3) * t
+                         + rS2) * t
+                        + rS1) * t
+                       + rS0) * t;
+
+      long double q = ((((((((( t
+                                + sS9) * t
+                              + sS8) * t
+                             + sS7) * t
+                            + sS6) * t
+                           + sS5) * t
+                          + sS4) * t
+                         + sS3) * t
+                        + sS2) * t
+                       + sS1) * t
+                    + sS0;
 
       return (pio2_hi - asinr5625) - (p / q - pio2_lo);
     }
index 29410e3e7716081f57fb4eb3e3905e4df7c6623e..6219888b35f70f2017face607b7bd5607662cba2 100644 (file)
@@ -112,100 +112,102 @@ afalg_stream (FILE *stream, const char *alg,
      read-write loop work around an empty-input bug noted below.  */
   int fd = fileno (stream);
   int result;
-  struct stat st;
-  off_t off = ftello (stream);
-  if (0 <= off && fstat (fd, &st) == 0
-      && (S_ISREG (st.st_mode) || S_TYPEISSHM (&st) || S_TYPEISTMO (&st))
-      && off < st.st_size && st.st_size - off < SYS_BUFSIZE_MAX)
-    {
-      /* Make sure the offset of fileno (stream) reflects how many bytes
-         have been read from stream before this function got invoked.
-         Note: fflush on an input stream after ungetc does not work as expected
-         on some platforms.  Therefore this situation is not supported here.  */
-      if (fflush (stream))
-        result = -EIO;
-      else
-        {
-          off_t nbytes = st.st_size - off;
-          if (sendfile (ofd, fd, &off, nbytes) == nbytes)
-            {
-              if (read (ofd, resblock, hashlen) == hashlen)
-                {
-                  /* The input buffers of stream are no longer valid.  */
-                  if (lseek (fd, off, SEEK_SET) != (off_t)-1)
-                    result = 0;
-                  else
-                    /* The file position of fd has not changed.  */
+  {
+    struct stat st;
+    off_t off = ftello (stream);
+    if (0 <= off && fstat (fd, &st) == 0
+        && (S_ISREG (st.st_mode) || S_TYPEISSHM (&st) || S_TYPEISTMO (&st))
+        && off < st.st_size && st.st_size - off < SYS_BUFSIZE_MAX)
+      {
+        /* Make sure the offset of fileno (stream) reflects how many bytes
+           have been read from stream before this function got invoked.
+           Note: fflush on an input stream after ungetc does not work as expected
+           on some platforms.  Therefore this situation is not supported here.  */
+        if (fflush (stream))
+          result = -EIO;
+        else
+          {
+            off_t nbytes = st.st_size - off;
+            if (sendfile (ofd, fd, &off, nbytes) == nbytes)
+              {
+                if (read (ofd, resblock, hashlen) == hashlen)
+                  {
+                    /* The input buffers of stream are no longer valid.  */
+                    if (lseek (fd, off, SEEK_SET) != (off_t)-1)
+                      result = 0;
+                    else
+                      /* The file position of fd has not changed.  */
+                      result = -EAFNOSUPPORT;
+                  }
+                else
+                  /* The file position of fd has not changed.  */
+                  result = -EAFNOSUPPORT;
+              }
+            else
+              /* The file position of fd has not changed.  */
+              result = -EAFNOSUPPORT;
+         }
+      }
+    else
+      {
+        /* sendfile not possible, do a classic read-write loop.  */
+
+        /* Number of bytes to seek (backwards) in case of error.  */
+        off_t nseek = 0;
+
+        for (;;)
+          {
+            char buf[BLOCKSIZE];
+            /* When the stream is not seekable, start with a single-byte block,
+               so that we can use ungetc() in the case that send() fails.  */
+            size_t blocksize = (nseek == 0 && off < 0 ? 1 : BLOCKSIZE);
+            ssize_t size = fread (buf, 1, blocksize, stream);
+            if (size == 0)
+              {
+                /* On Linux < 4.9, the value for an empty stream is wrong (all 0).
+                   See <https://patchwork.kernel.org/patch/9308641/>.
+                   This was not fixed properly until November 2016,
+                   see <https://patchwork.kernel.org/patch/9434741/>.  */
+                result = ferror (stream) ? -EIO : nseek == 0 ? -EAFNOSUPPORT : 0;
+                break;
+              }
+            nseek -= size;
+            if (send (ofd, buf, size, MSG_MORE) != size)
+              {
+                if (nseek == -1)
+                  {
+                    /* 1 byte of pushback buffer is guaranteed on stream, even
+                       if stream is not seekable.  */
+                    ungetc ((unsigned char) buf[0], stream);
                     result = -EAFNOSUPPORT;
-                }
-              else
-                /* The file position of fd has not changed.  */
-                result = -EAFNOSUPPORT;
-            }
-          else
-            /* The file position of fd has not changed.  */
-            result = -EAFNOSUPPORT;
-       }
-    }
-  else
-    {
-      /* sendfile not possible, do a classic read-write loop.  */
-
-      /* Number of bytes to seek (backwards) in case of error.  */
-      off_t nseek = 0;
-
-      for (;;)
-        {
-          char buf[BLOCKSIZE];
-          /* When the stream is not seekable, start with a single-byte block,
-             so that we can use ungetc() in the case that send() fails.  */
-          size_t blocksize = (nseek == 0 && off < 0 ? 1 : BLOCKSIZE);
-          ssize_t size = fread (buf, 1, blocksize, stream);
-          if (size == 0)
-            {
-              /* On Linux < 4.9, the value for an empty stream is wrong (all 0).
-                 See <https://patchwork.kernel.org/patch/9308641/>.
-                 This was not fixed properly until November 2016,
-                 see <https://patchwork.kernel.org/patch/9434741/>.  */
-              result = ferror (stream) ? -EIO : nseek == 0 ? -EAFNOSUPPORT : 0;
-              break;
-            }
-          nseek -= size;
-          if (send (ofd, buf, size, MSG_MORE) != size)
-            {
-              if (nseek == -1)
-                {
-                  /* 1 byte of pushback buffer is guaranteed on stream, even
-                     if stream is not seekable.  */
-                  ungetc ((unsigned char) buf[0], stream);
+                  }
+                else if (fseeko (stream, nseek, SEEK_CUR) == 0)
+                  /* The position of stream has been restored.  */
                   result = -EAFNOSUPPORT;
-                }
-              else if (fseeko (stream, nseek, SEEK_CUR) == 0)
-                /* The position of stream has been restored.  */
-                result = -EAFNOSUPPORT;
-              else
-                result = -EIO;
-              break;
-            }
-
-          /* Don't assume that EOF is sticky. See:
-             <https://sourceware.org/PR19476>.  */
-          if (feof (stream))
-            {
-              result = 0;
-              break;
-            }
-        }
-
-      if (result == 0 && read (ofd, resblock, hashlen) != hashlen)
-        {
-          if (nseek == 0 || fseeko (stream, nseek, SEEK_CUR) == 0)
-            /* The position of stream has been restored.  */
-            result = -EAFNOSUPPORT;
-          else
-            result = -EIO;
-        }
-    }
+                else
+                  result = -EIO;
+                break;
+              }
+
+            /* Don't assume that EOF is sticky. See:
+               <https://sourceware.org/PR19476>.  */
+            if (feof (stream))
+              {
+                result = 0;
+                break;
+              }
+          }
+
+        if (result == 0 && read (ofd, resblock, hashlen) != hashlen)
+          {
+            if (nseek == 0 || fseeko (stream, nseek, SEEK_CUR) == 0)
+              /* The position of stream has been restored.  */
+              result = -EAFNOSUPPORT;
+            else
+              result = -EIO;
+          }
+      }
+  }
   close (ofd);
   return result;
 }
index 15974b5cbb063a7c634a0de391fbdd509319ea22..078a65ce82e76cb246446c73b5f98a6ef263b526 100644 (file)
@@ -97,9 +97,9 @@ alignalloc (idx_t alignment, idx_t size)
 # if ALIGNALLOC_VIA_ALIGNED_ALLOC
   return aligned_alloc (alignment, size);
 # else
-  void *ptr = NULL;
   if (alignment < sizeof (void *))
     alignment = sizeof (void *);
+  void *ptr = NULL;
   /* Work around posix_memalign glitch by treating a 0 size as if it were 1,
      so that returning NULL is equivalent to failing.  */
   errno = posix_memalign (&ptr, alignment, size ? size : 1);
index 5eb16a9ff5c77909268afc7eb74ed2fe3d6dd80e..aff0c3bb66be8c4b42c2182f4b737e692bc5a48f 100644 (file)
@@ -61,11 +61,11 @@ static int stack_dir;           /* 1 or -1 once known.  */
 static int
 find_stack_direction (int *addr, int depth)
 {
-  int dir, dummy = 0;
+  int dummy = 0;
   if (! addr)
     addr = &dummy;
   *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
-  dir = depth ? find_stack_direction (addr, depth - 1) : 0;
+  int dir = depth ? find_stack_direction (addr, depth - 1) : 0;
   return dir + dummy;
 }
 
@@ -140,14 +140,11 @@ alloca (size_t size)
   /* Allocate combined header + user data storage.  */
 
   {
-    /* Address of header.  */
-    register header *new;
-
     size_t combined_size = sizeof (header) + size;
     if (combined_size < sizeof (header))
       memory_full ();
 
-    new = malloc (combined_size);
+    register header *new = malloc (combined_size);
 
     if (! new)
       memory_full ();
index 2ddff632eb5c7f56cdbc7da4784b25834965df85..656b26f529de5444f7f919ea8ebcc13f162f8087 100644 (file)
@@ -29,12 +29,7 @@ amemxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp)
 {
   /* Result accumulator.  */
   char *result;
-  size_t length;
   size_t allocated;
-
-  char orig_sentinel;
-
-  /* Initial memory allocation.  */
   if (resultbuf != NULL && *lengthp > 0)
     {
       result = resultbuf;
@@ -47,10 +42,10 @@ amemxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp)
       if (result == NULL)
         goto out_of_memory_2;
     }
-  length = 0;
+  size_t length = 0;
 
   /* Add sentinel.byte.  */
-  orig_sentinel = s[n];
+  char orig_sentinel = s[n];
   s[n] = '\0';
 
   /* Iterate through S, transforming each NUL terminated segment.
@@ -60,16 +55,13 @@ amemxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp)
     const char *p_end = s + n + 1;
     const char *p;
 
-    p = s;
-    for (;;)
+    for (p = s;;)
       {
         /* Search next NUL byte.  */
         size_t l = strlen (p);
 
         for (;;)
           {
-            size_t k;
-
             /* A call to strxfrm costs about 20 times more than a call to
                strdup of the result.  Therefore it is worth to try to avoid
                calling strxfrm more than once on a given string, by making
@@ -79,14 +71,13 @@ amemxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp)
             if (3 * l >= allocated - length)
               {
                 /* Grow the result buffer.  */
-                size_t new_allocated;
-                char *new_result;
-
-                new_allocated = length + 3 * l + 1;
+                size_t new_allocated = length + 3 * l + 1;
                 if (new_allocated < 2 * allocated)
                   new_allocated = 2 * allocated;
                 if (new_allocated < 64)
                   new_allocated = 64;
+
+                char *new_result;
                 if (result == resultbuf)
                   new_result = (char *) malloc (new_allocated);
                 else
@@ -99,20 +90,19 @@ amemxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp)
               }
 
             errno = 0;
-            k = strxfrm (result + length, p, allocated - length);
+            size_t k = strxfrm (result + length, p, allocated - length);
             if (errno != 0)
               goto fail;
             if (k >= allocated - length)
               {
                 /* Grow the result buffer.  */
-                size_t new_allocated;
-                char *new_result;
-
-                new_allocated = length + k + 1;
+                size_t new_allocated = length + k + 1;
                 if (new_allocated < 2 * allocated)
                   new_allocated = 2 * allocated;
                 if (new_allocated < 64)
                   new_allocated = 64;
+
+                char *new_result;
                 if (result == resultbuf)
                   new_result = (char *) malloc (new_allocated);
                 else
index 67e8b9f48bca6512915dd2854834ba84d9faa99c..7a97004e6563eafe54ab7587bdb5b30d1d37a5df 100644 (file)
@@ -38,13 +38,13 @@ arcfour_stream (arcfour_context * context, const char *inbuf, char *outbuf,
 
   for (; length > 0; length--)
     {
-      char t;
-
       i++;
       j += sbox[i];
-      t = sbox[i];
-      sbox[i] = sbox[j];
-      sbox[j] = t;
+      {
+        char t = sbox[i];
+        sbox[i] = sbox[j];
+        sbox[j] = t;
+      }
       *outbuf++ = (*inbuf++
                    ^ sbox[(0U + sbox[i] + sbox[j]) % ARCFOUR_SBOX_SIZE]);
     }
@@ -65,11 +65,12 @@ arcfour_setkey (arcfour_context * context, const char *key, size_t keylen)
   size_t i, j, k;
   for (i = j = k = 0; i < ARCFOUR_SBOX_SIZE; i++)
     {
-      char t;
       j = (j + sbox[i] + key[k]) % ARCFOUR_SBOX_SIZE;
-      t = sbox[i];
-      sbox[i] = sbox[j];
-      sbox[j] = t;
+      {
+        char t = sbox[i];
+        sbox[i] = sbox[j];
+        sbox[j] = t;
+      }
       if (++k == keylen)
         k = 0;
     }
index e56cba4145887a68e8b68d61d241b2648517fd31..889880c1cb90251ec8f252666e4163c212e05713 100644 (file)
@@ -80,7 +80,6 @@ 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 j;
       uint16_t word0 = 0, word1 = 0, word2 = 0, word3 = 0;
 
       word0 = (word0 << 8) | to_uchar (inbuf[1]);
@@ -94,7 +93,7 @@ arctwo_encrypt (arctwo_context *context, const char *inbuf,
 
       for (size_t i = 0; i < 16; i++)
         {
-          j = i * 4;
+          size_t j = i * 4;
           /* For some reason I cannot combine those steps. */
           word0 += (word1 & ~word3) + (word2 & word3) + context->S[j];
           word0 = rotl16 (word0, 1);
@@ -135,7 +134,6 @@ 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 j;
       uint16_t word0 = 0, word1 = 0, word2 = 0, word3 = 0;
 
       word0 = (word0 << 8) | to_uchar (inbuf[1]);
@@ -149,7 +147,7 @@ arctwo_decrypt (arctwo_context *context, const char *inbuf,
 
       for (size_t i = 16; i > 0; i--)
         {
-          j = (i - 1) * 4;
+          size_t j = (i - 1) * 4;
 
           word3 = rotr16 (word3, 5);
           word3 -= (word0 & ~word2) + (word1 & word2) + context->S[j + 3];
@@ -167,8 +165,8 @@ arctwo_decrypt (arctwo_context *context, const char *inbuf,
             {
               word3 = word3 - context->S[word2 & 63];
               word2 = word2 - context->S[word1 & 63];
-          word1 = word1 - context->S[word0 & 63];
-          word0 = word0 - context->S[word3 & 63];
+              word1 = word1 - context->S[word0 & 63];
+              word0 = word0 - context->S[word3 & 63];
             }
         }
 
@@ -187,12 +185,10 @@ void
 arctwo_setkey_ekb (arctwo_context *context,
                    size_t keylen, const char *key, size_t effective_keylen)
 {
-  uint8_t *S, x;
-
   if (keylen < 40 / 8 || effective_keylen > 1024)
     return;
 
-  S = (uint8_t *) context->S;
+  uint8_t *S = (uint8_t *) context->S;
 
   for (size_t i = 0; i < keylen; i++)
     S[i] = (uint8_t) key[i];
@@ -209,7 +205,7 @@ arctwo_setkey_ekb (arctwo_context *context,
     {
       size_t len = (effective_keylen + 7) >> 3;
       size_t i = 128 - len;
-      x = arctwo_sbox[S[i] & (255 >> (7 & -effective_keylen))];
+      uint8_t x = arctwo_sbox[S[i] & (255 >> (7 & -effective_keylen))];
       S[i] = x;
 
       while (i--)
index 235b4f3fa670c471703303d1690c391b81825ec9..5e3103d58720c40b9e78c27ca857e55e66101c50 100644 (file)
@@ -65,8 +65,6 @@ areadlink_with_size (char const *file, size_t size)
 
   while (1)
     {
-      ssize_t r;
-      size_t link_length;
       char stackbuf[stackbuf_size];
       char *buf = stackbuf;
       char *buffer = NULL;
@@ -81,15 +79,14 @@ areadlink_with_size (char const *file, size_t size)
             }
         }
 
-      r = readlink (file, buf, buf_size);
-      link_length = r;
-
+      ssize_t r = readlink (file, buf, buf_size);
       if (r < 0)
         {
           free (buffer);
           return NULL;
         }
 
+      size_t link_length = r;
       if (link_length < buf_size)
         {
           buf[link_length] = 0;
index b4f3a65713930ca3ddbbf8c80363a81f1de28f00..148664e4d793103d8750cae90a1d23252b03e228 100644 (file)
@@ -70,8 +70,6 @@ areadlinkat_with_size (int fd, char const *file, size_t size)
 
   while (1)
     {
-      ssize_t r;
-      size_t link_length;
       char stackbuf[stackbuf_size];
       char *buf = stackbuf;
       char *buffer = NULL;
@@ -85,15 +83,14 @@ areadlinkat_with_size (int fd, char const *file, size_t size)
             return NULL;
         }
 
-      r = readlinkat (fd, file, buf, buf_size);
-      link_length = r;
-
+      ssize_t r = readlinkat (fd, file, buf, buf_size);
       if (r < 0)
         {
           free (buffer);
           return NULL;
         }
 
+      size_t link_length = r;
       if (link_length < buf_size)
         {
           buf[link_length] = 0;
index 301db760a7efe79f98214bd6a31b3cc4a4186cf7..543a76cd183fb7c5764a4a1fc246aea16d3fe43e 100644 (file)
@@ -80,12 +80,11 @@ ptrdiff_t
 argmatch (const char *arg, const char *const *arglist,
           const void *vallist, size_t valsize)
 {
-  size_t arglen;                /* Length of ARG.  */
+  size_t arglen = strlen (arg); /* Length of ARG.  */
+
   ptrdiff_t matchind = -1;      /* Index of first nonexact match.  */
   bool ambiguous = false;       /* If true, multiple nonexact match(es).  */
 
-  arglen = strlen (arg);
-
   /* Test all elements for either exact match or abbreviated matches.  */
   for (size_t i = 0; arglist[i]; i++)
     {
@@ -187,7 +186,6 @@ __xargmatch_internal (const char *context,
                       bool allow_abbreviation)
 {
   ptrdiff_t res;
-
   if (allow_abbreviation)
     res = argmatch (arg, arglist, vallist, valsize);
   else
@@ -262,18 +260,20 @@ static const enum backup_type backup_vals[] =
 int
 main (int argc, const char *const *argv)
 {
-  const char *cp;
-  enum backup_type backup_type = no_backups;
-
   if (argc > 2)
     {
       fprintf (stderr, "Usage: %s [VERSION_CONTROL]\n", getprogname ());
       exit (1);
     }
 
-  if ((cp = getenv ("VERSION_CONTROL")))
-    backup_type = XARGMATCH ("$VERSION_CONTROL", cp,
-                             backup_args, backup_vals);
+  enum backup_type backup_type = no_backups;
+
+  {
+    const char *cp;
+    if ((cp = getenv ("VERSION_CONTROL")))
+      backup_type = XARGMATCH ("$VERSION_CONTROL", cp,
+                               backup_args, backup_vals);
+  }
 
   if (argc == 2)
     backup_type = XARGMATCH (getprogname (), argv[1],
index ac101ff58431d988b0e80e530a71310fcbcdd017..0eb724dc897db8bc619689e702bcb18cb5d7d232 100644 (file)
@@ -57,9 +57,8 @@ argp_fmtstream_t
 __argp_make_fmtstream (FILE *stream,
                        size_t lmargin, size_t rmargin, ssize_t wmargin)
 {
-  argp_fmtstream_t fs;
-
-  fs = (struct argp_fmtstream *) malloc (sizeof (struct argp_fmtstream));
+  argp_fmtstream_t fs =
+    (struct argp_fmtstream *) malloc (sizeof (struct argp_fmtstream));
   if (fs != NULL)
     {
       fs->stream = stream;
@@ -120,8 +119,7 @@ weak_alias (__argp_fmtstream_free, argp_fmtstream_free)
 void
 __argp_fmtstream_update (argp_fmtstream_t fs)
 {
-  char *buf, *nl;
-  size_t len;
+  char *buf;
 
   /* Scan the buffer for newlines.  */
   buf = fs->buf + fs->point_offs;
@@ -159,8 +157,8 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
           fs->point_col = pad;
         }
 
-      len = fs->p - buf;
-      nl = memchr (buf, '\n', len);
+      size_t len = fs->p - buf;
+      char *nl = memchr (buf, '\n', len);
 
       if (fs->point_col < 0)
         fs->point_col = 0;
@@ -351,11 +349,10 @@ __argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount)
 {
   if ((size_t) (fs->end - fs->p) < amount)
     {
-      ssize_t wrote;
-
       /* Flush FS's buffer.  */
       __argp_fmtstream_update (fs);
 
+      ssize_t wrote;
 #ifdef _LIBC
       __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf);
       wrote = fs->p - fs->buf;
@@ -406,11 +403,10 @@ __argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...)
 
   do
     {
-      va_list args;
-
       if (! __argp_fmtstream_ensure (fs, size_guess))
         return -1;
 
+      va_list args;
       va_start (args, fmt);
       avail = fs->end - fs->p;
       out = __vsnprintf (fs->p, avail, fmt, args);
index 23fd4515365ce6d7890e7db8eac3a4f95d8247d8..00877e60bfa6f4c8318e0675d254063795a033f6 100644 (file)
@@ -242,10 +242,9 @@ __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch)
 ARGP_FS_EI size_t
 __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin)
 {
-  size_t __old;
   if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
     __argp_fmtstream_update (__fs);
-  __old = __fs->lmargin;
+  size_t __old = __fs->lmargin;
   __fs->lmargin = __lmargin;
   return __old;
 }
@@ -254,10 +253,9 @@ __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin)
 ARGP_FS_EI size_t
 __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin)
 {
-  size_t __old;
   if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
     __argp_fmtstream_update (__fs);
-  __old = __fs->rmargin;
+  size_t __old = __fs->rmargin;
   __fs->rmargin = __rmargin;
   return __old;
 }
@@ -266,10 +264,9 @@ __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin)
 ARGP_FS_EI size_t
 __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin)
 {
-  size_t __old;
   if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
     __argp_fmtstream_update (__fs);
-  __old = __fs->wmargin;
+  size_t __old = __fs->wmargin;
   __fs->wmargin = __wmargin;
   return __old;
 }
index d0ac0a5fa59ffd7176f681f756be0dc6ffa25149..b7dbac4708dfd03e2780fa4c5da42488b0036026 100644 (file)
@@ -136,9 +136,9 @@ static const struct uparam_name uparam_names[] =
 static void
 validate_uparams (const struct argp_state *state, struct uparams *upptr)
 {
-  const struct uparam_name *up;
-
-  for (up = uparam_names; up < uparam_names + nuparam_names; up++)
+  for (const struct uparam_name *up = uparam_names;
+       up < uparam_names + nuparam_names;
+       up++)
     {
       if (!(up->is_bool
             || up->uparams_offs == offsetof (struct uparams, rmargin)))
@@ -175,17 +175,15 @@ fill_in_uparams (const struct argp_state *state)
 
           if (isalpha ((unsigned char) *var))
             {
-              size_t var_len;
-              const struct uparam_name *un;
-              int unspec = 0, val = 0;
               const char *arg = var;
 
               while (isalnum ((unsigned char) *arg) || *arg == '-' || *arg == '_')
                 arg++;
-              var_len = arg - var;
+              size_t var_len = arg - var;
 
               SKIPWS (arg);
 
+              int unspec = 0;
               if (*arg == '\0' || *arg == ',')
                 unspec = 1;
               else if (*arg == '=')
@@ -194,6 +192,7 @@ fill_in_uparams (const struct argp_state *state)
                   SKIPWS (arg);
                 }
 
+              int val = 0;
               if (unspec)
                 {
                   if (var[0] == 'n' && var[1] == 'o' && var[2] == '-')
@@ -213,6 +212,7 @@ fill_in_uparams (const struct argp_state *state)
                   SKIPWS (arg);
                 }
 
+              const struct uparam_name *un;
               for (un = uparam_names;
                    un < uparam_names + nuparam_names;
                    un++)
@@ -438,18 +438,12 @@ struct hol
 static struct hol *
 make_hol (const struct argp *argp, struct hol_cluster *cluster)
 {
-  char *so;
-  const struct argp_option *o;
-  const struct argp_option *opts = argp->options;
-  struct hol_entry *entry;
-  unsigned num_short_options = 0;
   struct hol *hol = malloc (sizeof (struct hol));
-
   assert (hol);
-
   hol->num_entries = 0;
   hol->clusters = NULL;
 
+  const struct argp_option *opts = argp->options;
   if (opts)
     {
       int cur_group = 0;
@@ -458,7 +452,8 @@ make_hol (const struct argp *argp, struct hol_cluster *cluster)
       assert (! oalias (opts));
 
       /* Calculate the space needed.  */
-      for (o = opts; ! oend (o); o++)
+      unsigned num_short_options = 0;
+      for (const struct argp_option *o = opts; ! oend (o); o++)
         {
           if (! oalias (o))
             hol->num_entries++;
@@ -474,7 +469,9 @@ make_hol (const struct argp *argp, struct hol_cluster *cluster)
         assert (hol->num_entries <= SIZE_MAX / sizeof (struct hol_entry));
 
       /* Fill in the entries.  */
-      so = hol->short_options;
+      char *so = hol->short_options;
+      const struct argp_option *o;
+      struct hol_entry *entry;
       for (o = opts, entry = hol->entries; ! oend (o); entry++)
         {
           entry->opt = o;
@@ -534,7 +531,6 @@ static void
 hol_free (struct hol *hol)
 {
   struct hol_cluster *cl = hol->clusters;
-
   while (cl)
     {
       struct hol_cluster *next = cl->next;
@@ -561,11 +557,12 @@ hol_entry_short_iterate (const struct hol_entry *entry,
                                      const char *domain, void *cookie),
                          const char *domain, void *cookie)
 {
-  unsigned nopts;
-  int val = 0;
-  const struct argp_option *opt, *real = entry->opt;
+  const struct argp_option *real = entry->opt;
   char *so = entry->short_options;
 
+  int val = 0;
+  const struct argp_option *opt;
+  unsigned nopts;
   for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--)
     if (oshort (opt) && *so == opt->key)
       {
@@ -592,10 +589,11 @@ hol_entry_long_iterate (const struct hol_entry *entry,
                                     const char *domain, void *cookie),
                         const char *domain, void *cookie)
 {
-  unsigned nopts;
-  int val = 0;
-  const struct argp_option *opt, *real = entry->opt;
+  const struct argp_option *real = entry->opt;
 
+  int val = 0;
+  const struct argp_option *opt;
+  unsigned nopts;
   for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--)
     if (opt->name)
       {
@@ -629,8 +627,8 @@ static const char *
 hol_entry_first_long (const struct hol_entry *entry)
 {
   const struct argp_option *opt;
-  unsigned num;
-  for (opt = entry->opt, num = entry->num; num > 0; opt++, num--)
+  unsigned nopts;
+  for (opt = entry->opt, nopts = entry->num; nopts > 0; opt++, nopts--)
     if (opt->name && ovisible (opt))
       return opt->name;
   return NULL;
@@ -781,12 +779,11 @@ hol_cluster_base (struct hol_cluster *cl)
 static int
 canon_doc_option (const char **name)
 {
-  int non_opt;
   /* Skip initial whitespace.  */
   while (isspace ((unsigned char) **name))
     (*name)++;
   /* Decide whether this looks like an option (leading '-') or not.  */
-  non_opt = (**name != '-');
+  int non_opt = (**name != '-');
   /* Skip until part of name used for sorting.  */
   while (**name && !isalnum ((unsigned char) **name))
     (*name)++;
@@ -957,15 +954,13 @@ hol_append (struct hol *hol, struct hol *more)
           more->num_entries = 0;        /* Mark MORE's fields as invalid.  */
         }
       else
-        /* Append the entries in MORE to those in HOL, taking care to only add
-           non-shadowed SHORT_OPTIONS values.  */
         {
-          unsigned left;
-          char *so, *more_so;
-          struct hol_entry *e;
+          /* Append the entries in MORE to those in HOL, taking care to only add
+             non-shadowed SHORT_OPTIONS values.  */
           unsigned num_entries = hol->num_entries + more->num_entries;
           struct hol_entry *entries =
             malloc (num_entries * sizeof (struct hol_entry));
+
           unsigned hol_so_len = strlen (hol->short_options);
           char *short_options =
             malloc (hol_so_len + strlen (more->short_options) + 1);
@@ -982,21 +977,22 @@ hol_append (struct hol *hol, struct hol *more)
           __mempcpy (short_options, hol->short_options, hol_so_len);
 
           /* Fix up the short options pointers from HOL.  */
+          struct hol_entry *e;
+          unsigned left;
           for (e = entries, left = hol->num_entries; left > 0; e++, left--)
             e->short_options
               = short_options + (e->short_options - hol->short_options);
 
           /* Now add the short options from MORE, fixing up its entries
              too.  */
-          so = short_options + hol_so_len;
-          more_so = more->short_options;
+          char *so = short_options + hol_so_len;
+          char *more_so = more->short_options;
           for (left = more->num_entries; left > 0; e++, left--)
             {
-              int opts_left;
-              const struct argp_option *opt;
-
               e->short_options = so;
 
+              int opts_left;
+              const struct argp_option *opt;
               for (opts_left = e->num, opt = e->opt; opts_left; opt++, opts_left--)
                 {
                   int ch = *more_so;
@@ -1032,8 +1028,9 @@ hol_append (struct hol *hol, struct hol *more)
 static struct hol *
 argp_hol (const struct argp *argp, struct hol_cluster *cluster)
 {
-  const struct argp_child *child = argp->children;
   struct hol *hol = make_hol (argp, cluster);
+
+  const struct argp_child *child = argp->children;
   if (child)
     while (child->argp)
       {
@@ -1227,51 +1224,64 @@ static void
 hol_entry_help (struct hol_entry *entry, const struct argp_state *state,
                 argp_fmtstream_t stream, struct hol_help_state *hhstate)
 {
-  unsigned num;
-  const struct argp_option *real = entry->opt, *opt;
-  char *so = entry->short_options;
-  int have_long_opt = 0;        /* We have any long options.  */
   /* Saved margins.  */
   int old_lm = __argp_fmtstream_set_lmargin (stream, 0);
   int old_wm = __argp_fmtstream_wmargin (stream);
+
   /* PEST is a state block holding some of our variables that we'd like to
      share with helper functions.  */
   struct pentry_state pest = { entry, stream, hhstate, 1, state };
 
+  const struct argp_option *real = entry->opt;
+
+  int have_long_opt = 0;        /* We have any long options.  */
   if (! odoc (real))
+    {
+      const struct argp_option *opt;
+      unsigned num;
+      for (opt = real, num = entry->num; num > 0; opt++, num--)
+        if (opt->name && ovisible (opt))
+          {
+            have_long_opt = 1;
+            break;
+          }
+    }
+
+  /* First emit short options.  */
+  {
+    __argp_fmtstream_set_wmargin (stream, uparams.short_opt_col); /* For truly bizarre cases. */
+    char *so = entry->short_options;
+
+    const struct argp_option *opt;
+    unsigned num;
     for (opt = real, num = entry->num; num > 0; opt++, num--)
-      if (opt->name && ovisible (opt))
+      if (oshort (opt) && opt->key == *so)
+        /* OPT has a valid (non shadowed) short option.  */
         {
-          have_long_opt = 1;
-          break;
+          if (ovisible (opt))
+            {
+              comma (uparams.short_opt_col, &pest);
+              __argp_fmtstream_putc (stream, '-');
+              __argp_fmtstream_putc (stream, *so);
+              if (!have_long_opt || uparams.dup_args)
+                arg (real, " %s", "[%s]",
+                     state == NULL ? NULL : state->root_argp->argp_domain,
+                     stream);
+              else if (real->arg)
+                hhstate->suppressed_dup_arg = 1;
+            }
+          so++;
         }
-
-  /* First emit short options.  */
-  __argp_fmtstream_set_wmargin (stream, uparams.short_opt_col); /* For truly bizarre cases. */
-  for (opt = real, num = entry->num; num > 0; opt++, num--)
-    if (oshort (opt) && opt->key == *so)
-      /* OPT has a valid (non shadowed) short option.  */
-      {
-        if (ovisible (opt))
-          {
-            comma (uparams.short_opt_col, &pest);
-            __argp_fmtstream_putc (stream, '-');
-            __argp_fmtstream_putc (stream, *so);
-            if (!have_long_opt || uparams.dup_args)
-              arg (real, " %s", "[%s]",
-                   state == NULL ? NULL : state->root_argp->argp_domain,
-                   stream);
-            else if (real->arg)
-              hhstate->suppressed_dup_arg = 1;
-          }
-        so++;
-      }
+  }
 
   /* Now, long options.  */
   if (odoc (real))
     /* A "documentation" option.  */
     {
       __argp_fmtstream_set_wmargin (stream, uparams.doc_opt_col);
+
+      const struct argp_option *opt;
+      unsigned num;
       for (opt = real, num = entry->num; num > 0; opt++, num--)
         if (opt->name && ovisible (opt))
           {
@@ -1289,6 +1299,9 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state,
     /* A real long option.  */
     {
       __argp_fmtstream_set_wmargin (stream, uparams.long_opt_col);
+
+      const struct argp_option *opt;
+      unsigned num;
       for (opt = real, num = entry->num; num > 0; opt++, num--)
         if (opt->name && ovisible (opt))
           {
@@ -1354,12 +1367,14 @@ static void
 hol_help (struct hol *hol, const struct argp_state *state,
           argp_fmtstream_t stream)
 {
-  unsigned num;
-  struct hol_entry *entry;
   struct hol_help_state hhstate = { NULL, 0, 0 };
 
-  for (entry = hol->entries, num = hol->num_entries; num > 0; entry++, num--)
-    hol_entry_help (entry, state, stream, &hhstate);
+  {
+    struct hol_entry *entry;
+    unsigned num;
+    for (entry = hol->entries, num = hol->num_entries; num > 0; entry++, num--)
+      hol_entry_help (entry, state, stream, &hhstate);
+  }
 
   if (hhstate.suppressed_dup_arg && uparams.dup_args_note)
     {
@@ -1404,24 +1419,27 @@ usage_argful_short_opt (const struct argp_option *opt,
                         const char *domain, void *cookie)
 {
   argp_fmtstream_t stream = cookie;
-  const char *arg = opt->arg;
-  int flags = opt->flags | real->flags;
 
+  const char *arg = opt->arg;
   if (! arg)
     arg = real->arg;
 
-  if (arg && !(flags & OPTION_NO_USAGE))
+  if (arg)
     {
-      arg = dgettext (domain, arg);
-
-      if (flags & OPTION_ARG_OPTIONAL)
-        __argp_fmtstream_printf (stream, " [-%c[%s]]", opt->key, arg);
-      else
+      int flags = opt->flags | real->flags;
+      if (!(flags & OPTION_NO_USAGE))
         {
-          /* Manually do line wrapping so that it (probably) won't
-             get wrapped at the embedded space.  */
-          space (stream, 6 + strlen (arg));
-          __argp_fmtstream_printf (stream, "[-%c %s]", opt->key, arg);
+          arg = dgettext (domain, arg);
+
+          if (flags & OPTION_ARG_OPTIONAL)
+            __argp_fmtstream_printf (stream, " [-%c[%s]]", opt->key, arg);
+          else
+            {
+              /* Manually do line wrapping so that it (probably) won't
+                 get wrapped at the embedded space.  */
+              space (stream, 6 + strlen (arg));
+              __argp_fmtstream_printf (stream, "[-%c %s]", opt->key, arg);
+            }
         }
     }
 
@@ -1436,12 +1454,12 @@ usage_long_opt (const struct argp_option *opt,
                 const char *domain, void *cookie)
 {
   argp_fmtstream_t stream = cookie;
-  const char *arg = opt->arg;
-  int flags = opt->flags | real->flags;
 
+  const char *arg = opt->arg;
   if (! arg)
     arg = real->arg;
 
+  int flags = opt->flags | real->flags;
   if (! (flags & OPTION_NO_USAGE))
     {
       if (arg)
@@ -1465,17 +1483,19 @@ hol_usage (struct hol *hol, argp_fmtstream_t stream)
 {
   if (hol->num_entries > 0)
     {
-      unsigned nentries;
-      struct hol_entry *entry;
       char *short_no_arg_opts = alloca (strlen (hol->short_options) + 1);
       char *snao_end = short_no_arg_opts;
 
       /* First we put a list of short options without arguments.  */
-      for (entry = hol->entries, nentries = hol->num_entries
-           ; nentries > 0
-           ; entry++, nentries--)
-        hol_entry_short_iterate (entry, add_argless_short_opt,
-                                 entry->argp->argp_domain, &snao_end);
+      {
+        struct hol_entry *entry;
+        unsigned nentries;
+        for (entry = hol->entries, nentries = hol->num_entries
+             ; nentries > 0
+             ; entry++, nentries--)
+          hol_entry_short_iterate (entry, add_argless_short_opt,
+                                   entry->argp->argp_domain, &snao_end);
+      }
       if (snao_end > short_no_arg_opts)
         {
           *snao_end++ = '\0';
@@ -1483,18 +1503,26 @@ hol_usage (struct hol *hol, argp_fmtstream_t stream)
         }
 
       /* Now a list of short options *with* arguments.  */
-      for (entry = hol->entries, nentries = hol->num_entries
-           ; nentries > 0
-           ; entry++, nentries--)
-        hol_entry_short_iterate (entry, usage_argful_short_opt,
-                                 entry->argp->argp_domain, stream);
+      {
+        struct hol_entry *entry;
+        unsigned nentries;
+        for (entry = hol->entries, nentries = hol->num_entries
+             ; nentries > 0
+             ; entry++, nentries--)
+          hol_entry_short_iterate (entry, usage_argful_short_opt,
+                                   entry->argp->argp_domain, stream);
+      }
 
       /* Finally, a list of long options (whew!).  */
-      for (entry = hol->entries, nentries = hol->num_entries
-           ; nentries > 0
-           ; entry++, nentries--)
-        hol_entry_long_iterate (entry, usage_long_opt,
-                                entry->argp->argp_domain, stream);
+      {
+        struct hol_entry *entry;
+        unsigned nentries;
+        for (entry = hol->entries, nentries = hol->num_entries
+             ; nentries > 0
+             ; entry++, nentries--)
+          hol_entry_long_iterate (entry, usage_long_opt,
+                                  entry->argp->argp_domain, stream);
+      }
     }
 }
 \f
@@ -1504,11 +1532,11 @@ static size_t
 argp_args_levels (const struct argp *argp)
 {
   size_t levels = 0;
-  const struct argp_child *child = argp->children;
 
   if (argp->args_doc && strchr (argp->args_doc, '\n'))
     levels++;
 
+  const struct argp_child *child = argp->children;
   if (child)
     while (child->argp)
       levels += argp_args_levels ((child++)->argp);
@@ -1527,39 +1555,43 @@ argp_args_usage (const struct argp *argp, const struct argp_state *state,
 {
   char *our_level = *levels;
   int multiple = 0;
-  const struct argp_child *child = argp->children;
-  const char *tdoc =
-    argp->args_doc ? dgettext (argp->argp_domain, argp->args_doc) : NULL;
-  const char *fdoc = filter_doc (tdoc, ARGP_KEY_HELP_ARGS_DOC, argp, state);
   const char *nl = NULL;
 
-  if (fdoc)
-    {
-      const char *cp = fdoc;
-      nl = __strchrnul (cp, '\n');
-      if (*nl != '\0')
-        /* This is a 'multi-level' args doc; advance to the correct position
-           as determined by our state in LEVELS, and update LEVELS.  */
-        {
-          int i;
-          multiple = 1;
-          for (i = 0; i < *our_level; i++)
-            cp = nl + 1, nl = __strchrnul (cp, '\n');
-          (*levels)++;
-        }
+  {
+    const char *tdoc =
+      argp->args_doc ? dgettext (argp->argp_domain, argp->args_doc) : NULL;
+    const char *fdoc = filter_doc (tdoc, ARGP_KEY_HELP_ARGS_DOC, argp, state);
 
-      /* Manually do line wrapping so that it (probably) won't get wrapped at
-         any embedded spaces.  */
-      space (stream, 1 + nl - cp);
+    if (fdoc)
+      {
+        const char *cp = fdoc;
+        nl = __strchrnul (cp, '\n');
+        if (*nl != '\0')
+          /* This is a 'multi-level' args doc; advance to the correct position
+             as determined by our state in LEVELS, and update LEVELS.  */
+          {
+            multiple = 1;
+            for (int i = 0; i < *our_level; i++)
+              cp = nl + 1, nl = __strchrnul (cp, '\n');
+            (*levels)++;
+          }
 
-      __argp_fmtstream_write (stream, cp, nl - cp);
-    }
-  if (fdoc && fdoc != tdoc)
-    free ((char *)fdoc);        /* Free user's modified doc string.  */
+        /* Manually do line wrapping so that it (probably) won't get wrapped at
+           any embedded spaces.  */
+        space (stream, 1 + nl - cp);
 
-  if (child)
-    while (child->argp)
-      advance = !argp_args_usage ((child++)->argp, state, levels, advance, stream);
+        __argp_fmtstream_write (stream, cp, nl - cp);
+      }
+    if (fdoc && fdoc != tdoc)
+      free ((char *)fdoc);        /* Free user's modified doc string.  */
+  }
+
+  {
+    const struct argp_child *child = argp->children;
+    if (child)
+      while (child->argp)
+        advance = !argp_args_usage ((child++)->argp, state, levels, advance, stream);
+  }
 
   if (advance && multiple)
     {
@@ -1590,23 +1622,23 @@ argp_doc (const struct argp *argp, const struct argp_state *state,
           int post, int pre_blank, int first_only,
           argp_fmtstream_t stream)
 {
-  const char *text;
   const char *inp_text;
-  void *input = NULL;
-  int anything = 0;
   size_t inp_text_limit = 0;
-  const char *doc = argp->doc ? dgettext (argp->argp_domain, argp->doc) : NULL;
-  const struct argp_child *child = argp->children;
 
-  if (doc)
-    {
-      char const *vt = strchr (doc, '\v');
-      inp_text = post ? (vt ? vt + 1 : NULL) : doc;
-      inp_text_limit = (!post && vt) ? (vt - doc) : 0;
-    }
-  else
-    inp_text = NULL;
+  {
+    const char *doc = argp->doc ? dgettext (argp->argp_domain, argp->doc) : NULL;
+    if (doc)
+      {
+        char const *vt = strchr (doc, '\v');
+        inp_text = post ? (vt ? vt + 1 : NULL) : doc;
+        inp_text_limit = (!post && vt) ? (vt - doc) : 0;
+      }
+    else
+      inp_text = NULL;
+  }
 
+  const char *text;
+  void *input = NULL;
   if (argp->help_filter)
     /* We have to filter the doc strings.  */
     {
@@ -1623,6 +1655,7 @@ argp_doc (const struct argp *argp, const struct argp_state *state,
   else
     text = (const char *) inp_text;
 
+  int anything = 0;
   if (text)
     {
       if (pre_blank)
@@ -1661,12 +1694,15 @@ argp_doc (const struct argp *argp, const struct argp_state *state,
         }
     }
 
-  if (child)
-    while (child->argp && !(first_only && anything))
-      anything |=
-        argp_doc ((child++)->argp, state,
-                  post, anything || pre_blank, first_only,
-                  stream);
+  {
+    const struct argp_child *child = argp->children;
+    if (child)
+      while (child->argp && !(first_only && anything))
+        anything |=
+          argp_doc ((child++)->argp, state,
+                    post, anything || pre_blank, first_only,
+                    stream);
+  }
 
   return anything;
 }
@@ -1679,10 +1715,6 @@ static void
 _help (const struct argp *argp, const struct argp_state *state, FILE *stream,
        unsigned flags, char *name)
 {
-  int anything = 0;             /* Whether we've output anything.  */
-  struct hol *hol = NULL;
-  argp_fmtstream_t fs;
-
   if (! stream)
     return;
 
@@ -1693,7 +1725,7 @@ _help (const struct argp *argp, const struct argp_state *state, FILE *stream,
   if (! uparams.valid)
     fill_in_uparams (state);
 
-  fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0);
+  argp_fmtstream_t fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0);
   if (! fs)
     {
 #if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
@@ -1702,6 +1734,7 @@ _help (const struct argp *argp, const struct argp_state *state, FILE *stream,
       return;
     }
 
+  struct hol *hol = NULL;
   if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG))
     {
       hol = argp_hol (argp, NULL);
@@ -1713,6 +1746,7 @@ _help (const struct argp *argp, const struct argp_state *state, FILE *stream,
       hol_sort (hol);
     }
 
+  int anything = 0;             /* Whether we've output anything.  */
   if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE))
     /* Print a short "Usage:" message.  */
     {
@@ -1884,12 +1918,11 @@ __argp_error (const struct argp_state *state, const char *fmt, ...)
 
       if (stream)
         {
-          va_list ap;
-
 #if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
           __flockfile (stream);
 #endif
 
+          va_list ap;
           va_start (ap, fmt);
 
 #ifdef _LIBC
@@ -1960,8 +1993,8 @@ __argp_failure (const struct argp_state *state, int status, int errnum,
           if (fmt)
             {
               va_list ap;
-
               va_start (ap, fmt);
+
 #ifdef _LIBC
               char *buf;
 
index c5597a08f66856e111896401c2090bf91cbdb872..6eddc0966925ab64bbe7bf79676c5078efe5b854 100644 (file)
@@ -225,12 +225,11 @@ group_parse (struct group *group, struct argp_state *state, int key, char *arg)
 {
   if (group->parser)
     {
-      error_t err;
       state->hook = group->hook;
       state->input = group->input;
       state->child_inputs = group->child_inputs;
       state->arg_num = group->args_processed;
-      err = (*group->parser)(key, arg, state);
+      error_t err = (*group->parser)(key, arg, state);
       group->hook = state->hook;
       return err;
     }
@@ -458,16 +457,7 @@ static error_t
 parser_init (struct parser *parser, const struct argp *argp,
              int argc, char **argv, int flags, void *input)
 {
-  error_t err = 0;
-  struct group *group;
   struct parser_sizes szs;
-  struct _getopt_data opt_data = _GETOPT_DATA_INITIALIZER;
-  char *storage;
-  size_t glen, gsum;
-  size_t clen, csum;
-  size_t llen, lsum;
-  size_t slen, ssum;
-
   szs.short_len = (flags & ARGP_NO_ARGS) ? 0 : 1;
   szs.long_len = 0;
   szs.num_groups = 0;
@@ -477,31 +467,34 @@ parser_init (struct parser *parser, const struct argp *argp,
     calc_sizes (argp, &szs);
 
   /* Lengths of the various bits of storage used by PARSER.  */
-  glen = (szs.num_groups + 1) * sizeof (struct group);
-  clen = szs.num_child_inputs * sizeof (void *);
-  llen = (szs.long_len + 1) * sizeof (struct option);
-  slen = szs.short_len + 1;
+  size_t glen = (szs.num_groups + 1) * sizeof (struct group);
+  size_t clen = szs.num_child_inputs * sizeof (void *);
+  size_t llen = (szs.long_len + 1) * sizeof (struct option);
+  size_t slen = szs.short_len + 1;
 
   /* Sums of previous lengths, properly aligned.  There's no need to
      align gsum, since struct group is aligned at least as strictly as
      void * (since it contains a void * member).  And there's no need
      to align lsum, since struct option is aligned at least as
      strictly as char.  */
-  gsum = glen;
-  csum = alignto (gsum + clen, alignof (struct option));
-  lsum = csum + llen;
-  ssum = lsum + slen;
+  size_t gsum = glen;
+  size_t csum = alignto (gsum + clen, alignof (struct option));
+  size_t lsum = csum + llen;
+  size_t ssum = lsum + slen;
 
   parser->storage = malloc (ssum);
   if (! parser->storage)
     return ENOMEM;
 
-  storage = parser->storage;
+  char *storage = parser->storage;
   parser->groups = parser->storage;
   parser->child_inputs = (void **) (storage + gsum);
   parser->long_opts = (struct option *) (storage + csum);
   parser->short_opts = storage + lsum;
-  parser->opt_data = opt_data;
+  {
+    struct _getopt_data opt_data = _GETOPT_DATA_INITIALIZER;
+    parser->opt_data = opt_data;
+  }
 
   memset (parser->child_inputs, 0, clen);
   parser_convert (parser, argp, flags);
@@ -522,28 +515,32 @@ parser_init (struct parser *parser, const struct argp *argp,
      values to child parsers.  */
   if (parser->groups < parser->egroup)
     parser->groups->input = input;
-  for (group = parser->groups;
-       group < parser->egroup && (!err || err == EBADKEY);
-       group++)
-    {
-      if (group->parent)
-        /* If a child parser, get the initial input value from the parent. */
-        group->input = group->parent->child_inputs[group->parent_index];
-
-      if (!group->parser
-          && group->argp->children && group->argp->children->argp)
-        /* For the special case where no parsing function is supplied for an
-           argp, propagate its input to its first child, if any (this just
-           makes very simple wrapper argps more convenient).  */
-        group->child_inputs[0] = group->input;
-
-      err = group_parse (group, &parser->state, ARGP_KEY_INIT, NULL);
-    }
-  if (err == EBADKEY)
-    err = 0;                    /* Some parser didn't understand.  */
+  {
+    error_t err = 0;
 
-  if (err)
-    return err;
+    for (struct group *group = parser->groups;
+         group < parser->egroup && (!err || err == EBADKEY);
+         group++)
+      {
+        if (group->parent)
+          /* If a child parser, get the initial input value from the parent. */
+          group->input = group->parent->child_inputs[group->parent_index];
+
+        if (!group->parser
+            && group->argp->children && group->argp->children->argp)
+          /* For the special case where no parsing function is supplied for an
+             argp, propagate its input to its first child, if any (this just
+             makes very simple wrapper argps more convenient).  */
+          group->child_inputs[0] = group->input;
+
+        err = group_parse (group, &parser->state, ARGP_KEY_INIT, NULL);
+      }
+    if (err == EBADKEY)
+      err = 0;                    /* Some parser didn't understand.  */
+
+    if (err)
+      return err;
+  }
 
   if (parser->state.flags & ARGP_NO_ERRS)
     {
@@ -570,8 +567,6 @@ static error_t
 parser_finalize (struct parser *parser,
                  error_t err, int arg_ebadkey, int *end_index)
 {
-  struct group *group;
-
   if (err == EBADKEY && arg_ebadkey)
     /* Suppress errors generated by unparsed arguments.  */
     err = 0;
@@ -582,12 +577,12 @@ parser_finalize (struct parser *parser,
         /* We successfully parsed all arguments!  Call all the parsers again,
            just a few more times... */
         {
-          for (group = parser->groups;
+          for (struct group *group = parser->groups;
                group < parser->egroup && (!err || err==EBADKEY);
                group++)
             if (group->args_processed == 0)
               err = group_parse (group, &parser->state, ARGP_KEY_NO_ARGS, NULL);
-          for (group = parser->egroup - 1;
+          for (struct group *group = parser->egroup - 1;
                group >= parser->groups && (!err || err==EBADKEY);
                group--)
             err = group_parse (group, &parser->state, ARGP_KEY_END, NULL);
@@ -628,7 +623,7 @@ parser_finalize (struct parser *parser,
                            ARGP_HELP_STD_ERR);
 
       /* Since we didn't exit, give each parser an error indication.  */
-      for (group = parser->groups; group < parser->egroup; group++)
+      for (struct group *group = parser->groups; group < parser->egroup; group++)
         group_parse (group, &parser->state, ARGP_KEY_ERROR, NULL);
     }
   else
@@ -637,7 +632,7 @@ parser_finalize (struct parser *parser,
       /* We pass over the groups in reverse order so that child groups are
          given a chance to do there processing before passing back a value to
          the parent.  */
-      for (group = parser->egroup - 1
+      for (struct group *group = parser->egroup - 1
            ; group >= parser->groups && (!err || err == EBADKEY)
            ; group--)
         err = group_parse (group, &parser->state, ARGP_KEY_SUCCESS, NULL);
@@ -646,7 +641,7 @@ parser_finalize (struct parser *parser,
     }
 
   /* Call parsers once more, to do any final cleanup.  Errors are ignored.  */
-  for (group = parser->egroup - 1; group >= parser->groups; group--)
+  for (struct group *group = parser->egroup - 1; group >= parser->groups; group--)
     group_parse (group, &parser->state, ARGP_KEY_FINI, NULL);
 
   if (err == EBADKEY)
@@ -780,9 +775,6 @@ parser_parse_opt (struct parser *parser, int opt, char *val)
 static error_t
 parser_parse_next (struct parser *parser, int *arg_ebadkey)
 {
-  int opt;
-  error_t err;
-
   if (parser->state.quoted && parser->state.next < parser->state.quoted)
     /* The next argument pointer has been moved to before the quoted
        region, so pretend we never saw the quoting "--", and give getopt
@@ -790,6 +782,7 @@ parser_parse_next (struct parser *parser, int *arg_ebadkey)
        process it again.  */
     parser->state.quoted = 0;
 
+  int opt;
   if (parser->try_getopt && !parser->state.quoted)
     /* Give getopt a chance to parse this.  */
     {
@@ -851,6 +844,7 @@ parser_parse_next (struct parser *parser, int *arg_ebadkey)
         }
     }
 
+  error_t err;
   if (opt == KEY_ARG)
     /* A non-option argument; try each parser in turn.  */
     err = parser_parse_arg (parser, parser->opt_data.optarg);
@@ -872,13 +866,6 @@ error_t
 __argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags,
               int *end_index, void *input)
 {
-  error_t err;
-  struct parser parser;
-
-  /* If true, then err == EBADKEY is a result of a non-option argument failing
-     to be parsed (which in some cases isn't actually an error).  */
-  int arg_ebadkey = 0;
-
 #ifndef _LIBC
   if (!(flags & ARGP_PARSE_ARGV0))
     {
@@ -917,11 +904,16 @@ __argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags,
     }
 
   /* Construct a parser for these arguments.  */
-  err = parser_init (&parser, argp, argc, argv, flags, input);
+  struct parser parser;
+  error_t err = parser_init (&parser, argp, argc, argv, flags, input);
 
   if (! err)
     /* Parse! */
     {
+      /* If true, then err == EBADKEY is a result of a non-option argument
+         failing to be parsed (which in some cases isn't actually an error).  */
+      int arg_ebadkey = 0;
+
       while (! err)
         err = parser_parse_next (&parser, &arg_ebadkey);
       err = parser_finalize (&parser, err, arg_ebadkey, end_index);
@@ -940,10 +932,11 @@ __argp_input (const struct argp *argp, const struct argp_state *state)
 {
   if (state)
     {
-      struct group *group;
       struct parser *parser = state->pstate;
 
-      for (group = parser->groups; group < parser->egroup; group++)
+      for (struct group *group = parser->groups;
+           group < parser->egroup;
+           group++)
         if (group->argp == argp)
           return group->input;
     }
index 1262ab4bb7a2c96fa6345c2d6901503c21e7fe0a..b87a07fcbaa9cba603c1b9ea6b8416a014c08396 100644 (file)
@@ -59,15 +59,12 @@ argz_add_sep (char **argz, size_t *argz_len, const char *string, int delim)
 
   if (nlen > 1)
     {
-      const char *rp;
-      char *wp;
-
       *argz = (char *) realloc (*argz, *argz_len + nlen);
       if (*argz == NULL)
         return ENOMEM;
 
-      wp = *argz + *argz_len;
-      rp = string;
+      char *wp = *argz + *argz_len;
+      const char *rp = string;
       do
         if (*rp == delim)
           {
@@ -95,15 +92,12 @@ argz_create_sep (const char *string, int delim, char **argz, size_t *len)
 
   if (nlen > 1)
     {
-      const char *rp;
-      char *wp;
-
       *argz = (char *) malloc (nlen);
       if (*argz == NULL)
         return ENOMEM;
 
-      rp = string;
-      wp = *argz;
+      const char *rp = string;
+      char *wp = *argz;
       do
         if (*rp == delim)
           {
@@ -250,8 +244,6 @@ error_t
 argz_create (char *const argv[], char **argz, size_t *len)
 {
   size_t tlen = 0;
-  char *const *ap;
-  char *p;
 
   for (int argc = 0; argv[argc] != NULL; ++argc)
     tlen += strlen (argv[argc]) + 1;
@@ -264,6 +256,8 @@ argz_create (char *const argv[], char **argz, size_t *len)
       if (*argz == NULL)
         return ENOMEM;
 
+      char *p;
+      char *const *ap;
       for (p = *argz, ap = argv; *ap; ++ap, ++p)
         p = stpcpy (p, *ap);
     }
@@ -325,7 +319,6 @@ argz_replace (char **argz, size_t *argz_len, const char *str, const char *with,
 
   if (str && *str)
     {
-      char *arg = 0;
       char *src = *argz;
       size_t src_len = *argz_len;
       char *dst = 0;
@@ -333,58 +326,62 @@ argz_replace (char **argz, size_t *argz_len, const char *str, const char *with,
       int delayed_copy = 1;     /* True while we've avoided copying anything.  */
       size_t str_len = strlen (str), with_len = strlen (with);
 
-      while (!err && (arg = argz_next (src, src_len, arg)))
-        {
-          char *match = strstr (arg, str);
-          if (match)
-            {
-              char *from = match + str_len;
-              size_t to_len = match - arg;
-              char *to = strndup (arg, to_len);
-
-              while (to && from)
-                {
-                  str_append (&to, &to_len, with, with_len);
-                  if (to)
-                    {
-                      match = strstr (from, str);
-                      if (match)
-                        {
-                          str_append (&to, &to_len, from, match - from);
-                          from = match + str_len;
-                        }
-                      else
-                        {
-                          str_append (&to, &to_len, from, strlen (from));
-                          from = 0;
-                        }
-                    }
-                }
-
-              if (to)
-                {
-                  if (delayed_copy)
-                    /* We avoided copying SRC to DST until we found a match;
-                       now that we've done so, copy everything from the start
-                       of SRC.  */
-                    {
-                      if (arg > src)
-                        err = argz_append (&dst, &dst_len, src, (arg - src));
-                      delayed_copy = 0;
-                    }
-                  if (! err)
-                    err = argz_add (&dst, &dst_len, to);
-                  free (to);
-                }
-              else
-                err = ENOMEM;
-
-              if (replace_count)
-                (*replace_count)++;
-            }
-          else if (! delayed_copy)
-            err = argz_add (&dst, &dst_len, arg);
-        }
+      {
+        char *arg = 0;
+
+        while (!err && (arg = argz_next (src, src_len, arg)))
+          {
+            char *match = strstr (arg, str);
+            if (match)
+              {
+                char *from = match + str_len;
+                size_t to_len = match - arg;
+                char *to = strndup (arg, to_len);
+
+                while (to && from)
+                  {
+                    str_append (&to, &to_len, with, with_len);
+                    if (to)
+                      {
+                        match = strstr (from, str);
+                        if (match)
+                          {
+                            str_append (&to, &to_len, from, match - from);
+                            from = match + str_len;
+                          }
+                        else
+                          {
+                            str_append (&to, &to_len, from, strlen (from));
+                            from = 0;
+                          }
+                      }
+                  }
+
+                if (to)
+                  {
+                    if (delayed_copy)
+                      /* We avoided copying SRC to DST until we found a match;
+                         now that we've done so, copy everything from the start
+                         of SRC.  */
+                      {
+                        if (arg > src)
+                          err = argz_append (&dst, &dst_len, src, (arg - src));
+                        delayed_copy = 0;
+                      }
+                    if (! err)
+                      err = argz_add (&dst, &dst_len, to);
+                    free (to);
+                  }
+                else
+                  err = ENOMEM;
+
+                if (replace_count)
+                  (*replace_count)++;
+              }
+            else if (! delayed_copy)
+              err = argz_add (&dst, &dst_len, arg);
+          }
+      }
 
       if (! err)
         {
index 14811f50f76e94e689006c8734f1754a640f0a4a..b84b959ddff93a7eb92209969996c1bff5f197ab 100644 (file)
@@ -132,11 +132,8 @@ static const long double
 long double
 asinl (long double x)
 {
-  long double y, t, p, q;
-  int sign;
-
-  sign = 1;
-  y = x;
+  int sign = 1;
+  long double y = x;
   if (x < 0.0L)
     {
       sign = -1;
@@ -151,34 +148,36 @@ asinl (long double x)
 
       return (x - x) / (x - x); /* asin(|x|>1) is NaN */
     }
-  else if (y < 0.5L) /* |x| < 0.5 */
+
+  long double t;
+  if (y < 0.5L) /* |x| < 0.5 */
     {
       if (y < 0.000000000000000006938893903907228377647697925567626953125L) /* |x| < 2**-57 */
         if (huge + y > one)
           return y;             /* return x with inexact if x!=0 */
 
       t = x * x;
-      p = (((((((((pS9 * t
-                   + pS8) * t
-                  + pS7) * t
-                 + pS6) * t
-                + pS5) * t
-               + pS4) * t
-              + pS3) * t
-             + pS2) * t
-            + pS1) * t
-           + pS0) * t;
-
-      q = (((((((( t
-                  + qS8) * t
-                 + qS7) * t
-                + qS6) * t
-               + qS5) * t
-              + qS4) * t
-             + qS3) * t
-            + qS2) * t
-           + qS1) * t
-        + qS0;
+      long double p = (((((((((pS9 * t
+                               + pS8) * t
+                              + pS7) * t
+                             + pS6) * t
+                            + pS5) * t
+                           + pS4) * t
+                          + pS3) * t
+                         + pS2) * t
+                        + pS1) * t
+                       + pS0) * t;
+
+      long double q = (((((((( t
+                              + qS8) * t
+                             + qS7) * t
+                            + qS6) * t
+                           + qS5) * t
+                          + qS4) * t
+                         + qS3) * t
+                        + qS2) * t
+                       + qS1) * t
+                    + qS0;
 
       return x + x * (p / q);
     }
@@ -186,29 +185,29 @@ asinl (long double x)
   else if (y < 0.625) /* 0.625 */
     {
       t = y - 0.5625;
-      p = ((((((((((rS10 * t
-                    + rS9) * t
-                   + rS8) * t
-                  + rS7) * t
-                 + rS6) * t
-                + rS5) * t
-               + rS4) * t
-              + rS3) * t
-             + rS2) * t
-            + rS1) * t
-           + rS0) * t;
-
-      q = ((((((((( t
-                    + sS9) * t
-                  + sS8) * t
-                 + sS7) * t
-                + sS6) * t
-               + sS5) * t
-              + sS4) * t
-             + sS3) * t
-            + sS2) * t
-           + sS1) * t
-        + sS0;
+      long double p = ((((((((((rS10 * t
+                                + rS9) * t
+                               + rS8) * t
+                              + rS7) * t
+                             + rS6) * t
+                            + rS5) * t
+                           + rS4) * t
+                          + rS3) * t
+                         + rS2) * t
+                        + rS1) * t
+                       + rS0) * t;
+
+      long double q = ((((((((( t
+                                + sS9) * t
+                              + sS8) * t
+                             + sS7) * t
+                            + sS6) * t
+                           + sS5) * t
+                          + sS4) * t
+                         + sS3) * t
+                        + sS2) * t
+                       + sS1) * t
+                    + sS0;
       t = asinr5625 + p / q;
     }
   else
index 0488b6bef1583baa45078a61144903aff52467d9..ce2f5a48c6bf719adf5a56e80eedb267e0a0aa16 100644 (file)
@@ -25,10 +25,8 @@ char *
 asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
 {
   va_list args;
-  char *result;
-
   va_start (args, format);
-  result = vasnprintf (resultbuf, lengthp, format, args);
+  char *result = vasnprintf (resultbuf, lengthp, format, args);
   va_end (args);
   return result;
 }
index 0232c74836937ae3607e53d6c4a45dd857af4d87..0e3b6850ad2cc0844d94ddc8f9a495d5f2a66053 100644 (file)
@@ -25,10 +25,8 @@ wchar_t *
 asnwprintf (wchar_t *resultbuf, size_t *lengthp, const wchar_t *format, ...)
 {
   va_list args;
-  wchar_t *result;
-
   va_start (args, format);
-  result = vasnwprintf (resultbuf, lengthp, format, args);
+  wchar_t *result = vasnwprintf (resultbuf, lengthp, format, args);
   va_end (args);
   return result;
 }
index 336700be66ce226771ea78ffead664ffb8864cd9..12d43ec820f1b2dabda4cdc4af1a2811cbc2f5e0 100644 (file)
@@ -30,10 +30,8 @@ int
 asprintf (char **resultp, const char *format, ...)
 {
   va_list args;
-  int result;
-
   va_start (args, format);
-  result = vasprintf (resultp, format, args);
+  int result = vasprintf (resultp, format, args);
   va_end (args);
   return result;
 }
index 0e3e34c28ac1cb0d14de2abe5c28807dfd759534..fe827fd335e564703ddb9562781adc6d0a7b650e 100644 (file)
@@ -37,8 +37,6 @@ astrxfrm (const char *s, char *resultbuf, size_t *lengthp)
   char *result;      /* either == resultbuf or == tmpbuf or freshly allocated
                         or NULL.  */
   size_t allocated;  /* number of bytes allocated at result */
-  size_t length;
-
   if (resultbuf != NULL)
     {
       result = resultbuf;
@@ -49,10 +47,10 @@ astrxfrm (const char *s, char *resultbuf, size_t *lengthp)
       result = NULL;
       allocated = 0;
     }
+  size_t length;
 
   {
     size_t l = strlen (s);
-    size_t k;
 
     /* A call to strxfrm costs about 20 times more than a call to strdup of
        the result.  Therefore it is worth to try to avoid calling strxfrm
@@ -69,13 +67,10 @@ astrxfrm (const char *s, char *resultbuf, size_t *lengthp)
           }
         else
           {
-            size_t new_allocated;
-            char *new_result;
-
-            new_allocated = 3 * l + 1;
+            size_t new_allocated = 3 * l + 1;
             if (new_allocated < 2 * allocated)
               new_allocated = 2 * allocated;
-            new_result = (char *) malloc (new_allocated);
+            char *new_result = (char *) malloc (new_allocated);
             if (new_result != NULL)
               {
                 allocated = new_allocated;
@@ -85,7 +80,7 @@ astrxfrm (const char *s, char *resultbuf, size_t *lengthp)
       }
 
     errno = 0;
-    k = strxfrm (result, s, allocated);
+    size_t k = strxfrm (result, s, allocated);
     if (errno != 0)
       goto fail;
     if (k >= allocated)
@@ -100,11 +95,8 @@ astrxfrm (const char *s, char *resultbuf, size_t *lengthp)
           }
         else
           {
-            size_t new_allocated;
-            char *new_result;
-
-            new_allocated = k + 1;
-            new_result = (char *) malloc (new_allocated);
+            size_t new_allocated = k + 1;
+            char *new_result = (char *) malloc (new_allocated);
             if (new_result == NULL)
               goto out_of_memory;
             allocated = new_allocated;
@@ -139,7 +131,6 @@ astrxfrm (const char *s, char *resultbuf, size_t *lengthp)
       else
         {
           char *memory = (char *) malloc (length);
-
           if (memory == NULL)
             goto out_of_memory;
           memcpy (memory, result, length);
index af2b90f86ed98bd22724ce052cc8846a9d6390fa..2f442d9412a10789b96cd969d95febf2ba5aab5c 100644 (file)
@@ -25,10 +25,8 @@ ptrdiff_t
 aszprintf (char **resultp, const char *format, ...)
 {
   va_list args;
-  ptrdiff_t result;
-
   va_start (args, format);
-  result = vaszprintf (resultp, format, args);
+  ptrdiff_t result = vaszprintf (resultp, format, args);
   va_end (args);
   return result;
 }
index fc433a45e4c2c9347e7db824743f67a2cf312138..b61d5ec3749c4417a359ab78876338b731744db5 100644 (file)
@@ -78,12 +78,8 @@ AT_FUNC_NAME (int fd, char const *file AT_FUNC_POST_FILE_PARAM_DECLS)
   errno = ENOTSUP;
   return FUNC_FAIL;
 #else
-  {
-  /* Be careful to choose names unlikely to conflict with
+  /* Be careful to choose variable names unlikely to conflict with
      AT_FUNC_POST_FILE_PARAM_DECLS.  */
-  struct saved_cwd saved_cwd;
-  int saved_errno;
-  FUNC_RESULT err;
 
   {
     char proc_buf[OPENAT_BUFFER_SIZE];
@@ -107,6 +103,7 @@ AT_FUNC_NAME (int fd, char const *file AT_FUNC_POST_FILE_PARAM_DECLS)
       }
   }
 
+  struct saved_cwd saved_cwd;
   if (save_cwd (&saved_cwd) != 0)
     openat_save_fail (errno);
   if (0 <= fd && fd == saved_cwd.desc)
@@ -121,14 +118,14 @@ AT_FUNC_NAME (int fd, char const *file AT_FUNC_POST_FILE_PARAM_DECLS)
 
   if (fchdir (fd) != 0)
     {
-      saved_errno = errno;
+      int saved_errno = errno;
       free_cwd (&saved_cwd);
       errno = saved_errno;
       return FUNC_FAIL;
     }
 
-  err = CALL_FUNC (file);
-  saved_errno = (err == FUNC_FAIL ? errno : 0);
+  FUNC_RESULT err = CALL_FUNC (file);
+  int saved_errno = (err == FUNC_FAIL ? errno : 0);
 
   if (restore_cwd (&saved_cwd) != 0)
     openat_restore_fail (errno);
@@ -138,7 +135,6 @@ AT_FUNC_NAME (int fd, char const *file AT_FUNC_POST_FILE_PARAM_DECLS)
   if (saved_errno)
     errno = saved_errno;
   return err;
-  }
 #endif
 }
 #undef CALL_FUNC
index 91f6f00ed289569038dd92f071a9ecfb12d2058b..e608b794ca9ba51f4e47ff94420b87a1c8e6c8ba 100644 (file)
@@ -41,14 +41,6 @@ at_func2 (int fd1, char const *file1,
           int fd2, char const *file2,
           int (*func) (char const *file1, char const *file2))
 {
-  struct saved_cwd saved_cwd;
-  int saved_errno;
-  int err;
-  char *file1_alt;
-  char *file2_alt;
-  struct stat st1;
-  struct stat st2;
-
   /* There are 16 possible scenarios, based on whether an fd is
      AT_FDCWD or real, and whether a file is absolute or relative:
 
@@ -125,6 +117,8 @@ at_func2 (int fd1, char const *file1,
 
   if (fd1 == AT_FDCWD) /* Cases 3, 7.  */
     {
+      struct stat st1;
+      struct stat st2;
       if (stat (".", &st1) == -1 || fstat (fd2, &st2) == -1)
         return -1;
       if (!S_ISDIR (st2.st_mode))
@@ -137,6 +131,8 @@ at_func2 (int fd1, char const *file1,
     }
   else if (fd2 == AT_FDCWD) /* Cases 12, 13.  */
     {
+      struct stat st1;
+      struct stat st2;
       if (stat (".", &st2) == -1 || fstat (fd1, &st1) == -1)
         return -1;
       if (!S_ISDIR (st1.st_mode))
@@ -149,6 +145,8 @@ at_func2 (int fd1, char const *file1,
     }
   else if (fd1 != fd2) /* Case 15b.  */
     {
+      struct stat st1;
+      struct stat st2;
       if (fstat (fd1, &st1) == -1 || fstat (fd2, &st2) == -1)
         return -1;
       if (!S_ISDIR (st1.st_mode) || !S_ISDIR (st2.st_mode))
@@ -165,6 +163,7 @@ at_func2 (int fd1, char const *file1,
     }
   else /* Case 15a.  */
     {
+      struct stat st1;
       if (fstat (fd1, &st1) == -1)
         return -1;
       if (!S_ISDIR (st1.st_mode))
@@ -172,6 +171,7 @@ at_func2 (int fd1, char const *file1,
           errno = ENOTDIR;
           return -1;
         }
+      struct stat st2;
       if (stat (".", &st2) == 0 && psame_inode (&st1, &st2))
         return func (file1, file2); /* Reduced to case 5.  */
     }
@@ -186,6 +186,7 @@ at_func2 (int fd1, char const *file1,
   /* Cases 3, 7, 12, 13, 15a, 15b remain.  With all reductions in
      place, it is time to start changing directories.  */
 
+  struct saved_cwd saved_cwd;
   if (save_cwd (&saved_cwd) != 0)
     openat_save_fail (errno);
 
@@ -193,7 +194,7 @@ at_func2 (int fd1, char const *file1,
     {
       if (fchdir (fd1) != 0)
         {
-          saved_errno = errno;
+          int saved_errno = errno;
           free_cwd (&saved_cwd);
           errno = saved_errno;
           return -1;
@@ -204,8 +205,8 @@ at_func2 (int fd1, char const *file1,
   /* Cases 3, 7, 12, 13, 15a remain.  Convert one relative name to
      absolute, if necessary.  */
 
-  file1_alt = (char *) file1;
-  file2_alt = (char *) file2;
+  char *file1_alt = (char *) file1;
+  char *file2_alt = (char *) file2;
 
   if (fd1 == AT_FDCWD && !IS_ABSOLUTE_FILE_NAME (file1)) /* Case 7.  */
     {
@@ -215,7 +216,7 @@ at_func2 (int fd1, char const *file1,
       char *cwd = getcwd (NULL, 0);
       if (!cwd)
         {
-          saved_errno = errno;
+          int saved_errno = errno;
           free_cwd (&saved_cwd);
           errno = saved_errno;
           return -1;
@@ -223,7 +224,7 @@ at_func2 (int fd1, char const *file1,
       file1_alt = mfile_name_concat (cwd, file1, NULL);
       if (!file1_alt)
         {
-          saved_errno = errno;
+          int saved_errno = errno;
           free (cwd);
           free_cwd (&saved_cwd);
           errno = saved_errno;
@@ -236,7 +237,7 @@ at_func2 (int fd1, char const *file1,
       char *cwd = getcwd (NULL, 0);
       if (!cwd)
         {
-          saved_errno = errno;
+          int saved_errno = errno;
           free_cwd (&saved_cwd);
           errno = saved_errno;
           return -1;
@@ -244,7 +245,7 @@ at_func2 (int fd1, char const *file1,
       file2_alt = mfile_name_concat (cwd, file2, NULL);
       if (!file2_alt)
         {
-          saved_errno = errno;
+          int saved_errno = errno;
           free (cwd);
           free_cwd (&saved_cwd);
           errno = saved_errno;
@@ -256,7 +257,7 @@ at_func2 (int fd1, char const *file1,
   /* Cases 3, 12, 15a remain.  Change to the correct directory.  */
   if (fchdir (fd1 == AT_FDCWD ? fd2 : fd1) != 0)
     {
-      saved_errno = errno;
+      int saved_errno = errno;
       free_cwd (&saved_cwd);
       if (file1 != file1_alt)
         free (file1_alt);
@@ -268,8 +269,8 @@ at_func2 (int fd1, char const *file1,
 
   /* Finally safe to perform the user's function, then clean up.  */
 
-  err = func (file1_alt, file2_alt);
-  saved_errno = (err < 0 ? errno : 0);
+  int err = func (file1_alt, file2_alt);
+  int saved_errno = (err < 0 ? errno : 0);
 
   if (file1 != file1_alt)
     free (file1_alt);
index a0696a0fb9cb61d8836c22d36390ba67fcb9b8b1..a8fc7469eb9a9c0fd83c7e5784e78dfab61b85c7 100644 (file)
@@ -184,14 +184,11 @@ static const long double
 long double
 atanl (long double x)
 {
-  int k, sign;
-  long double t, u, p, q;
-
   /* Check for zero or NaN.  */
   if (isnanl (x) || x == 0.0)
     return x + x;
 
-  sign = x < 0.0;
+  int sign = x < 0.0;
 
   if (x + x == x)
     {
@@ -203,8 +200,10 @@ atanl (long double x)
     }
 
   if (sign)
-      x = -x;
+    x = -x;
 
+  int k;
+  long double t;
   if (x >= 10.25)
     {
       k = 83;
@@ -216,15 +215,15 @@ atanl (long double x)
          Roundoff to integer is asymmetrical to avoid cancellation when t < 0
          (cf. fdlibm). */
       k = 8.0 * x + 0.25;
-      u = 0.125 * k;
+      long double u = 0.125 * k;
       /* Small arctan argument.  */
       t = (x - u) / (1.0 + x * u);
     }
 
   /* Arctan of small argument t.  */
-  u = t * t;
-  p =     ((((p4 * u) + p3) * u + p2) * u + p1) * u + p0;
-  q = ((((u + q4) * u + q3) * u + q2) * u + q1) * u + q0;
+  long double u = t * t;
+  long double p =     ((((p4 * u) + p3) * u + p2) * u + p1) * u + p0;
+  long double q = ((((u + q4) * u + q3) * u + q2) * u + q1) * u + q0;
   u = t * u * p / q  +  t;
 
   /* arctan x = arctan u  +  arctan t */
index 4dfc4614a1aec2785260ef71398e93cba24ddfab..805c4caa8c73045b6d19eb2b53a13cb0bdd347e2 100644 (file)
@@ -211,7 +211,6 @@ numbered_backup (int dir_fd, char **buffer, idx_t buffer_size, idx_t filelen,
   enum numbered_backup_result result = BACKUP_IS_NEW;
   DIR *dirp = *dirpp;
   char *buf = *buffer;
-  idx_t versionlenmax = 1;
   idx_t baselen = filelen - base_offset;
 
   if (dirp)
@@ -234,6 +233,8 @@ numbered_backup (int dir_fd, char **buffer, idx_t buffer_size, idx_t filelen,
       *dirpp = dirp;
     }
 
+  idx_t versionlenmax = 1;
+
   for (struct dirent *dp; (dp = readdir (dirp)) != NULL; )
     {
       if (_D_EXACT_NAMLEN (dp) < baselen + 4)
index 9df9878d8c090ccff7e6ac3df190cf8b5e00c279..d5a49d634d62d5992c84723e4733965f4426f455 100644 (file)
@@ -335,13 +335,14 @@ static bool
 decode_8 (char const *restrict in, idx_t inlen,
           char *restrict *outp, idx_t *outleft)
 {
-  char *out = *outp;
   if (inlen < 8)
     return false;
 
   if (!isbase32 (in[0]) || !isbase32 (in[1]))
     return false;
 
+  char *out = *outp;
+
   if (*outleft)
     {
       *out++ = ((base32_to_int[to_uchar (in[0])] << 3)
@@ -464,7 +465,6 @@ base32_decode_ctx (struct base32_decode_context *ctx,
                    const char *restrict in, idx_t inlen,
                    char *restrict out, idx_t *outlen)
 {
-  idx_t outleft = *outlen;
   bool ignore_newlines = ctx != NULL;
   bool flush_ctx = false;
   unsigned int ctx_i = 0;
@@ -475,6 +475,7 @@ base32_decode_ctx (struct base32_decode_context *ctx,
       flush_ctx = inlen == 0;
     }
 
+  idx_t outleft = *outlen;
 
   while (true)
     {
@@ -512,8 +513,8 @@ base32_decode_ctx (struct base32_decode_context *ctx,
 
           {
             char const *in_end = in + inlen;
-            char const *non_nl;
 
+            char const *non_nl;
             if (ignore_newlines)
               non_nl = get_8 (ctx, &in, in_end, &inlen);
             else
index cfdfef0bb0111f0563f97b19071a14e1f9d347cb..ac3ad4f3bc86234bff693ca2a108a38f95007119 100644 (file)
@@ -372,13 +372,14 @@ static bool
 decode_4 (char const *restrict in, idx_t inlen,
           char *restrict *outp, idx_t *outleft)
 {
-  char *out = *outp;
   if (inlen < 2)
     return false;
 
   if (!isbase64 (in[0]) || !isbase64 (in[1]))
     return false;
 
+  char *out = *outp;
+
   if (*outleft)
     {
       *out++ = ((base64_to_int[to_uchar (in[0])] << 2)
@@ -466,7 +467,6 @@ base64_decode_ctx (struct base64_decode_context *ctx,
                    const char *restrict in, idx_t inlen,
                    char *restrict out, idx_t *outlen)
 {
-  idx_t outleft = *outlen;
   bool ignore_newlines = ctx != NULL;
   bool flush_ctx = false;
   unsigned int ctx_i = 0;
@@ -477,6 +477,7 @@ base64_decode_ctx (struct base64_decode_context *ctx,
       flush_ctx = inlen == 0;
     }
 
+  idx_t outleft = *outlen;
 
   while (true)
     {
@@ -514,8 +515,8 @@ base64_decode_ctx (struct base64_decode_context *ctx,
 
           {
             char const *in_end = in + inlen;
-            char const *non_nl;
 
+            char const *non_nl;
             if (ignore_newlines)
               non_nl = get_4 (ctx, &in, in_end, &inlen);
             else
index 0d712ecdc34565e5d00ad644a318d14a42db449b..4b5db66f9c359af314b51fa5c0b686460d30ced3 100644 (file)
@@ -29,11 +29,10 @@ char *
 last_component (char const *name)
 {
   char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
-  bool last_was_slash = false;
-
   while (ISSLASH (*base))
     base++;
 
+  bool last_was_slash = false;
   for (char const *p = base; *p; p++)
     {
       if (ISSLASH (*p))
@@ -52,8 +51,6 @@ size_t
 base_len (char const *name)
 {
   size_t len;
-  size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
-
   for (len = strlen (name);  1 < len && ISSLASH (name[len - 1]);  len--)
     continue;
 
@@ -61,6 +58,7 @@ base_len (char const *name)
       && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
     return 2;
 
+  size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
   if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
       && len == prefix_len && ISSLASH (name[prefix_len]))
     return prefix_len + 1;
index c715cc471300c5ad1271e701165fef72cc479dfb..764ec3251a7814a29a6b306e8f3247399d854486 100644 (file)
@@ -367,12 +367,13 @@ bitset_count_ (bitset src)
 bool
 bitset_copy_ (bitset dst, bitset src)
 {
-  bitset_bindex i;
-  bitset_iterator iter;
-
   /* Convert bitset types.  We assume that the DST bitset
      is large enough to hold the SRC bitset.  */
+
   bitset_zero (dst);
+
+  bitset_bindex i;
+  bitset_iterator iter;
   BITSET_FOR_EACH (iter, src, i, 0)
     bitset_set (dst, i);
 
index 724e7d47ec9b97a5d6de9b648ccc032107311f0c..c830933dc2ff99c4744ea11e717db949a38cd171 100644 (file)
@@ -227,11 +227,11 @@ lbitset_prune (bitset bset, lbitset_elt *elt)
       bset->b.csize = 0;
     }
 
-  lbitset_elt *next;
-  for (; elt; elt = next)
+  for (; elt;)
     {
-      next = elt->next;
+      lbitset_elt *next = elt->next;
       lbitset_elt_free (elt);
+      elt = next;
     }
 }
 
@@ -378,12 +378,12 @@ lbitset_elt_find (bitset bset, bitset_windex windex,
 static inline void
 lbitset_weed (bitset bset)
 {
-  lbitset_elt *next;
-  for (lbitset_elt *elt = LBITSET_HEAD (bset); elt; elt = next)
+  for (lbitset_elt *elt = LBITSET_HEAD (bset); elt;)
     {
-      next = elt->next;
+      lbitset_elt *next = elt->next;
       if (lbitset_elt_zero_p (elt))
         lbitset_elt_unlink (bset, elt);
+      elt = next;
     }
 }
 
@@ -724,19 +724,22 @@ lbitset_list (bitset bset, bitset_bindex *list,
           /* The coast is clear, plant boot!  */
 
 #if LBITSET_ELT_WORDS == 2
-          bitset_word word = srcp[0];
-          if (word)
-            BITSET_FOR_EACH_BIT (pos, word)
-              list[count++] = bitno + pos;
-          windex++;
-          bitno = windex * BITSET_WORD_BITS;
-
-          word = srcp[1];
-          if (word)
-            BITSET_FOR_EACH_BIT (pos, word)
-              list[count++] = bitno + pos;
-          windex++;
-          bitno = windex * BITSET_WORD_BITS;
+          {
+            bitset_word word = srcp[0];
+            if (word)
+              BITSET_FOR_EACH_BIT (pos, word)
+                list[count++] = bitno + pos;
+            windex++;
+            bitno = windex * BITSET_WORD_BITS;
+          }
+          {
+            bitset_word word = srcp[1];
+            if (word)
+              BITSET_FOR_EACH_BIT (pos, word)
+                list[count++] = bitno + pos;
+            windex++;
+            bitno = windex * BITSET_WORD_BITS;
+          }
 #else
           for (int i = 0; i < LBITSET_ELT_WORDS; i++)
             {
index 710a60f3d428f66627b02e97d0bae3c4aaba44b3..71fe200c231c14d4ea04de37e5233281c45aa52c 100644 (file)
@@ -658,19 +658,22 @@ tbitset_list (bitset bset, bitset_bindex *list,
               /* The coast is clear, plant boot!  */
 
 #if TBITSET_ELT_WORDS == 2
-              bitset_word word = srcp[0];
-              if (word)
-                BITSET_FOR_EACH_BIT (pos, word)
-                  list[count++] = bitno + pos;
-              windex++;
-              bitno = windex * BITSET_WORD_BITS;
-
-              word = srcp[1];
-              if (word)
-                BITSET_FOR_EACH_BIT (pos, word)
-                  list[count++] = bitno + pos;
-              windex++;
-              bitno = windex * BITSET_WORD_BITS;
+              {
+                bitset_word word = srcp[0];
+                if (word)
+                  BITSET_FOR_EACH_BIT (pos, word)
+                    list[count++] = bitno + pos;
+                windex++;
+                bitno = windex * BITSET_WORD_BITS;
+              }
+              {
+                bitset_word word = srcp[1];
+                if (word)
+                  BITSET_FOR_EACH_BIT (pos, word)
+                    list[count++] = bitno + pos;
+                windex++;
+                bitno = windex * BITSET_WORD_BITS;
+              }
 #else
               for (int i = 0; i < TBITSET_ELT_WORDS; i++, windex++)
                 {
index f1f940b12e48933aa70f9b482675460f4ce71fce..af28ea6db428decb431433f6f87603342eaaa342 100644 (file)
@@ -395,13 +395,15 @@ get_windows_boot_time_fallback (struct timespec *p_boot_time)
   if (GetTickCount64Func != NULL)
     {
       ULONGLONG uptime_ms = GetTickCount64Func ();
-      struct timespec uptime;
-      struct timespec result;
+
       struct timeval tv;
       if (gettimeofday (&tv, NULL) >= 0)
         {
+          struct timespec uptime;
           uptime.tv_sec = uptime_ms / 1000;
           uptime.tv_nsec = (uptime_ms % 1000) * 1000000;
+
+          struct timespec result;
           result.tv_sec = tv.tv_sec;
           result.tv_nsec = tv.tv_usec * 1000;
           if (result.tv_nsec < uptime.tv_nsec)
@@ -411,6 +413,7 @@ get_windows_boot_time_fallback (struct timespec *p_boot_time)
             }
           result.tv_sec -= uptime.tv_sec;
           result.tv_nsec -= uptime.tv_nsec;
+
           *p_boot_time = result;
           return 0;
         }
index 28792cb54e40f0ef7f06e7995d97cd916dc6ef8b..41a8309a46d1373aa01f27a84615cc563fd46f2c 100644 (file)
@@ -42,11 +42,10 @@ btoc32 (int c)
   if (c != EOF)
     {
       mbstate_t state;
-      char s[1];
-      char32_t wc;
-
       mbszero (&state);
+      char s[1];
       s[0] = (unsigned char) c;
+      char32_t wc;
       if (mbrtoc32 (&wc, s, 1, &state) <= 1)
         return wc;
     }
index c14b3fa87071fddc77056bdcabb04343a1597136..f09071a8a9d6a56f6bba61fe69877bbad5b36cb3 100644 (file)
@@ -26,10 +26,9 @@ int
 c_asprintf (char **resultp, const char *format, ...)
 {
   va_list args;
-  int result;
-
   va_start (args, format);
-  result = c_vasprintf (resultp, format, args);
+  int result = c_vasprintf (resultp, format, args);
   va_end (args);
+
   return result;
 }
index 84a0293f7c3d7c760743aa18cf1681413e16dc25..8bfdfa63e6aff7f01d33c16ce19e461de7f6ef3a 100644 (file)
@@ -25,10 +25,9 @@ ptrdiff_t
 c_aszprintf (char **resultp, const char *format, ...)
 {
   va_list args;
-  ptrdiff_t result;
-
   va_start (args, format);
-  result = c_vaszprintf (resultp, format, args);
+  ptrdiff_t result = c_vaszprintf (resultp, format, args);
   va_end (args);
+
   return result;
 }
index c6ef08c4626cbc395455cdaf810f45181ea6edbf..a6583759a30c22538ca1ad53c0b61068c318f1d9 100644 (file)
@@ -30,10 +30,10 @@ int
 c_snprintf (char *str, size_t size, const char *format, ...)
 {
   va_list args;
-  ptrdiff_t ret;
-
   va_start (args, format);
-  ret = c_vsnzprintf (str, size, format, args);
+
+  ptrdiff_t ret = c_vsnzprintf (str, size, format, args);
+
   va_end (args);
 
 #if PTRDIFF_MAX > INT_MAX
index 8b7a30aa5f43698db78b65330ec0f7b7e2816e63..e0a3cf9fcbc841b89c4726716d1d8b78bf00c499 100644 (file)
 ptrdiff_t
 c_snzprintf (char *str, size_t size, const char *format, ...)
 {
-  char *output;
-  size_t len;
-  size_t lenbuf = size;
   va_list args;
-
   va_start (args, format);
-  output = c_vasnprintf (str, &lenbuf, format, args);
-  len = lenbuf;
+
+  size_t lenbuf = size;
+  char *output = c_vasnprintf (str, &lenbuf, format, args);
+  size_t len = lenbuf;
+
   va_end (args);
 
   if (!output)
index 2d963c30e98e25261df15d10c2847d85dd7b0b1f..5e7dd41836fa1b87117854dfe8bffbfc7dd76d25 100644 (file)
@@ -28,29 +28,24 @@ c_strcasecmp (const char *s1, const char *s2)
 {
   register const unsigned char *p1 = (const unsigned char *) s1;
   register const unsigned char *p2 = (const unsigned char *) s2;
-  unsigned char c1, c2;
 
   if (p1 == p2)
     return 0;
 
-  do
+  for (;; p1++, p2++)
     {
-      c1 = c_tolower (*p1);
-      c2 = c_tolower (*p2);
-
-      if (c1 == '\0')
-        break;
-
-      ++p1;
-      ++p2;
+      unsigned char c1 = c_tolower (*p1);
+      unsigned char c2 = c_tolower (*p2);
+
+      if (c1 == '\0' || c1 != c2)
+        {
+          if (UCHAR_MAX <= INT_MAX)
+            return c1 - c2;
+          else
+            /* On machines where 'char' and 'int' are types of the same size,
+               the difference of two 'unsigned char' values - including the
+               sign bit - doesn't fit in an 'int'.  */
+            return _GL_CMP (c1, c2);
+        }
     }
-  while (c1 == c2);
-
-  if (UCHAR_MAX <= INT_MAX)
-    return c1 - c2;
-  else
-    /* On machines where 'char' and 'int' are types of the same size, the
-       difference of two 'unsigned char' values - including the sign bit -
-       doesn't fit in an 'int'.  */
-    return _GL_CMP (c1, c2);
 }
index 36b587be24022276fc45bf59a98e8dc26b0f1856..d3e71d981b50619d6f6d3583e9ca7f25eb774782 100644 (file)
 char *
 c_strcasestr (const char *haystack_start, const char *needle_start)
 {
-  const char *haystack = haystack_start;
   const char *needle = needle_start;
-  size_t needle_len; /* Length of NEEDLE.  */
-  size_t haystack_len; /* Known minimum length of HAYSTACK.  */
-  bool ok = true; /* True if NEEDLE is prefix of HAYSTACK.  */
 
   /* Determine length of NEEDLE, and in the process, make sure
      HAYSTACK is at least as long (no point processing all of a long
      NEEDLE if HAYSTACK is too short).  */
-  while (*haystack && *needle)
-    ok &= (c_tolower ((unsigned char) *haystack++)
-           == c_tolower ((unsigned char) *needle++));
-  if (*needle)
-    return NULL;
-  if (ok)
-    return (char *) haystack_start;
-  needle_len = needle - needle_start;
-  haystack = haystack_start + 1;
-  haystack_len = needle_len - 1;
+  {
+    const char *haystack = haystack_start;
+    bool ok = true; /* True if NEEDLE is prefix of HAYSTACK.  */
+    while (*haystack && *needle)
+      ok &= (c_tolower ((unsigned char) *haystack++)
+             == c_tolower ((unsigned char) *needle++));
+    if (*needle)
+      return NULL;
+    if (ok)
+      return (char *) haystack_start;
+  }
+
+  size_t needle_len = /* Length of NEEDLE.  */
+    needle - needle_start;
+  const char *haystack = haystack_start + 1;
+  size_t haystack_len = /* Known minimum length of HAYSTACK.  */
+    needle_len - 1;
 
   /* Perform the search.  Abstract memory is considered to be an array
      of 'unsigned char' values, not an array of 'char' values.  See
index 6da59d09b32c063063e850588ad35ab3d2936c54..0409e19a98f623d71cefb9cb649ac515325440f5 100644 (file)
@@ -28,29 +28,24 @@ c_strncasecmp (const char *s1, const char *s2, size_t n)
 {
   register const unsigned char *p1 = (const unsigned char *) s1;
   register const unsigned char *p2 = (const unsigned char *) s2;
-  unsigned char c1, c2;
 
   if (p1 == p2 || n == 0)
     return 0;
 
-  do
+  for (;; p1++, p2++)
     {
-      c1 = c_tolower (*p1);
-      c2 = c_tolower (*p2);
-
-      if (--n == 0 || c1 == '\0')
-        break;
-
-      ++p1;
-      ++p2;
+      unsigned char c1 = c_tolower (*p1);
+      unsigned char c2 = c_tolower (*p2);
+
+      if (--n == 0 || c1 == '\0' || c1 != c2)
+        {
+          if (UCHAR_MAX <= INT_MAX)
+            return c1 - c2;
+          else
+            /* On machines where 'char' and 'int' are types of the same size,
+               the difference of two 'unsigned char' values - including the
+               sign bit - doesn't fit in an 'int'.  */
+            return _GL_CMP (c1, c2);
+        }
     }
-  while (c1 == c2);
-
-  if (UCHAR_MAX <= INT_MAX)
-    return c1 - c2;
-  else
-    /* On machines where 'char' and 'int' are types of the same size, the
-       difference of two 'unsigned char' values - including the sign bit -
-       doesn't fit in an 'int'.  */
-    return _GL_CMP (c1, c2);
 }
index e3977d75d48b93f4d8e83b9c33fa603e616d31f0..55e1ca3e3191042a35e48d7bf771fae534fa4c36 100644 (file)
@@ -180,8 +180,9 @@ C_STRTOD (char const *nptr, char **endptr)
             end = p + 1;
             if (p[1] == 'x' || p[1] == 'X')
               {
-                size_t num_hex_digits = 0;
                 p += 2;
+
+                size_t num_hex_digits = 0;
                 /* Parse a non-empty sequence of hexadecimal digits optionally
                    containing the decimal point character '.'.  */
                 while (*p != '\0')
@@ -295,11 +296,10 @@ C_STRTOD (char const *nptr, char **endptr)
           /* Create a modified floating-point number, in which the character '.'
              is replaced with the locale-dependent decimal_point.  */
           size_t len = end - start;
+
+          char stackbuf[1000];
           char *buf;
           char *buf_malloced = NULL;
-          char stackbuf[1000];
-          char *end_in_buf;
-
           if (len < sizeof (stackbuf))
             buf = stackbuf;
           else
@@ -323,6 +323,7 @@ C_STRTOD (char const *nptr, char **endptr)
             buf[decimal_point_p - start] = decimal_point;
           buf[len] = '\0';
 
+          char *end_in_buf;
           r = STRTOD (buf, &end_in_buf);
           if (endptr != NULL)
             *endptr = (char *) (start + (end_in_buf - buf));
index 8f3475944a349e8f6770dcd47ddfe009729f041b..cc5d93e72f0298560dbcac2b47011628f31fc718 100644 (file)
 ptrdiff_t
 c_vsnzprintf (char *str, size_t size, const char *format, va_list args)
 {
-  char *output;
-  size_t len;
   size_t lenbuf = size;
-
-  output = c_vasnprintf (str, &lenbuf, format, args);
-  len = lenbuf;
+  char *output = c_vasnprintf (str, &lenbuf, format, args);
+  size_t len = lenbuf;
 
   if (!output)
     return -1;
index 89205127875c4c2b561900cadc0f168875ca89be..75284521a0a4a7957ccde683c0a8e504521e7b6c 100644 (file)
@@ -24,10 +24,8 @@ char *
 c_xasprintf (const char *format, ...)
 {
   va_list args;
-  char *result;
-
   va_start (args, format);
-  result = c_xvasprintf (format, args);
+  char *result = c_xvasprintf (format, args);
   va_end (args);
 
   return result;
index f4be1b05320952c5647ab9a660b06df8e5ef1240..b3b724cb2aa7aa73e14d177627ea56d973398466 100644 (file)
@@ -31,7 +31,7 @@ size_t
 c32stombs (char *dest, const char32_t *src, size_t len)
 {
   mbstate_t state;
-
   mbszero (&state);
+
   return c32srtombs (dest, &src, len, &state);
 }
index ecaf3d2afb67c72c4c1eecdd10baef0de69e20ce..36ce8d3cf6c9b49506679a7ce0de2dc8f8d2c5f6 100644 (file)
@@ -42,9 +42,9 @@ c32tob (wint_t wc)
   if (wc != WEOF)
     {
       mbstate_t state;
-      char buf[8];
-
       mbszero (&state);
+
+      char buf[8];
       if (c32rtomb (buf, wc, &state) == 1)
         return (unsigned char) buf[0];
     }
index b5d3dfbf2ed1e3385c5419fa197dfede10e8e2a4..66b7c4c87e735defbf42e397fe9a15bc444b58a5 100644 (file)
@@ -60,13 +60,13 @@ canon_host (const char *host)
 char *
 canon_host_r (char const *host, int *cherror)
 {
-  char *retval = NULL;
   static struct addrinfo hints;
+  hints.ai_flags = AI_CANONNAME;
+
   struct addrinfo *res = NULL;
-  int status;
+  int status = getaddrinfo (host, NULL, &hints, &res);
 
-  hints.ai_flags = AI_CANONNAME;
-  status = getaddrinfo (host, NULL, &hints, &res);
+  char *retval = NULL;
   if (!status)
     {
       /* https://lists.gnu.org/r/bug-coreutils/2006-09/msg00300.html
index be5519da5886036e1e42a9893d958aa5f6684b70..cddf2ff36e062ee6164d8baffc9fcb46d114fec1 100644 (file)
@@ -191,11 +191,6 @@ struct realpath_bufs
 static char *
 realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs)
 {
-  char *dest;
-  char const *start;
-  char const *end;
-  int num_links = 0;
-
   if (name == NULL)
     {
       /* As per Single Unix Specification V2 we must return an error if
@@ -215,13 +210,14 @@ realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs)
     }
 
   char *rname = bufs->rname.data;
-  bool end_in_extra_buffer = false;
-  bool failed = true;
 
   /* This is always zero for Posix hosts, but can be 2 for MS-Windows
      and MS-DOS X:/foo/bar file names.  */
   idx_t prefix_len;
 
+  char *dest;
+  char const *start;
+
   if (!IS_ABSOLUTE_FILE_NAME (name))
     {
       while (!__getcwd (bufs->rname.data, bufs->rname.length))
@@ -254,13 +250,18 @@ realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs)
       start = name + prefix_len;
     }
 
-  for ( ; *start; start = end)
+  int num_links = 0;
+  bool end_in_extra_buffer = false;
+  bool failed = true;
+
+  for (; *start;)
     {
       /* Skip sequence of multiple file name separators.  */
       while (ISSLASH (*start))
         ++start;
 
       /* Find end of component.  */
+      char const *end;
       for (end = start; *end && !ISSLASH (*end); ++end)
         /* Nothing.  */;
 
@@ -379,6 +380,8 @@ realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs)
                       : errno == EINVAL))
             goto error;
         }
+
+      start = end;
     }
   if (dest > rname + prefix_len + 1 && ISSLASH (dest[-1]))
     --dest;
index a8eadfb8567443ddd377471d4505cf51000049ba..49eaffd4f17763cad9f3c2944b8e108cbc27e644 100644 (file)
@@ -180,13 +180,6 @@ static char *
 canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
                                 struct realpath_bufs *bufs)
 {
-  char *dest;
-  char const *start;
-  char const *end;
-  Hash_table *ht = NULL;
-  bool logical = (can_mode & CAN_NOLINKS) != 0;
-  int num_links = 0;
-
   canonicalize_mode_t can_exist = can_mode & CAN_MODE_MASK;
   if (multiple_bits_set (can_exist))
     {
@@ -207,13 +200,14 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
     }
 
   char *rname = bufs->rname.data;
-  bool end_in_extra_buffer = false;
-  bool failed = true;
 
   /* This is always zero for Posix hosts, but can be 2 for MS-Windows
      and MS-DOS X:/foo/bar file names.  */
   idx_t prefix_len;
 
+  char *dest;
+  char const *start;
+
   if (!IS_ABSOLUTE_FILE_NAME (name))
     {
       while (!getcwd (bufs->rname.data, bufs->rname.length))
@@ -277,13 +271,21 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
       start = name + prefix_len;
     }
 
-  for ( ; *start; start = end)
+  bool logical = (can_mode & CAN_NOLINKS) != 0;
+
+  int num_links = 0;
+  Hash_table *ht = NULL;
+  bool end_in_extra_buffer = false;
+  bool failed = true;
+
+  for (; *start;)
     {
       /* Skip sequence of multiple file name separators.  */
       while (ISSLASH (*start))
         ++start;
 
       /* Find end of component.  */
+      char const *end;
       for (end = start; *end && !ISSLASH (*end); ++end)
         /* Nothing.  */;
 
@@ -366,7 +368,7 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
                   if (seen_triple (&ht, start, &st))
                     {
                       if (can_exist == CAN_MISSING)
-                        continue;
+                        goto next_component;
                       errno = ELOOP;
                       goto error;
                     }
@@ -433,6 +435,9 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
                           && !end[strspn (end, SLASHES)])))
             goto error;
         }
+
+     next_component:
+      start = end;
     }
   if (dest > rname + prefix_len + 1 && ISSLASH (dest[-1]))
     --dest;
@@ -469,9 +474,12 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
   scratch_buffer_init (&bufs.rname);
   scratch_buffer_init (&bufs.extra);
   scratch_buffer_init (&bufs.link);
+
   char *result = canonicalize_filename_mode_stk (name, can_mode, &bufs);
+
   scratch_buffer_free (&bufs.link);
   scratch_buffer_free (&bufs.extra);
   scratch_buffer_free (&bufs.rname);
+
   return result;
 }
index e954b53bee58433167a5ee901911075084406f3c..efd9abfd561d666a2b0e3d51e4b37a8beb8c7269 100644 (file)
@@ -48,27 +48,25 @@ cbrt (double x)
 {
   if (isfinite (x) && x != 0.0)
     {
-      double xm, ym, u, t2;
+      /* Reduce X.  XM now is in range 1.0 to 0.5.  */
       int xe;
-
-      /* Reduce X.  XM now is an range 1.0 to 0.5.  */
-      xm = frexp (fabs (x), &xe);
-
-      u = (0.354895765043919860
-           + ((1.50819193781584896
-               + ((-2.11499494167371287
-                   + ((2.44693122563534430
-                       + ((-1.83469277483613086
-                           + (0.784932344976639262 - 0.145263899385486377 * xm)
-                             * xm)
-                          * xm))
-                      * xm))
-                  * xm))
-              * xm));
-
-      t2 = u * u * u;
-
-      ym = u * (t2 + 2.0 * xm) / (2.0 * t2 + xm) * factor[2 + xe % 3];
+      double xm = frexp (fabs (x), &xe);
+
+      double u = (0.354895765043919860
+                  + ((1.50819193781584896
+                      + ((-2.11499494167371287
+                          + ((2.44693122563534430
+                              + ((-1.83469277483613086
+                                  + (0.784932344976639262 - 0.145263899385486377 * xm)
+                                    * xm)
+                                 * xm))
+                             * xm))
+                         * xm))
+                     * xm));
+
+      double t2 = u * u * u;
+
+      double ym = u * (t2 + 2.0 * xm) / (2.0 * t2 + xm) * factor[2 + xe % 3];
 
       return ldexp (x > 0.0 ? ym : -ym, xe / 3);
     }
index 63fee54732630dd3b4f48cfed3243b0536b7a6a2..5d7fad9aedc5f238e1cec34fe632729dbed0cebb 100644 (file)
@@ -48,18 +48,16 @@ cbrtf (float x)
 {
   if (isfinite (x) && x != 0.0f)
     {
-      float xm, ym, u, t2;
+      /* Reduce X.  XM now is in range 1.0 to 0.5.  */
       int xe;
+      float xm = frexpf (fabsf (x), &xe);
 
-      /* Reduce X.  XM now is an range 1.0 to 0.5.  */
-      xm = frexpf (fabsf (x), &xe);
+      float u = (0.492659620528969547
+                 + (0.697570460207922770 - 0.191502161678719066 * xm) * xm);
 
-      u = (0.492659620528969547
-           + (0.697570460207922770 - 0.191502161678719066 * xm) * xm);
+      float t2 = u * u * u;
 
-      t2 = u * u * u;
-
-      ym = u * (t2 + 2.0 * xm) / (2.0 * t2 + xm) * factor[2 + xe % 3];
+      float ym = u * (t2 + 2.0 * xm) / (2.0 * t2 + xm) * factor[2 + xe % 3];
 
       return ldexpf (x > 0.0 ? ym : -ym, xe / 3);
     }
index e6998daa6c90b83bd8a442245f7e0007a16cc452..d6968afc5d65b05773dc29288473b004c617ce2b 100644 (file)
@@ -80,9 +80,7 @@ cbrtl (long double x)
 {
   if (isfinite (x) && x != 0.0L)
     {
-      int e, rem, sign;
-      long double z;
-
+      int sign;
       if (x > 0)
         sign = 1;
       else
@@ -91,8 +89,9 @@ cbrtl (long double x)
           x = -x;
         }
 
-      z = x;
+      long double z = x;
       /* extract power of 2, leaving mantissa between 0.5 and 1  */
+      int e;
       x = frexpl (x, &e);
 
       /* Approximate cube root of number between .5 and 1,
@@ -104,6 +103,7 @@ cbrtl (long double x)
            + 1.3304961236013647092521e0L) * x + 3.7568280825958912391243e-1L;
 
       /* exponent divided by 3 */
+      int rem;
       if (e >= 0)
         {
           rem = e;
index a7b55991f385bde28c50f81132b8a1222848df36..157556185e8155b2547d54529b9678527d583df1 100644 (file)
@@ -115,9 +115,8 @@ chdir_long (char *dir)
   {
     size_t len = strlen (dir);
     char *dir_end = dir + len;
-    struct cd_buf cdb;
-    size_t n_leading_slash;
 
+    struct cd_buf cdb;
     cdb_init (&cdb);
 
     /* If DIR is the empty string, then the chdir above
@@ -126,7 +125,7 @@ chdir_long (char *dir)
     assure (PATH_MAX <= len);
 
     /* Count leading slashes.  */
-    n_leading_slash = strspn (dir, "/");
+    size_t n_leading_slash = strspn (dir, "/");
 
     /* Handle any leading slashes as well as any name that matches
        the regular expression, m!^//hostname[/]*! .  Handling this
@@ -135,7 +134,6 @@ chdir_long (char *dir)
        code in the following loop cleaner.  */
     if (n_leading_slash == 2)
       {
-        int err;
         /* Find next slash.
            We already know that dir[2] is neither a slash nor '\0'.  */
         char *slash = memchr (dir + 3, '/', dir_end - (dir + 3));
@@ -145,7 +143,7 @@ chdir_long (char *dir)
             return -1;
           }
         *slash = '\0';
-        err = cdb_advance_fd (&cdb, dir);
+        int err = cdb_advance_fd (&cdb, dir);
         *slash = '/';
         if (err != 0)
           goto Fail;
@@ -163,7 +161,6 @@ chdir_long (char *dir)
 
     while (PATH_MAX <= dir_end - dir)
       {
-        int err;
         /* Find a slash that is PATH_MAX or fewer bytes away from dir.
            I.e. see if there is a slash that will give us a name of
            length PATH_MAX-1 or less.  */
@@ -176,7 +173,7 @@ chdir_long (char *dir)
 
         *slash = '\0';
         assure (slash - dir < PATH_MAX);
-        err = cdb_advance_fd (&cdb, dir);
+        int err = cdb_advance_fd (&cdb, dir);
         *slash = '/';
         if (err != 0)
           goto Fail;
@@ -214,13 +211,11 @@ chdir_long (char *dir)
 int
 main (int argc, char *argv[])
 {
-  char *line = NULL;
-  size_t n = 0;
-  int len;
-
   atexit (close_stdout);
 
-  len = getline (&line, &n, stdin);
+  char *line = NULL;
+  size_t n = 0;
+  int len = getline (&line, &n, stdin);
   if (len < 0)
     {
       int saved_errno = errno;
index 6ecf0d4ec582859decd97446684aa3853da83493..8e888dc1cb11c53f76f6070a547249273cd9d969 100644 (file)
@@ -52,41 +52,38 @@ char *
 new_classpath (const char * const *classpaths, unsigned int classpaths_count,
                bool use_minimal_classpath)
 {
-  const char *old_classpath;
-  unsigned int length;
-  char *result;
-  char *p;
-
-  old_classpath = (use_minimal_classpath ? NULL : getenv (CLASSPATHVAR));
+  const char *old_classpath = (use_minimal_classpath ? NULL : getenv (CLASSPATHVAR));
   if (old_classpath == NULL)
     old_classpath = "";
 
-  length = 0;
+  unsigned int length = 0;
   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')
     length--;
 
-  result = XNMALLOC (length + 1, char);
-  p = result;
-  for (unsigned int i = 0; i < classpaths_count; i++)
-    {
-      memcpy (p, classpaths[i], strlen (classpaths[i]));
-      p += strlen (classpaths[i]);
-      *p++ = PATH_SEPARATOR;
-    }
-  if (old_classpath[0] != '\0')
-    {
-      memcpy (p, old_classpath, strlen (old_classpath));
-      p += strlen (old_classpath);
-    }
-  else
-    {
-      if (classpaths_count > 0)
-        p--;
-    }
-  *p = '\0';
+  char *result = XNMALLOC (length + 1, char);
+  {
+    char *p = result;
+    for (unsigned int i = 0; i < classpaths_count; i++)
+      {
+        memcpy (p, classpaths[i], strlen (classpaths[i]));
+        p += strlen (classpaths[i]);
+        *p++ = PATH_SEPARATOR;
+      }
+    if (old_classpath[0] != '\0')
+      {
+        memcpy (p, old_classpath, strlen (old_classpath));
+        p += strlen (old_classpath);
+      }
+    else
+      {
+        if (classpaths_count > 0)
+          p--;
+      }
+    *p = '\0';
+  }
 
   return result;
 }
index 34af089d55f8f73b7fe0d8ffa4a04ffeba1df82e..b93ca157b3b7c42e5df354a3dd4a2d96d608b315 100644 (file)
@@ -165,10 +165,8 @@ cleanup_action (_GL_UNUSED int sig)
 
     if (fds != NULL)
       {
-        gl_list_iterator_t iter;
+        gl_list_iterator_t iter = gl_list_iterator (fds);
         const void *element;
-
-        iter = gl_list_iterator (fds);
         while (gl_list_iterator_next (&iter, &element, NULL))
           {
             clean_temp_asyncsafe_close ((struct closeable_fd *) element);
@@ -182,10 +180,8 @@ cleanup_action (_GL_UNUSED int sig)
 
     if (files != NULL)
       {
-        gl_list_iterator_t iter;
+        gl_list_iterator_t iter = gl_list_iterator (files);
         const void *element;
-
-        iter = gl_list_iterator (files);
         while (gl_list_iterator_next (&iter, &element, NULL))
           {
             const char *file = (const char *) element;
@@ -201,26 +197,28 @@ cleanup_action (_GL_UNUSED int sig)
 
       if (dir != NULL)
         {
-          gl_list_iterator_t iter;
-          const void *element;
-
-          /* First cleanup the files in the subdirectories.  */
-          iter = gl_list_iterator (dir->files);
-          while (gl_list_iterator_next (&iter, &element, NULL))
-            {
-              const char *file = (const char *) element;
-              unlink (file);
-            }
-          gl_list_iterator_free (&iter);
-
-          /* Then cleanup the subdirectories.  */
-          iter = gl_list_iterator (dir->subdirs);
-          while (gl_list_iterator_next (&iter, &element, NULL))
-            {
-              const char *subdir = (const char *) element;
-              rmdir (subdir);
-            }
-          gl_list_iterator_free (&iter);
+          {
+            /* First cleanup the files in the subdirectories.  */
+            gl_list_iterator_t iter = gl_list_iterator (dir->files);
+            const void *element;
+            while (gl_list_iterator_next (&iter, &element, NULL))
+              {
+                const char *file = (const char *) element;
+                unlink (file);
+              }
+            gl_list_iterator_free (&iter);
+          }
+          {
+            /* Then cleanup the subdirectories.  */
+            gl_list_iterator_t iter = gl_list_iterator (dir->subdirs);
+            const void *element;
+            while (gl_list_iterator_next (&iter, &element, NULL))
+              {
+                const char *subdir = (const char *) element;
+                rmdir (subdir);
+              }
+            gl_list_iterator_free (&iter);
+          }
 
           /* Then cleanup the temporary directory itself.  */
           rmdir (dir->dirname);
@@ -363,9 +361,7 @@ unregister_temporary_file (const char *absolute_file_name)
 int
 cleanup_temporary_file (const char *absolute_file_name, bool cleanup_verbose)
 {
-  int err;
-
-  err = clean_temp_unlink (absolute_file_name, cleanup_verbose);
+  int err = clean_temp_unlink (absolute_file_name, cleanup_verbose);
   unregister_temporary_file (absolute_file_name);
 
   return err;
index 8c62275886c651980c6f922818ba89e9a65e9565..5e6c1d196f0ce3d6384ef9cdbde5f3f209bc9b10 100644 (file)
@@ -150,13 +150,9 @@ create_temp_dir (const char *prefix, const char *parentdir,
 
   if (mt) gl_lock_lock (dir_cleanup_list_lock);
 
-  struct tempdir * volatile *tmpdirp = NULL;
-  struct tempdir *tmpdir;
-  char *xtemplate;
-  char *tmpdirname;
-
   /* See whether it can take the slot of an earlier temporary directory
      already cleaned up.  */
+  struct tempdir * volatile *tmpdirp = NULL;
   for (size_t i = 0; i < dir_cleanup_list.tempdir_count; i++)
     if (dir_cleanup_list.tempdir_list[i] == NULL)
       {
@@ -214,7 +210,7 @@ create_temp_dir (const char *prefix, const char *parentdir,
     }
 
   /* Initialize a 'struct tempdir'.  */
-  tmpdir = XMALLOC (struct tempdir);
+  struct tempdir *tmpdir = XMALLOC (struct tempdir);
   tmpdir->dirname = NULL;
   tmpdir->cleanup_verbose = cleanup_verbose;
   tmpdir->subdirs =
@@ -227,7 +223,7 @@ create_temp_dir (const char *prefix, const char *parentdir,
                           NULL, false);
 
   /* Create the temporary directory.  */
-  xtemplate = (char *) xmalloca (PATH_MAX);
+  char *xtemplate = (char *) xmalloca (PATH_MAX);
   if (path_search (xtemplate, PATH_MAX, parentdir, prefix, parentdir == NULL))
     {
       error (0, errno,
@@ -235,7 +231,7 @@ create_temp_dir (const char *prefix, const char *parentdir,
       goto quit;
     }
   block_fatal_signals ();
-  tmpdirname = mkdtemp (xtemplate);
+  char *tmpdirname = mkdtemp (xtemplate);
   int saved_errno = errno;
   if (tmpdirname != NULL)
     {
@@ -297,9 +293,8 @@ unregister_temp_file (struct temp_dir *dir,
   if (mt) gl_lock_lock (dir_cleanup_list_lock);
 
   gl_list_t list = tmpdir->files;
-  gl_list_node_t node;
 
-  node = gl_list_search (list, absolute_file_name);
+  gl_list_node_t node = gl_list_search (list, absolute_file_name);
   if (node != NULL)
     {
       char *old_string = (char *) gl_list_node_value (list, node);
@@ -344,9 +339,8 @@ unregister_temp_subdir (struct temp_dir *dir,
   if (mt) gl_lock_lock (dir_cleanup_list_lock);
 
   gl_list_t list = tmpdir->subdirs;
-  gl_list_node_t node;
 
-  node = gl_list_search (list, absolute_dir_name);
+  gl_list_node_t node = gl_list_search (list, absolute_dir_name);
   if (node != NULL)
     {
       char *old_string = (char *) gl_list_node_value (list, node);
@@ -379,9 +373,7 @@ int
 cleanup_temp_file (struct temp_dir *dir,
                    const char *absolute_file_name)
 {
-  int err;
-
-  err = clean_temp_unlink (absolute_file_name, dir->cleanup_verbose);
+  int err = clean_temp_unlink (absolute_file_name, dir->cleanup_verbose);
   unregister_temp_file (dir, absolute_file_name);
 
   return err;
@@ -393,9 +385,7 @@ int
 cleanup_temp_subdir (struct temp_dir *dir,
                      const char *absolute_dir_name)
 {
-  int err;
-
-  err = do_rmdir (absolute_dir_name, dir->cleanup_verbose);
+  int err = do_rmdir (absolute_dir_name, dir->cleanup_verbose);
   unregister_temp_subdir (dir, absolute_dir_name);
 
   return err;
@@ -409,38 +399,42 @@ cleanup_temp_dir_contents (struct temp_dir *dir)
 {
   struct tempdir *tmpdir = (struct tempdir *)dir;
   int err = 0;
-  gl_list_t list;
-  gl_list_iterator_t iter;
-  const void *element;
-  gl_list_node_t node;
 
   /* First cleanup the files in the subdirectories.  */
-  list = tmpdir->files;
-  iter = gl_list_iterator (list);
-  while (gl_list_iterator_next (&iter, &element, &node))
-    {
-      char *file = (char *) element;
+  {
+    gl_list_t list = tmpdir->files;
+    gl_list_iterator_t iter = gl_list_iterator (list);
+    const void *element;
+    gl_list_node_t node;
+    while (gl_list_iterator_next (&iter, &element, &node))
+      {
+        char *file = (char *) element;
 
-      err |= clean_temp_unlink (file, dir->cleanup_verbose);
-      gl_list_remove_node (list, node);
-      /* Now only we can free file.  */
-      free (file);
-    }
-  gl_list_iterator_free (&iter);
+        err |= clean_temp_unlink (file, dir->cleanup_verbose);
+        gl_list_remove_node (list, node);
+        /* Now only we can free file.  */
+        free (file);
+      }
+    gl_list_iterator_free (&iter);
+  }
 
   /* Then cleanup the subdirectories.  */
-  list = tmpdir->subdirs;
-  iter = gl_list_iterator (list);
-  while (gl_list_iterator_next (&iter, &element, &node))
-    {
-      char *subdir = (char *) element;
+  {
+    gl_list_t list = tmpdir->subdirs;
+    gl_list_iterator_t iter = gl_list_iterator (list);
+    const void *element;
+    gl_list_node_t node;
+    while (gl_list_iterator_next (&iter, &element, &node))
+      {
+        char *subdir = (char *) element;
 
-      err |= do_rmdir (subdir, dir->cleanup_verbose);
-      gl_list_remove_node (list, node);
-      /* Now only we can free subdir.  */
-      free (subdir);
-    }
-  gl_list_iterator_free (&iter);
+        err |= do_rmdir (subdir, dir->cleanup_verbose);
+        gl_list_remove_node (list, node);
+        /* Now only we can free subdir.  */
+        free (subdir);
+      }
+    gl_list_iterator_free (&iter);
+  }
 
   return err;
 }
@@ -553,10 +547,8 @@ register_fd (int fd)
 int
 open_temp (const char *file_name, int flags, mode_t mode, bool delete_on_close)
 {
-  int fd;
-  int saved_errno;
-
   block_fatal_signals ();
+  int fd;
   /* Note: 'open' here is actually open() or open_safer().  */
 #if defined _WIN32 && ! defined __CYGWIN__
   /* Use _O_TEMPORARY when possible, to increase the chances that the
@@ -566,7 +558,7 @@ open_temp (const char *file_name, int flags, mode_t mode, bool delete_on_close)
   else
 #endif
     fd = open (file_name, flags, mode);
-  saved_errno = errno;
+  int saved_errno = errno;
   if (fd >= 0)
     register_fd (fd);
   unblock_fatal_signals ();
@@ -582,10 +574,9 @@ open_temp (const char *file_name, int flags, mode_t mode, bool delete_on_close)
 FILE *
 fopen_temp (const char *file_name, const char *mode, bool delete_on_close)
 {
+  block_fatal_signals ();
   FILE *fp;
   int saved_errno;
-
-  block_fatal_signals ();
   /* Note: 'fopen' here is actually fopen() or fopen_safer().  */
 #if defined _WIN32 && ! defined __CYGWIN__
   /* Use _O_TEMPORARY when possible, to increase the chances that the
@@ -687,9 +678,6 @@ close_temp (int fd)
 
   clean_temp_init_asyncsafe_close ();
 
-  int result = 0;
-  int saved_errno = 0;
-
   bool mt = gl_multithreaded ();
 
   if (mt) gl_lock_lock (descriptors_lock);
@@ -700,40 +688,44 @@ close_temp (int fd)
     abort ();
 
   /* Search through the list, and clean it up on the fly.  */
+  int result = 0;
+  int saved_errno = 0;
   bool found = false;
-  gl_list_iterator_t iter = gl_list_iterator (list);
-  const void *elt;
-  gl_list_node_t node;
-  if (gl_list_iterator_next (&iter, &elt, &node))
-    for (;;)
-      {
-        struct closeable_fd *element = (struct closeable_fd *) elt;
+  {
+    gl_list_iterator_t iter = gl_list_iterator (list);
+    const void *elt;
+    gl_list_node_t node;
+    if (gl_list_iterator_next (&iter, &elt, &node))
+      for (;;)
+        {
+          struct closeable_fd *element = (struct closeable_fd *) elt;
 
-        /* Close the file descriptor, avoiding races with the signal
-           handler.  */
-        if (element->fd == fd)
-          {
-            found = true;
-            result = clean_temp_asyncsafe_close (element);
-            saved_errno = errno;
-          }
+          /* Close the file descriptor, avoiding races with the signal
+             handler.  */
+          if (element->fd == fd)
+            {
+              found = true;
+              result = clean_temp_asyncsafe_close (element);
+              saved_errno = errno;
+            }
 
-        bool free_this_node = element->done;
-        struct closeable_fd *element_to_free = element;
-        gl_list_node_t node_to_free = node;
+          bool free_this_node = element->done;
+          struct closeable_fd *element_to_free = element;
+          gl_list_node_t node_to_free = node;
 
-        bool have_next = gl_list_iterator_next (&iter, &elt, &node);
+          bool have_next = gl_list_iterator_next (&iter, &elt, &node);
 
-        if (free_this_node)
-          {
-            free (element_to_free);
-            gl_list_remove_node (list, node_to_free);
-          }
+          if (free_this_node)
+            {
+              free (element_to_free);
+              gl_list_remove_node (list, node_to_free);
+            }
 
-        if (!have_next)
-          break;
-      }
-  gl_list_iterator_free (&iter);
+          if (!have_next)
+            break;
+        }
+    gl_list_iterator_free (&iter);
+  }
   if (!found)
     /* descriptors should already contain fd.  */
     abort ();
@@ -749,9 +741,6 @@ fclose_variant_temp (FILE *fp, int (*fclose_variant) (FILE *))
 {
   int fd = fileno (fp);
 
-  int result = 0;
-  int saved_errno = 0;
-
   bool mt = gl_multithreaded ();
 
   if (mt) gl_lock_lock (descriptors_lock);
@@ -762,40 +751,44 @@ fclose_variant_temp (FILE *fp, int (*fclose_variant) (FILE *))
     abort ();
 
   /* Search through the list, and clean it up on the fly.  */
+  int result = 0;
+  int saved_errno = 0;
   bool found = false;
-  gl_list_iterator_t iter = gl_list_iterator (list);
-  const void *elt;
-  gl_list_node_t node;
-  if (gl_list_iterator_next (&iter, &elt, &node))
-    for (;;)
-      {
-        struct closeable_fd *element = (struct closeable_fd *) elt;
+  {
+    gl_list_iterator_t iter = gl_list_iterator (list);
+    const void *elt;
+    gl_list_node_t node;
+    if (gl_list_iterator_next (&iter, &elt, &node))
+      for (;;)
+        {
+          struct closeable_fd *element = (struct closeable_fd *) elt;
 
-        /* Close the file descriptor and the stream, avoiding races with the
-           signal handler.  */
-        if (element->fd == fd)
-          {
-            found = true;
-            result = asyncsafe_fclose_variant (element, fp, fclose_variant);
-            saved_errno = errno;
-          }
+          /* Close the file descriptor and the stream, avoiding races with the
+             signal handler.  */
+          if (element->fd == fd)
+            {
+              found = true;
+              result = asyncsafe_fclose_variant (element, fp, fclose_variant);
+              saved_errno = errno;
+            }
 
-        bool free_this_node = element->done;
-        struct closeable_fd *element_to_free = element;
-        gl_list_node_t node_to_free = node;
+          bool free_this_node = element->done;
+          struct closeable_fd *element_to_free = element;
+          gl_list_node_t node_to_free = node;
 
-        bool have_next = gl_list_iterator_next (&iter, &elt, &node);
+          bool have_next = gl_list_iterator_next (&iter, &elt, &node);
 
-        if (free_this_node)
-          {
-            free (element_to_free);
-            gl_list_remove_node (list, node_to_free);
-          }
+          if (free_this_node)
+            {
+              free (element_to_free);
+              gl_list_remove_node (list, node_to_free);
+            }
 
-        if (!have_next)
-          break;
-      }
-  gl_list_iterator_free (&iter);
+          if (!have_next)
+            break;
+        }
+    gl_list_iterator_free (&iter);
+  }
   if (!found)
     /* descriptors should have contained fd.  */
     abort ();
index 56af147b528c70d3e491e536caac7bf214b34c69..5943760b3c34283c00733daef926eb4231f2ff9f 100644 (file)
@@ -48,31 +48,28 @@ copy_file_internal (const char *src_filename, const char *dest_filename,
                     bool preserve)
 {
   int err = 0;
-  int src_fd;
-  struct stat statbuf;
-  int mode;
-  int dest_fd;
 
-  src_fd = open (src_filename, O_RDONLY | O_BINARY | O_CLOEXEC);
+  int src_fd = open (src_filename, O_RDONLY | O_BINARY | O_CLOEXEC);
   if (src_fd < 0)
     return GL_COPY_ERR_OPEN_READ;
+  struct stat statbuf;
   if (fstat (src_fd, &statbuf) < 0)
     {
       err = GL_COPY_ERR_OPEN_READ;
       goto error_src;
     }
 
-  mode = statbuf.st_mode & 07777;
+  int mode = statbuf.st_mode & 07777;
   off_t inbytes = S_ISREG (statbuf.st_mode) ? statbuf.st_size : -1;
   bool empty_regular_file = inbytes == 0;
 
-  dest_fd = open (dest_filename,
-                  O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_CLOEXEC,
-                  /* If preserve is true, we must assume that the file may
-                     have confidential contents.  Therefore open it with mode
-                     0600 and assign the permissions at the end.
-                     If preserve is false, open it with mode 0666 & ~umask.  */
-                  preserve ? 0600 : 0666);
+  int dest_fd = open (dest_filename,
+                      O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_CLOEXEC,
+                      /* If preserve is true, we must assume that the file may
+                         have confidential contents.  Therefore open it with
+                         mode 0600 and assign the permissions at the end.
+                         If preserve is false, open it with mode 0666 & ~umask.  */
+                      preserve ? 0600 : 0666);
   if (dest_fd < 0)
     {
       err = GL_COPY_ERR_OPEN_BACKUP_WRITE;
@@ -102,7 +99,10 @@ copy_file_internal (const char *src_filename, const char *dest_filename,
       int bufsize = IO_SIZE;
       char *buf = malloc (bufsize);
       if (!buf)
-        buf = smallbuf, bufsize = sizeof smallbuf;
+        {
+          buf = smallbuf;
+          bufsize = sizeof smallbuf;
+        }
 
       while (true)
         {
@@ -142,9 +142,9 @@ copy_file_internal (const char *src_filename, const char *dest_filename,
       /* Preserve the access and modification times.  */
       {
         struct timespec ts[2];
-
         ts[0] = get_stat_atime (&statbuf);
         ts[1] = get_stat_mtime (&statbuf);
+
         utimens (dest_filename, ts);
       }
 
index 34be82b9c355ebd9fa1735bc0c5afb859ced8f9d..860f20cb520d7cbb1de8301fe1c509030e552586 100644 (file)
@@ -83,9 +83,6 @@ cosl (long double x)
 long double
 cosl (long double x)
 {
-  long double y[2],z=0.0L;
-  int n;
-
   /* cosl(NaN) is NaN */
   if (isnanl (x))
     return x;
@@ -93,7 +90,10 @@ cosl (long double x)
   /* |x| ~< pi/4 */
   if (x >= -0.7853981633974483096156608458198757210492
       && x <= 0.7853981633974483096156608458198757210492)
-    return kernel_cosl(x, z);
+    {
+      long double z = 0.0L;
+      return kernel_cosl(x, z);
+    }
 
   /* cosl(Inf) is NaN, cosl(0) is 1 */
   else if (x + x == x && x != 0.0)
@@ -102,7 +102,8 @@ cosl (long double x)
   /* argument reduction needed */
   else
     {
-      n = ieee754_rem_pio2l (x, y);
+      long double y[2];
+      int n = ieee754_rem_pio2l (x, y);
       switch (n & 3)
         {
         case 0:
index 84df10f491b351e03e509d2156f668c67e839071..8fd9dbb8b22e0c4dbec96113672d4c43131dd861 100644 (file)
@@ -43,11 +43,9 @@ static unsigned long crc_table[256];
 static void
 make_crc_table (int bits)
 {
-  unsigned long c;
-
   for (int n = 0; n < 256; n++)
     {
-      c = (unsigned long) n;
+      unsigned long c = (unsigned long) n;
       for (int k = 0; k < bits; k++)
         {
           if (c & 1)
index 69d00a61c647cbb1de1fa4c6fe8fcc826991192c..da4e61ce5f4a1eabc2673a4839e1f3af353e1a29 100644 (file)
@@ -32,23 +32,6 @@ __attribute__ ((__target__ ("pclmul,avx")))
 uint32_t
 crc32_update_no_xor_pclmul (uint32_t crc, const void *buf, size_t len)
 {
-  const __m128i_u *data = buf;
-  __m128i *datarw;
-  size_t bytes_remaining = len;
-  __m128i in256[4] = { 0 };
-  __m128i xor_crc;
-  __m128i in1 = _mm_setzero_si128 ();
-  __m128i in2 = _mm_setzero_si128 ();
-  __m128i in3 = _mm_setzero_si128 ();
-  __m128i in4 = _mm_setzero_si128 ();
-  __m128i in5 = _mm_setzero_si128 ();
-  __m128i in6 = _mm_setzero_si128 ();
-  __m128i in7 = _mm_setzero_si128 ();
-  __m128i in8 = _mm_setzero_si128 ();
-  __m128i final_buf[12] = { 0 };
-  __m128i fold_high;
-  __m128i fold_low;
-
   /* These constants are calculated as T-1 mod P
      0x8F352D95 = (544 - 1) mod P etc
      This method is described in Fast CRC Computation for Generic Polynomials
@@ -60,45 +43,60 @@ crc32_update_no_xor_pclmul (uint32_t crc, const void *buf, size_t len)
      P(x) is the generator polynomial for this CRC32 implementation */
   __m128i mu_poly = _mm_set_epi64x (0x1DB710641, 0x1F7011641);
 
+  const __m128i_u *data = buf;
+  size_t bytes_remaining = len;
+  __m128i final_buf[12] = { 0 };
+  __m128i *datarw;
+
   if (bytes_remaining >= 128)
     {
       /* Here we fold 4x 128bit words forward by 512 bits */
       /* First load up our initial state */
-      in1 = _mm_loadu_si128 (data);
-      in2 = _mm_loadu_si128 (data + 1);
-      in3 = _mm_loadu_si128 (data + 2);
-      in4 = _mm_loadu_si128 (data + 3);
+      __m128i in1 = _mm_loadu_si128 (data);
+      __m128i in2 = _mm_loadu_si128 (data + 1);
+      __m128i in3 = _mm_loadu_si128 (data + 2);
+      __m128i in4 = _mm_loadu_si128 (data + 3);
 
       /* Initialise with incoming CRC */
-      xor_crc = _mm_set_epi32 (0, 0, 0, crc);
-      in1 = _mm_xor_si128 (in1, xor_crc);
+      {
+        __m128i xor_crc = _mm_set_epi32 (0, 0, 0, crc);
+        in1 = _mm_xor_si128 (in1, xor_crc);
+      }
 
       while (bytes_remaining >= 128)
         {
           /* Load up second set of 512 bits */
-          in5 = _mm_loadu_si128 (data + 4);
-          in6 = _mm_loadu_si128 (data + 5);
-          in7 = _mm_loadu_si128 (data + 6);
-          in8 = _mm_loadu_si128 (data + 7);
+          __m128i in5 = _mm_loadu_si128 (data + 4);
+          __m128i in6 = _mm_loadu_si128 (data + 5);
+          __m128i in7 = _mm_loadu_si128 (data + 6);
+          __m128i in8 = _mm_loadu_si128 (data + 7);
 
           /* We shift the high QWORD forward 544 bits and the
              low QWORD 480 bits */
-          fold_high = _mm_clmulepi64_si128 (in1, shift544_shift480, 0x11);
-          fold_low = _mm_clmulepi64_si128 (in1, shift544_shift480, 0x00);
-          in1 = _mm_xor_si128 (in5, fold_high);
-          in1 = _mm_xor_si128 (in1, fold_low);
-          fold_high = _mm_clmulepi64_si128 (in2, shift544_shift480, 0x11);
-          fold_low = _mm_clmulepi64_si128 (in2, shift544_shift480, 0x00);
-          in2 = _mm_xor_si128 (in6, fold_high);
-          in2 = _mm_xor_si128 (in2, fold_low);
-          fold_high = _mm_clmulepi64_si128 (in3, shift544_shift480, 0x11);
-          fold_low = _mm_clmulepi64_si128 (in3, shift544_shift480, 0x00);
-          in3 = _mm_xor_si128 (in7, fold_high);
-          in3 = _mm_xor_si128 (in3, fold_low);
-          fold_high = _mm_clmulepi64_si128 (in4, shift544_shift480, 0x11);
-          fold_low = _mm_clmulepi64_si128 (in4, shift544_shift480, 0x00);
-          in4 = _mm_xor_si128 (in8, fold_high);
-          in4 = _mm_xor_si128 (in4, fold_low);
+          {
+            __m128i fold_high = _mm_clmulepi64_si128 (in1, shift544_shift480, 0x11);
+            __m128i fold_low = _mm_clmulepi64_si128 (in1, shift544_shift480, 0x00);
+            in1 = _mm_xor_si128 (in5, fold_high);
+            in1 = _mm_xor_si128 (in1, fold_low);
+          }
+          {
+            __m128i fold_high = _mm_clmulepi64_si128 (in2, shift544_shift480, 0x11);
+            __m128i fold_low = _mm_clmulepi64_si128 (in2, shift544_shift480, 0x00);
+            in2 = _mm_xor_si128 (in6, fold_high);
+            in2 = _mm_xor_si128 (in2, fold_low);
+          }
+          {
+            __m128i fold_high = _mm_clmulepi64_si128 (in3, shift544_shift480, 0x11);
+            __m128i fold_low = _mm_clmulepi64_si128 (in3, shift544_shift480, 0x00);
+            in3 = _mm_xor_si128 (in7, fold_high);
+            in3 = _mm_xor_si128 (in3, fold_low);
+          }
+          {
+            __m128i fold_high = _mm_clmulepi64_si128 (in4, shift544_shift480, 0x11);
+            __m128i fold_low = _mm_clmulepi64_si128 (in4, shift544_shift480, 0x00);
+            in4 = _mm_xor_si128 (in8, fold_high);
+            in4 = _mm_xor_si128 (in4, fold_low);
+          }
 
           bytes_remaining -= 64;
           data += 4;
@@ -118,9 +116,11 @@ crc32_update_no_xor_pclmul (uint32_t crc, const void *buf, size_t len)
       /* Move everything to final_buf because it is RW */
       /* XOR in previous CRC value */
       memcpy (final_buf, data, bytes_remaining);
-      in1 = _mm_loadu_si128 (final_buf);
-      xor_crc = _mm_set_epi32 (0, 0, 0, crc);
-      in1 = _mm_xor_si128 (in1, xor_crc);
+      __m128i in1 = _mm_loadu_si128 (final_buf);
+      {
+        __m128i xor_crc = _mm_set_epi32 (0, 0, 0, crc);
+        in1 = _mm_xor_si128 (in1, xor_crc);
+      }
       _mm_storeu_si128 (final_buf, in1);
       datarw = final_buf;
     }
@@ -128,13 +128,13 @@ crc32_update_no_xor_pclmul (uint32_t crc, const void *buf, size_t len)
   while (bytes_remaining >= 32)
     {
       /* Do 128-bit folds as above */
-      in1 = _mm_loadu_si128 (datarw);
-      in2 = _mm_loadu_si128 (datarw + 1);
+      __m128i in1 = _mm_loadu_si128 (datarw);
+      __m128i in2 = _mm_loadu_si128 (datarw + 1);
 
       /* We shift the high QWORD forward 160 bits and the
          low QWORD 96 bits */
-      fold_high = _mm_clmulepi64_si128 (in1, shift160_shift96, 0x11);
-      fold_low = _mm_clmulepi64_si128 (in1, shift160_shift96, 0x00);
+      __m128i fold_high = _mm_clmulepi64_si128 (in1, shift160_shift96, 0x11);
+      __m128i fold_low = _mm_clmulepi64_si128 (in1, shift160_shift96, 0x00);
       in2 = _mm_xor_si128 (in2, fold_high);
       in2 = _mm_xor_si128 (in2, fold_low);
 
@@ -149,6 +149,8 @@ crc32_update_no_xor_pclmul (uint32_t crc, const void *buf, size_t len)
      which means with little endian we're shifting the number higher
      we'll also use this step to pick the <16 byte case */
 
+  __m128i in1;
+
   if (bytes_remaining != 16)
     {
       /* Pad remainder and fold 128-bits
@@ -156,16 +158,21 @@ crc32_update_no_xor_pclmul (uint32_t crc, const void *buf, size_t len)
          This is inefficient so we only actually want to hit this on the actual end of data
          If we're reading a multiple of 32 bytes in the loop then this will never get hit */
 
+      __m128i in2;
+
       /* Read in at an offset so we get the shift for free */
-      memcpy (((char *) in256) + (32 - bytes_remaining), datarw,
-              bytes_remaining);
-      in1 = _mm_loadu_si128 (in256);
-      in2 = _mm_loadu_si128 (in256 + 1);
+      {
+        __m128i in256[4] = { 0 };
+        memcpy (((char *) in256) + (32 - bytes_remaining), datarw,
+                bytes_remaining);
+        in1 = _mm_loadu_si128 (in256);
+        in2 = _mm_loadu_si128 (in256 + 1);
+      }
 
       /* Now we fold in1 onto in2 */
       shift160_shift96 = _mm_set_epi64x (0x0ccaa009e, 0x1751997d0);
-      fold_high = _mm_clmulepi64_si128 (in1, shift160_shift96, 0x11);
-      fold_low = _mm_clmulepi64_si128 (in1, shift160_shift96, 0x00);
+      __m128i fold_high = _mm_clmulepi64_si128 (in1, shift160_shift96, 0x11);
+      __m128i fold_low = _mm_clmulepi64_si128 (in1, shift160_shift96, 0x00);
       in2 = _mm_xor_si128 (in2, fold_high);
       in1 = _mm_xor_si128 (in2, fold_low);
     }
@@ -174,36 +181,41 @@ crc32_update_no_xor_pclmul (uint32_t crc, const void *buf, size_t len)
 
   /* We now have 16 bytes and fold as normal */
 
-  in2 =
-    _mm_and_si128 (_mm_srli_si128 (in1, 8), _mm_set_epi64x (0, 0xffffffff));
-  in3 =
-    _mm_and_si128 (_mm_srli_si128 (in1, 12), _mm_set_epi64x (0, 0xffffffff));
-  in1 = _mm_and_si128 (in1, _mm_set_epi64x (0, 0xffffffffffffffff));
-  /* Multiply first 64 bits against shift96 */
-  in1 = _mm_clmulepi64_si128 (shift96_shift64, in1, 0x00);
-  /* First 32 bits go on in2 */
-  in2 =
-    _mm_xor_si128 (in2, _mm_and_si128 (in1, _mm_set_epi64x (0, 0xffffffff)));
-  /* Next 64 bits go on in3 */
-  in3 = _mm_xor_si128 (in3, _mm_srli_si128 (in1, 4));
-  /* Then shift 64 bits from here */
-  in1 = _mm_clmulepi64_si128 (shift96_shift64, in2, 0x01);
-  in1 = _mm_xor_si128 (in1, in3);
-
-  /* This is the Barrett reduction */
-  /* Take the bottom 32 bits */
-  in2 = _mm_and_si128 (in1, _mm_set_epi64x (0, 0xffffffff));
-  /* Multiply by mu */
-  in2 = _mm_clmulepi64_si128 (mu_poly, in2, 0x00);
-  /* Take the bottom 32 bits of the result */
-  in2 = _mm_and_si128 (in2, _mm_set_epi64x (0, 0xffffffff));
-  /* Multiply by P(x) */
-  in2 = _mm_clmulepi64_si128 (mu_poly, in2, 0x01);
-  /* XOR against input */
-  in1 = _mm_xor_si128 (in1, in2);
-  /* Take bits 32-63 as the CRC */
-  in1 = _mm_srli_si128 (in1, 4);
-  crc = _mm_cvtsi128_si32 (in1);
-
-  return crc;
+  {
+    __m128i in2;
+    __m128i in3;
+
+    in2 =
+      _mm_and_si128 (_mm_srli_si128 (in1, 8), _mm_set_epi64x (0, 0xffffffff));
+    in3 =
+      _mm_and_si128 (_mm_srli_si128 (in1, 12), _mm_set_epi64x (0, 0xffffffff));
+    in1 = _mm_and_si128 (in1, _mm_set_epi64x (0, 0xffffffffffffffff));
+    /* Multiply first 64 bits against shift96 */
+    in1 = _mm_clmulepi64_si128 (shift96_shift64, in1, 0x00);
+    /* First 32 bits go on in2 */
+    in2 =
+      _mm_xor_si128 (in2, _mm_and_si128 (in1, _mm_set_epi64x (0, 0xffffffff)));
+    /* Next 64 bits go on in3 */
+    in3 = _mm_xor_si128 (in3, _mm_srli_si128 (in1, 4));
+    /* Then shift 64 bits from here */
+    in1 = _mm_clmulepi64_si128 (shift96_shift64, in2, 0x01);
+    in1 = _mm_xor_si128 (in1, in3);
+
+    /* This is the Barrett reduction */
+    /* Take the bottom 32 bits */
+    in2 = _mm_and_si128 (in1, _mm_set_epi64x (0, 0xffffffff));
+    /* Multiply by mu */
+    in2 = _mm_clmulepi64_si128 (mu_poly, in2, 0x00);
+    /* Take the bottom 32 bits of the result */
+    in2 = _mm_and_si128 (in2, _mm_set_epi64x (0, 0xffffffff));
+    /* Multiply by P(x) */
+    in2 = _mm_clmulepi64_si128 (mu_poly, in2, 0x01);
+    /* XOR against input */
+    in1 = _mm_xor_si128 (in1, in2);
+    /* Take bits 32-63 as the CRC */
+    in1 = _mm_srli_si128 (in1, 4);
+  }
+  uint32_t final_crc = _mm_cvtsi128_si32 (in1);
+
+  return final_crc;
 }
index 9551a3db82ef48afd2affc02d95e802e24651ce9..5679b0367e7021fbe63d81e38ce2da4493944a1b 100644 (file)
--- a/lib/crc.c
+++ b/lib/crc.c
@@ -31,7 +31,7 @@ static bool pclmul_checked = false;
 #include <string.h>
 
 #if GL_CRC_SLICE_BY_8
-#include "crc-sliceby8.h"
+# include "crc-sliceby8.h"
 
 /*
  * When we calculate the CRC32 byte-by-byte we take the checksum
@@ -76,16 +76,17 @@ crc32_update_no_xor_slice_by_8 (uint32_t crc, const char *buf)
   uint64_t local_buf;
   memcpy (&local_buf, buf, 8);
   local_buf = le64toh (local_buf) ^ crc;
-  crc = crc32_sliceby8_table[0][(local_buf >> 56) & 0xFF]
-        ^ crc32_sliceby8_table[1][(local_buf >> 48) & 0xFF]
-        ^ crc32_sliceby8_table[2][(local_buf >> 40) & 0xFF]
-        ^ crc32_sliceby8_table[3][(local_buf >> 32) & 0xFF]
-        ^ crc32_sliceby8_table[4][(local_buf >> 24) & 0xFF]
-        ^ crc32_sliceby8_table[5][(local_buf >> 16) & 0xFF]
-        ^ crc32_sliceby8_table[6][(local_buf >> 8) & 0xFF]
-        ^ crc32_sliceby8_table[7][local_buf & 0xFF];
 
-  return crc;
+  uint32_t final_crc = crc32_sliceby8_table[0][(local_buf >> 56) & 0xFF]
+                       ^ crc32_sliceby8_table[1][(local_buf >> 48) & 0xFF]
+                       ^ crc32_sliceby8_table[2][(local_buf >> 40) & 0xFF]
+                       ^ crc32_sliceby8_table[3][(local_buf >> 32) & 0xFF]
+                       ^ crc32_sliceby8_table[4][(local_buf >> 24) & 0xFF]
+                       ^ crc32_sliceby8_table[5][(local_buf >> 16) & 0xFF]
+                       ^ crc32_sliceby8_table[6][(local_buf >> 8) & 0xFF]
+                       ^ crc32_sliceby8_table[7][local_buf & 0xFF];
+
+  return final_crc;
 }
 
 static uint32_t
@@ -93,8 +94,6 @@ crc32_update_no_xor_slice_by_n (uint32_t crc, const char *buf,
                                 size_t num_bytes)
 {
   uint64_t local_buf;
-  size_t shift_amount;
-
   memcpy (&local_buf, buf, num_bytes);
   local_buf = le64toh (local_buf) ^ crc;
 
@@ -105,7 +104,7 @@ crc32_update_no_xor_slice_by_n (uint32_t crc, const char *buf,
 
   for (size_t i = 0; i < num_bytes; i++)
     {
-      shift_amount = ((num_bytes - i - 1) * 8);
+      size_t shift_amount = ((num_bytes - i - 1) * 8);
       crc = crc ^ crc32_sliceby8_table[i][(local_buf >> shift_amount) & 0xFF];
     }
 
@@ -115,8 +114,7 @@ crc32_update_no_xor_slice_by_n (uint32_t crc, const char *buf,
 uint32_t
 crc32_update_no_xor (uint32_t crc, const char *buf, size_t len)
 {
-  size_t n, slice_alignment;
-#ifdef GL_CRC_X86_64_PCLMUL
+# ifdef GL_CRC_X86_64_PCLMUL
   if (!pclmul_checked)
     {
       pclmul_enabled = (cpu_supports ("pclmul")
@@ -126,10 +124,11 @@ crc32_update_no_xor (uint32_t crc, const char *buf, size_t len)
 
   if (pclmul_enabled && len >= 16)
     return crc32_update_no_xor_pclmul (crc, buf, len);
-#endif
+# endif
 
-  slice_alignment = (len & (-8));
+  size_t slice_alignment = (len & (-8));
 
+  size_t n;
   for (n = 0; n < slice_alignment; n += 8)
     crc = crc32_update_no_xor_slice_by_8 (crc, buf + n);
 
@@ -138,6 +137,7 @@ crc32_update_no_xor (uint32_t crc, const char *buf, size_t len)
 
   return crc;
 }
+
 #else
 
 /* Table of CRCs of all 8-bit messages.  Generated by running code
@@ -196,7 +196,7 @@ static const uint32_t crc32_table[256] = {
 uint32_t
 crc32_update_no_xor (uint32_t crc, const char *buf, size_t len)
 {
-#ifdef GL_CRC_X86_64_PCLMUL
+# ifdef GL_CRC_X86_64_PCLMUL
   if (!pclmul_checked)
     {
       pclmul_enabled = (cpu_supports ("pclmul")
@@ -206,7 +206,7 @@ crc32_update_no_xor (uint32_t crc, const char *buf, size_t len)
 
   if (pclmul_enabled && len >= 16)
     return crc32_update_no_xor_pclmul (crc, buf, len);
-#endif
+# endif
 
   for (size_t n = 0; n < len; n++)
     crc = crc32_table[(crc ^ buf[n]) & 0xff] ^ (crc >> 8);
index 39954b72bb25d7a9b1851a4782d63ea6783fe0e3..8435b40f9546ccd1888d6a574838c861652a890e 100644 (file)
@@ -100,15 +100,13 @@ compile_csharp_using_mono (const char * const *sources,
          and (to exclude an unrelated 'mcs' program on QNX 6)
          "mcs --version 2>/dev/null | grep Mono >/dev/null"  */
       const char *argv[3];
-      pid_t child;
-      int fd[1];
-      int exitstatus;
-
       argv[0] = "mcs";
       argv[1] = "--version";
       argv[2] = NULL;
-      child = create_pipe_in ("mcs", "mcs", argv, NULL, NULL,
-                              DEV_NULL, true, true, false, fd);
+
+      int fd[1];
+      pid_t child = create_pipe_in ("mcs", "mcs", argv, NULL, NULL,
+                                    DEV_NULL, true, true, false, fd);
       mcs_present = false;
       if (child != -1)
         {
@@ -133,7 +131,7 @@ compile_csharp_using_mono (const char * const *sources,
 
           /* Remove zombie process from process list, and retrieve exit
              status.  */
-          exitstatus =
+          int exitstatus =
             wait_subprocess (child, "mcs", false, true, true, false, NULL);
           if (exitstatus != 0)
             mcs_present = false;
@@ -143,70 +141,60 @@ compile_csharp_using_mono (const char * const *sources,
 
   if (mcs_present)
     {
-      unsigned int argc;
-      const char **argv;
-      const char **argp;
-      pid_t child;
-      int fd[1];
-      FILE *fp;
-      char *line[2];
-      size_t linesize[2];
-      size_t linelen[2];
-      unsigned int l;
-      int exitstatus;
-
-      argc =
+      unsigned int argc =
         1 + (output_is_library ? 1 : 0) + 1 + libdirs_count + libraries_count
         + (debug ? 1 : 0) + sources_count;
-      argv = (const char **) xmalloca ((argc + 1) * sizeof (const char *));
-
-      argp = argv;
-      *argp++ = "mcs";
-      if (output_is_library)
-        *argp++ = "-target:library";
+      const char **argv =
+        (const char **) xmalloca ((argc + 1) * sizeof (const char *));
       {
-        char *option = (char *) xmalloca (5 + strlen (output_file) + 1);
-        memcpy (option, "-out:", 5);
-        strcpy (option + 5, output_file);
-        *argp++ = option;
-      }
-      for (unsigned int i = 0; i < libdirs_count; i++)
+        const char **argp = argv;
+        *argp++ = "mcs";
+        if (output_is_library)
+          *argp++ = "-target:library";
         {
-          char *option = (char *) xmalloca (5 + strlen (libdirs[i]) + 1);
-          memcpy (option, "-lib:", 5);
-          strcpy (option + 5, libdirs[i]);
+          char *option = (char *) xmalloca (5 + strlen (output_file) + 1);
+          memcpy (option, "-out:", 5);
+          strcpy (option + 5, output_file);
           *argp++ = option;
         }
-      for (unsigned int i = 0; i < libraries_count; i++)
-        {
-          char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
-          memcpy (option, "-reference:", 11);
-          memcpy (option + 11, libraries[i], strlen (libraries[i]));
-          strcpy (option + 11 + strlen (libraries[i]), ".dll");
-          *argp++ = option;
-        }
-      if (debug)
-        *argp++ = "-debug";
-      for (unsigned int i = 0; i < sources_count; i++)
-        {
-          const char *source_file = sources[i];
-          if (strlen (source_file) >= 10
-              && memeq (source_file + strlen (source_file) - 10,
-                        ".resources", 10))
-            {
-              char *option = (char *) xmalloca (10 + strlen (source_file) + 1);
+        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 (unsigned int i = 0; i < libraries_count; i++)
+          {
+            char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
+            memcpy (option, "-reference:", 11);
+            memcpy (option + 11, libraries[i], strlen (libraries[i]));
+            strcpy (option + 11 + strlen (libraries[i]), ".dll");
+            *argp++ = option;
+          }
+        if (debug)
+          *argp++ = "-debug";
+        for (unsigned int i = 0; i < sources_count; i++)
+          {
+            const char *source_file = sources[i];
+            if (strlen (source_file) >= 10
+                && memeq (source_file + strlen (source_file) - 10,
+                          ".resources", 10))
+              {
+                char *option = (char *) xmalloca (10 + strlen (source_file) + 1);
 
-              memcpy (option, "-resource:", 10);
-              strcpy (option + 10, source_file);
-              *argp++ = option;
-            }
-          else
-            *argp++ = source_file;
-        }
-      *argp = NULL;
-      /* Ensure argv length was correctly calculated.  */
-      if (argp - argv != argc)
-        abort ();
+                memcpy (option, "-resource:", 10);
+                strcpy (option + 10, source_file);
+                *argp++ = option;
+              }
+            else
+              *argp++ = source_file;
+          }
+        *argp = NULL;
+        /* Ensure argv length was correctly calculated.  */
+        if (argp - argv != argc)
+          abort ();
+      }
 
       if (verbose)
         {
@@ -215,17 +203,21 @@ compile_csharp_using_mono (const char * const *sources,
           free (command);
         }
 
-      child = create_pipe_in ("mcs", "mcs", argv, NULL, NULL,
-                              NULL, false, true, true, fd);
+      int fd[1];
+      pid_t child = create_pipe_in ("mcs", "mcs", argv, NULL, NULL,
+                                    NULL, false, true, true, fd);
 
       /* Read the subprocess output, copying it to stderr.  Drop the last
          line if it starts with "Compilation succeeded".  */
-      fp = fdopen (fd[0], "r");
+      FILE *fp = fdopen (fd[0], "r");
       if (fp == NULL)
         error (EXIT_FAILURE, errno, _("fdopen() failed"));
+      char *line[2];
+      size_t linesize[2];
       line[0] = NULL; linesize[0] = 0;
       line[1] = NULL; linesize[1] = 0;
-      l = 0;
+      unsigned int l = 0;
+      size_t linelen[2];
       for (;;)
         {
           linelen[l] = getline (&line[l], &linesize[l], fp);
@@ -247,7 +239,7 @@ compile_csharp_using_mono (const char * const *sources,
       fclose (fp);
 
       /* Remove zombie process from process list, and retrieve exit status.  */
-      exitstatus =
+      int exitstatus =
         wait_subprocess (child, "mcs", false, false, true, true, NULL);
 
       for (unsigned int i = 1 + (output_is_library ? 1 : 0);
@@ -285,28 +277,26 @@ compile_csharp_using_dotnet (const char * const *sources,
       /* Test for presence of dotnet:
          dotnet --list-runtimes >/dev/null 2>/dev/null
          && test -n "`dotnet --list-sdks 2>/dev/null`"  */
-      int exitstatus;
+      int exitstatus1;
       {
         const char *argv[3];
-
         argv[0] = "dotnet";
         argv[1] = "--list-runtimes";
         argv[2] = NULL;
-        exitstatus = execute ("dotnet", "dotnet", argv, NULL, NULL,
-                              false, false, true, true,
-                              true, false, NULL);
+        exitstatus1 = execute ("dotnet", "dotnet", argv, NULL, NULL,
+                               false, false, true, true,
+                               true, false, NULL);
       }
-      if (exitstatus == 0)
+      if (exitstatus1 == 0)
         {
           const char *argv[3];
-          pid_t child;
-          int fd[1];
-
           argv[0] = "dotnet";
           argv[1] = "--list-sdks";
           argv[2] = NULL;
-          child = create_pipe_in ("dotnet", "dotnet", argv, NULL, NULL,
-                                  DEV_NULL, true, true, false, fd);
+
+          int fd[1];
+          pid_t child = create_pipe_in ("dotnet", "dotnet", argv, NULL, NULL,
+                                        DEV_NULL, true, true, false, fd);
           if (child != -1)
             {
               /* Read the subprocess output, and test whether it is
@@ -327,7 +317,7 @@ compile_csharp_using_dotnet (const char * const *sources,
 
               /* Remove zombie process from process list, and retrieve exit
                  status.  */
-              exitstatus =
+              int exitstatus =
                 wait_subprocess (child, "dotnet", false, true, true, false,
                                  NULL);
               dotnet_present = (exitstatus == 0 && count > 0);
@@ -344,11 +334,9 @@ compile_csharp_using_dotnet (const char * const *sources,
     {
       bool err = false;
 
-      char *dotnet_runtime_dir;
-      char *dotnet_sdk_dir;
-
       /* Invoke 'dotnet --list-runtimes' and extract the .NET runtime dir
          from its output.  */
+      char *dotnet_runtime_dir;
       {
         dotnet_runtime_dir = NULL;
 
@@ -441,6 +429,7 @@ compile_csharp_using_dotnet (const char * const *sources,
 
       /* Invoke 'dotnet --list-sdks' and extract the .NET SDK dir
          from its output.  */
+      char *dotnet_sdk_dir;
       {
         dotnet_sdk_dir = NULL;
 
@@ -529,21 +518,9 @@ compile_csharp_using_dotnet (const char * const *sources,
       if (err)
         return 1;
 
-      struct dirent **dlls;
-      int num_dlls;
-      char *roslyn_dir;
-      char *roslyn_bin_dir;
-      char *csc;
-      char *csc_converted;
-      char **malloced;
-      char **mallocedp;
-      unsigned int argc;
-      const char **argv;
-      const char **argp;
-      int exitstatus;
-
       /* Get a list of all *.dll files in dotnet_runtime_dir.  */
-      num_dlls = scandir (dotnet_runtime_dir, &dlls, name_is_dll, alphasort);
+      struct dirent **dlls;
+      int num_dlls = scandir (dotnet_runtime_dir, &dlls, name_is_dll, alphasort);
       if (num_dlls < 0 && errno == ENOMEM)
         xalloc_die ();
       if (num_dlls <= 0)
@@ -553,100 +530,102 @@ compile_csharp_using_dotnet (const char * const *sources,
         }
 
       /* Construct the file name of the 'csc' compiler.  */
-      roslyn_dir = xconcatenated_filename (dotnet_sdk_dir, "Roslyn", NULL);
-      roslyn_bin_dir = xconcatenated_filename (roslyn_dir, "bincore", NULL);
-      csc = xconcatenated_filename (roslyn_bin_dir, "csc.dll", NULL);
-      csc_converted = cygpath_w (csc);
+      char *roslyn_dir = xconcatenated_filename (dotnet_sdk_dir, "Roslyn", NULL);
+      char *roslyn_bin_dir = xconcatenated_filename (roslyn_dir, "bincore", NULL);
+      char *csc = xconcatenated_filename (roslyn_bin_dir, "csc.dll", NULL);
+      char *csc_converted = cygpath_w (csc);
 
       /* Here, we assume that 'csc' is a native Windows program, therefore
          we need to use cygpath_w.  */
-      malloced =
+      char **malloced =
         (char **)
         xmalloca ((1 + libdirs_count + sources_count * 2 + 1) * sizeof (char *));
-      mallocedp = malloced;
+      char **mallocedp = malloced;
 
-      argc =
+      unsigned int argc =
         3 + 1 + 1 + libdirs_count + libraries_count
         + (optimize ? 1 : 0) + (debug ? 1 : 0) + sources_count + 1 + num_dlls;
-      argv = (const char **) xmalloca ((argc + 1) * sizeof (const char *));
-
-      argp = argv;
-      *argp++ = "dotnet";
-      *argp++ = csc_converted;
-      *argp++ = "-nologo";
-      *argp++ = (output_is_library ? "-target:library" : "-target:exe");
+      const char **argv =
+        (const char **) xmalloca ((argc + 1) * sizeof (const char *));
       {
-        char *output_file_converted = cygpath_w (output_file);
-        *mallocedp++ = output_file_converted;
-        char *option = (char *) xmalloca (5 + strlen (output_file_converted) + 1);
-        memcpy (option, "-out:", 5);
-        strcpy (option + 5, output_file_converted);
-        *argp++ = option;
-      }
-      for (unsigned int i = 0; i < libdirs_count; i++)
+        const char **argp = argv;
+        *argp++ = "dotnet";
+        *argp++ = csc_converted;
+        *argp++ = "-nologo";
+        *argp++ = (output_is_library ? "-target:library" : "-target:exe");
         {
-          const char *libdir = libdirs[i];
-          char *libdir_converted = cygpath_w (libdir);
-          *mallocedp++ = libdir_converted;
-          char *option = (char *) xmalloca (5 + strlen (libdir_converted) + 1);
-          memcpy (option, "-lib:", 5);
-          strcpy (option + 5, libdir_converted);
+          char *output_file_converted = cygpath_w (output_file);
+          *mallocedp++ = output_file_converted;
+          char *option = (char *) xmalloca (5 + strlen (output_file_converted) + 1);
+          memcpy (option, "-out:", 5);
+          strcpy (option + 5, output_file_converted);
           *argp++ = option;
         }
-      for (unsigned int i = 0; i < libraries_count; i++)
+        for (unsigned int i = 0; i < libdirs_count; i++)
+          {
+            const char *libdir = libdirs[i];
+            char *libdir_converted = cygpath_w (libdir);
+            *mallocedp++ = libdir_converted;
+            char *option = (char *) xmalloca (5 + strlen (libdir_converted) + 1);
+            memcpy (option, "-lib:", 5);
+            strcpy (option + 5, libdir_converted);
+            *argp++ = option;
+          }
+        for (unsigned int i = 0; i < libraries_count; i++)
+          {
+            char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
+            memcpy (option, "-reference:", 11);
+            memcpy (option + 11, libraries[i], strlen (libraries[i]));
+            strcpy (option + 11 + strlen (libraries[i]), ".dll");
+            *argp++ = option;
+          }
+        if (optimize)
+          *argp++ = "-optimize+";
+        if (debug)
+          *argp++ = "-debug+";
+        for (unsigned int i = 0; i < sources_count; i++)
+          {
+            const char *source_file = sources[i];
+            char *source_file_converted = cygpath_w (source_file);
+            *mallocedp++ = source_file_converted;
+            if (strlen (source_file_converted) >= 10
+                && memeq ((source_file_converted
+                           + strlen (source_file_converted) - 10),
+                          ".resources", 10))
+              {
+                char *option =
+                  (char *) xmalloc (10 + strlen (source_file_converted) + 1);
+                memcpy (option, "-resource:", 10);
+                strcpy (option + 10, source_file_converted);
+                *mallocedp++ = option;
+                *argp++ = option;
+              }
+            else
+              *argp++ = source_file_converted;
+          }
+        /* Add -lib and -reference options, so that the compiler finds
+           Object, Console, String, etc.  */
         {
-          char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
-          memcpy (option, "-reference:", 11);
-          memcpy (option + 11, libraries[i], strlen (libraries[i]));
-          strcpy (option + 11 + strlen (libraries[i]), ".dll");
+          char *dotnet_runtime_dir_converted = cygpath_w (dotnet_runtime_dir);
+          *mallocedp++ = dotnet_runtime_dir_converted;
+          char *option =
+            (char *) xmalloca (5 + strlen (dotnet_runtime_dir_converted) + 1);
+          memcpy (option, "-lib:", 5);
+          strcpy (option + 5, dotnet_runtime_dir_converted);
           *argp++ = option;
         }
-      if (optimize)
-        *argp++ = "-optimize+";
-      if (debug)
-        *argp++ = "-debug+";
-      for (unsigned int i = 0; i < sources_count; i++)
-        {
-          const char *source_file = sources[i];
-          char *source_file_converted = cygpath_w (source_file);
-          *mallocedp++ = source_file_converted;
-          if (strlen (source_file_converted) >= 10
-              && memeq ((source_file_converted
-                         + strlen (source_file_converted) - 10),
-                        ".resources", 10))
-            {
-              char *option =
-                (char *) xmalloc (10 + strlen (source_file_converted) + 1);
-              memcpy (option, "-resource:", 10);
-              strcpy (option + 10, source_file_converted);
-              *mallocedp++ = option;
-              *argp++ = option;
-            }
-          else
-            *argp++ = source_file_converted;
-        }
-      /* Add -lib and -reference options, so that the compiler finds
-         Object, Console, String, etc.  */
-      {
-        char *dotnet_runtime_dir_converted = cygpath_w (dotnet_runtime_dir);
-        *mallocedp++ = dotnet_runtime_dir_converted;
-        char *option =
-          (char *) xmalloca (5 + strlen (dotnet_runtime_dir_converted) + 1);
-        memcpy (option, "-lib:", 5);
-        strcpy (option + 5, dotnet_runtime_dir_converted);
-        *argp++ = option;
+        for (unsigned int i = 0; i < num_dlls; i++)
+          {
+            char *option = (char *) xmalloca (11 + strlen (dlls[i]->d_name) + 1);
+            memcpy (option, "-reference:", 11);
+            strcpy (option + 11, dlls[i]->d_name);
+            *argp++ = option;
+          }
+        *argp = NULL;
+        /* Ensure argv length was correctly calculated.  */
+        if (argp - argv != argc)
+          abort ();
       }
-      for (unsigned int i = 0; i < num_dlls; i++)
-        {
-          char *option = (char *) xmalloca (11 + strlen (dlls[i]->d_name) + 1);
-          memcpy (option, "-reference:", 11);
-          strcpy (option + 11, dlls[i]->d_name);
-          *argp++ = option;
-        }
-      *argp = NULL;
-      /* Ensure argv length was correctly calculated.  */
-      if (argp - argv != argc)
-        abort ();
 
       if (verbose)
         {
@@ -655,9 +634,9 @@ compile_csharp_using_dotnet (const char * const *sources,
           free (command);
         }
 
-      exitstatus = execute ("dotnet", "dotnet", argv, NULL, NULL,
-                            false, false, false, false,
-                            true, true, NULL);
+      int exitstatus = execute ("dotnet", "dotnet", argv, NULL, NULL,
+                                false, false, false, false,
+                                true, true, NULL);
 
       for (unsigned int i = 4; i < 5 + libdirs_count + libraries_count; i++)
         freea ((char *) argv[i]);
@@ -688,15 +667,13 @@ compile_csharp_using_dotnet (const char * const *sources,
              "csc -help 2>/dev/null | grep -i analyzer >/dev/null \
               && ! { csc -help 2>/dev/null | grep -i chicken > /dev/null; }"  */
           const char *argv[3];
-          pid_t child;
-          int fd[1];
-          int exitstatus;
-
           argv[0] = "csc";
           argv[1] = "-help";
           argv[2] = NULL;
-          child = create_pipe_in ("csc", "csc", argv, NULL, NULL,
-                                  DEV_NULL, true, true, false, fd);
+
+          int fd[1];
+          pid_t child = create_pipe_in ("csc", "csc", argv, NULL, NULL,
+                                        DEV_NULL, true, true, false, fd);
           if (child != -1)
             {
               /* Read the subprocess output, and test whether it contains the
@@ -731,7 +708,7 @@ compile_csharp_using_dotnet (const char * const *sources,
 
               /* Remove zombie process from process list, and retrieve exit
                  status.  */
-              exitstatus =
+              int exitstatus =
                 wait_subprocess (child, "csc", false, true, true, false, NULL);
               csc_present = (exitstatus == 0 && seen_analyzer && !seen_chicken);
             }
@@ -742,83 +719,78 @@ compile_csharp_using_dotnet (const char * const *sources,
 
       if (csc_present)
         {
-          char **malloced;
-          char **mallocedp;
-          unsigned int argc;
-          const char **argv;
-          const char **argp;
-          int exitstatus;
-
           /* Here, we assume that 'csc' is a native Windows program, therefore
              we need to use cygpath_w.  */
-          malloced =
+          char **malloced =
             (char **)
             xmalloca ((1 + libdirs_count + sources_count * 2) * sizeof (char *));
-          mallocedp = malloced;
+          char **mallocedp = malloced;
 
-          argc =
+          unsigned int argc =
             2 + 1 + 1 + libdirs_count + libraries_count
             + (optimize ? 1 : 0) + (debug ? 1 : 0) + sources_count;
-          argv = (const char **) xmalloca ((argc + 1) * sizeof (const char *));
-
-          argp = argv;
-          *argp++ = "csc";
-          *argp++ = "-nologo";
-          *argp++ = (output_is_library ? "-target:library" : "-target:exe");
+          const char **argv =
+            (const char **) xmalloca ((argc + 1) * sizeof (const char *));
           {
-            char *output_file_converted = cygpath_w (output_file);
-            *mallocedp++ = output_file_converted;
-            char *option = (char *) xmalloca (5 + strlen (output_file_converted) + 1);
-            memcpy (option, "-out:", 5);
-            strcpy (option + 5, output_file_converted);
-            *argp++ = option;
-          }
-          for (unsigned int i = 0; i < libdirs_count; i++)
+            const char **argp = argv;
+            *argp++ = "csc";
+            *argp++ = "-nologo";
+            *argp++ = (output_is_library ? "-target:library" : "-target:exe");
             {
-              const char *libdir = libdirs[i];
-              char *libdir_converted = cygpath_w (libdir);
-              *mallocedp++ = libdir_converted;
-              char *option = (char *) xmalloca (5 + strlen (libdir_converted) + 1);
-              memcpy (option, "-lib:", 5);
-              strcpy (option + 5, libdir_converted);
+              char *output_file_converted = cygpath_w (output_file);
+              *mallocedp++ = output_file_converted;
+              char *option = (char *) xmalloca (5 + strlen (output_file_converted) + 1);
+              memcpy (option, "-out:", 5);
+               strcpy (option + 5, output_file_converted);
               *argp++ = option;
             }
-          for (unsigned int i = 0; i < libraries_count; i++)
-            {
-              char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
-              memcpy (option, "-reference:", 11);
-              memcpy (option + 11, libraries[i], strlen (libraries[i]));
-              strcpy (option + 11 + strlen (libraries[i]), ".dll");
-              *argp++ = option;
-            }
-          if (optimize)
-            *argp++ = "-optimize+";
-          if (debug)
-            *argp++ = "-debug+";
-          for (unsigned int i = 0; i < sources_count; i++)
-            {
-              const char *source_file = sources[i];
-              char *source_file_converted = cygpath_w (source_file);
-              *mallocedp++ = source_file_converted;
-              if (strlen (source_file_converted) >= 10
-                  && memeq ((source_file_converted
-                             + strlen (source_file_converted) - 10),
-                            ".resources", 10))
-                {
-                  char *option =
-                    (char *) xmalloc (10 + strlen (source_file_converted) + 1);
-                  memcpy (option, "-resource:", 10);
-                  strcpy (option + 10, source_file_converted);
-                  *mallocedp++ = option;
-                  *argp++ = option;
-                }
-              else
-                *argp++ = source_file_converted;
-            }
-          *argp = NULL;
-          /* Ensure argv length was correctly calculated.  */
-          if (argp - argv != argc)
-            abort ();
+            for (unsigned int i = 0; i < libdirs_count; i++)
+              {
+                const char *libdir = libdirs[i];
+                char *libdir_converted = cygpath_w (libdir);
+                *mallocedp++ = libdir_converted;
+                char *option = (char *) xmalloca (5 + strlen (libdir_converted) + 1);
+                memcpy (option, "-lib:", 5);
+                strcpy (option + 5, libdir_converted);
+                *argp++ = option;
+              }
+            for (unsigned int i = 0; i < libraries_count; i++)
+              {
+                char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
+                memcpy (option, "-reference:", 11);
+                memcpy (option + 11, libraries[i], strlen (libraries[i]));
+                strcpy (option + 11 + strlen (libraries[i]), ".dll");
+                *argp++ = option;
+              }
+            if (optimize)
+              *argp++ = "-optimize+";
+            if (debug)
+              *argp++ = "-debug+";
+            for (unsigned int i = 0; i < sources_count; i++)
+              {
+                const char *source_file = sources[i];
+                char *source_file_converted = cygpath_w (source_file);
+                *mallocedp++ = source_file_converted;
+                if (strlen (source_file_converted) >= 10
+                    && memeq ((source_file_converted
+                               + strlen (source_file_converted) - 10),
+                              ".resources", 10))
+                  {
+                    char *option =
+                      (char *) xmalloc (10 + strlen (source_file_converted) + 1);
+                    memcpy (option, "-resource:", 10);
+                    strcpy (option + 10, source_file_converted);
+                    *mallocedp++ = option;
+                    *argp++ = option;
+                  }
+                else
+                  *argp++ = source_file_converted;
+              }
+            *argp = NULL;
+            /* Ensure argv length was correctly calculated.  */
+            if (argp - argv != argc)
+              abort ();
+          }
 
           if (verbose)
             {
@@ -827,9 +799,9 @@ compile_csharp_using_dotnet (const char * const *sources,
               free (command);
             }
 
-          exitstatus = execute ("csc", "csc", argv, NULL, NULL,
-                                false, false, false, false,
-                                true, true, NULL);
+          int exitstatus = execute ("csc", "csc", argv, NULL, NULL,
+                                    false, false, false, false,
+                                    true, true, NULL);
 
           for (unsigned int i = 3; i < 4 + libdirs_count + libraries_count; i++)
             freea ((char *) argv[i]);
@@ -865,15 +837,13 @@ compile_csharp_using_sscli (const char * const *sources,
          "csc -help >/dev/null 2>/dev/null \
           && ! { csc -help 2>/dev/null | grep -i chicken > /dev/null; }"  */
       const char *argv[3];
-      pid_t child;
-      int fd[1];
-      int exitstatus;
-
       argv[0] = "csc";
       argv[1] = "-help";
       argv[2] = NULL;
-      child = create_pipe_in ("csc", "csc", argv, NULL, NULL,
-                              DEV_NULL, true, true, false, fd);
+
+      int fd[1];
+      pid_t child = create_pipe_in ("csc", "csc", argv, NULL, NULL,
+                                    DEV_NULL, true, true, false, fd);
       csc_present = false;
       if (child != -1)
         {
@@ -902,7 +872,7 @@ compile_csharp_using_sscli (const char * const *sources,
 
           /* Remove zombie process from process list, and retrieve exit
              status.  */
-          exitstatus =
+          int exitstatus =
             wait_subprocess (child, "csc", false, true, true, false, NULL);
           if (exitstatus != 0)
             csc_present = false;
@@ -912,83 +882,78 @@ compile_csharp_using_sscli (const char * const *sources,
 
   if (csc_present)
     {
-      char **malloced;
-      char **mallocedp;
-      unsigned int argc;
-      const char **argv;
-      const char **argp;
-      int exitstatus;
-
       /* Here, we assume that 'csc' is a native Windows program, therefore
          we need to use cygpath_w.  */
-      malloced =
+      char **malloced =
         (char **)
         xmalloca ((1 + libdirs_count + sources_count * 2) * sizeof (char *));
-      mallocedp = malloced;
+      char **mallocedp = malloced;
 
-      argc =
+      unsigned int argc =
         2 + 1 + 1 + libdirs_count + libraries_count
         + (optimize ? 1 : 0) + (debug ? 1 : 0) + sources_count;
-      argv = (const char **) xmalloca ((argc + 1) * sizeof (const char *));
-
-      argp = argv;
-      *argp++ = "csc";
-      *argp++ = "-nologo";
-      *argp++ = (output_is_library ? "-target:library" : "-target:exe");
+      const char **argv =
+        (const char **) xmalloca ((argc + 1) * sizeof (const char *));
       {
-        char *output_file_converted = cygpath_w (output_file);
-        *mallocedp++ = output_file_converted;
-        char *option = (char *) xmalloca (5 + strlen (output_file_converted) + 1);
-        memcpy (option, "-out:", 5);
-        strcpy (option + 5, output_file_converted);
-        *argp++ = option;
-      }
-      for (unsigned int i = 0; i < libdirs_count; i++)
+        const char **argp = argv;
+        *argp++ = "csc";
+        *argp++ = "-nologo";
+        *argp++ = (output_is_library ? "-target:library" : "-target:exe");
         {
-          const char *libdir = libdirs[i];
-          char *libdir_converted = cygpath_w (libdir);
-          *mallocedp++ = libdir_converted;
-          char *option = (char *) xmalloca (5 + strlen (libdir_converted) + 1);
-          memcpy (option, "-lib:", 5);
-          strcpy (option + 5, libdir_converted);
-          *argp++ = option;
-        }
-      for (unsigned int i = 0; i < libraries_count; i++)
-        {
-          char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
-          memcpy (option, "-reference:", 11);
-          memcpy (option + 11, libraries[i], strlen (libraries[i]));
-          strcpy (option + 11 + strlen (libraries[i]), ".dll");
+          char *output_file_converted = cygpath_w (output_file);
+          *mallocedp++ = output_file_converted;
+          char *option = (char *) xmalloca (5 + strlen (output_file_converted) + 1);
+          memcpy (option, "-out:", 5);
+          strcpy (option + 5, output_file_converted);
           *argp++ = option;
         }
-      if (optimize)
-        *argp++ = "-optimize+";
-      if (debug)
-        *argp++ = "-debug+";
-      for (unsigned int i = 0; i < sources_count; i++)
-        {
-          const char *source_file = sources[i];
-          char *source_file_converted = cygpath_w (source_file);
-          *mallocedp++ = source_file_converted;
-          if (strlen (source_file_converted) >= 10
-              && memeq ((source_file_converted
-                         + strlen (source_file_converted) - 10),
-                        ".resources", 10))
-            {
-              char *option =
-                (char *) xmalloc (10 + strlen (source_file_converted) + 1);
-              memcpy (option, "-resource:", 10);
-              strcpy (option + 10, source_file_converted);
-              *mallocedp++ = option;
-              *argp++ = option;
-            }
-          else
-            *argp++ = source_file_converted;
-        }
-      *argp = NULL;
-      /* Ensure argv length was correctly calculated.  */
-      if (argp - argv != argc)
-        abort ();
+        for (unsigned int i = 0; i < libdirs_count; i++)
+          {
+            const char *libdir = libdirs[i];
+            char *libdir_converted = cygpath_w (libdir);
+            *mallocedp++ = libdir_converted;
+            char *option = (char *) xmalloca (5 + strlen (libdir_converted) + 1);
+            memcpy (option, "-lib:", 5);
+            strcpy (option + 5, libdir_converted);
+            *argp++ = option;
+          }
+        for (unsigned int i = 0; i < libraries_count; i++)
+          {
+            char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
+            memcpy (option, "-reference:", 11);
+            memcpy (option + 11, libraries[i], strlen (libraries[i]));
+            strcpy (option + 11 + strlen (libraries[i]), ".dll");
+            *argp++ = option;
+          }
+        if (optimize)
+          *argp++ = "-optimize+";
+        if (debug)
+          *argp++ = "-debug+";
+        for (unsigned int i = 0; i < sources_count; i++)
+          {
+            const char *source_file = sources[i];
+            char *source_file_converted = cygpath_w (source_file);
+            *mallocedp++ = source_file_converted;
+            if (strlen (source_file_converted) >= 10
+                && memeq ((source_file_converted
+                           + strlen (source_file_converted) - 10),
+                          ".resources", 10))
+              {
+                char *option =
+                  (char *) xmalloc (10 + strlen (source_file_converted) + 1);
+                memcpy (option, "-resource:", 10);
+                strcpy (option + 10, source_file_converted);
+                *mallocedp++ = option;
+                *argp++ = option;
+              }
+            else
+              *argp++ = source_file_converted;
+          }
+        *argp = NULL;
+        /* Ensure argv length was correctly calculated.  */
+        if (argp - argv != argc)
+          abort ();
+      }
 
       if (verbose)
         {
@@ -997,9 +962,9 @@ compile_csharp_using_sscli (const char * const *sources,
           free (command);
         }
 
-      exitstatus = execute ("csc", "csc", argv, NULL, NULL,
-                            false, false, false, false,
-                            true, true, NULL);
+      int exitstatus = execute ("csc", "csc", argv, NULL, NULL,
+                                false, false, false, false,
+                                true, true, NULL);
 
       for (unsigned int i = 3; i < 4 + libdirs_count + libraries_count; i++)
         freea ((char *) argv[i]);
@@ -1028,6 +993,7 @@ compile_csharp_class (const char * const *sources,
   bool output_is_library =
     (strlen (output_file) >= 4
      && memeq (output_file + strlen (output_file) - 4, ".dll", 4));
+
   int result;
 
   /* First try the C# implementation specified through --enable-csharp.  */
index 26e787c493c2b3d8308cec2f39f5d62cd22311eb..2062671acaebb794c00aa38f54f2d5034f2ac770 100644 (file)
@@ -127,28 +127,23 @@ execute_csharp_using_mono (const char *assembly_path,
       /* Test for presence of mono:
          "mono --version >/dev/null 2>/dev/null"  */
       const char *argv[3];
-      int exitstatus;
-
       argv[0] = "mono";
       argv[1] = "--version";
       argv[2] = NULL;
-      exitstatus = execute ("mono", "mono", argv, NULL, NULL,
-                            false, false, true, true,
-                            true, false, NULL);
+      int exitstatus = execute ("mono", "mono", argv, NULL, NULL,
+                                false, false, true, true,
+                                true, false, NULL);
       mono_present = (exitstatus == 0);
       mono_tested = true;
     }
 
   if (mono_present)
     {
-      char *old_monopath;
-      const char **argv =
-        (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
-      bool err;
-
       /* Set MONO_PATH.  */
-      old_monopath = set_monopath (libdirs, libdirs_count, false, verbose);
+      char *old_monopath = set_monopath (libdirs, libdirs_count, false, verbose);
 
+      const char **argv =
+        (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
       argv[0] = "mono";
       argv[1] = assembly_path;
       for (unsigned int i = 0; i <= nargs; i++)
@@ -161,13 +156,13 @@ execute_csharp_using_mono (const char *assembly_path,
           free (command);
         }
 
-      err = executer ("mono", "mono", argv, private_data);
+      bool err = executer ("mono", "mono", argv, private_data);
+
+      freea (argv);
 
       /* Reset MONO_PATH.  */
       reset_monopath (old_monopath);
 
-      freea (argv);
-
       return err;
     }
   else
@@ -190,24 +185,18 @@ execute_csharp_using_dotnet (const char *assembly_path,
       /* Test for presence of dotnet:
          "dotnet --list-runtimes >/dev/null 2>/dev/null"  */
       const char *argv[3];
-      int exitstatus;
-
       argv[0] = "dotnet";
       argv[1] = "--list-runtimes";
       argv[2] = NULL;
-      exitstatus = execute ("dotnet", "dotnet", argv, NULL, NULL,
-                            false, false, true, true,
-                            true, false, NULL);
+      int exitstatus = execute ("dotnet", "dotnet", argv, NULL, NULL,
+                                false, false, true, true,
+                                true, false, NULL);
       dotnet_present = (exitstatus == 0);
       dotnet_tested = true;
     }
 
   if (dotnet_present)
     {
-      bool err = false;
-
-      char *assembly_path_converted = cygpath_w (assembly_path);
-
       /* Handle the -L options.
          The way this works is that we have to copy (or symlink) the DLLs into
          the directory where FOO.exe resides.
@@ -229,11 +218,9 @@ execute_csharp_using_dotnet (const char *assembly_path,
             {
               const char *libdir = libdirs[l];
 
-              struct dirent **dlls;
-              int num_dlls;
-
               /* Get a list of all *.dll files in libdir.  */
-              num_dlls = scandir (libdir, &dlls, name_is_dll, alphasort);
+              struct dirent **dlls;
+              int num_dlls = scandir (libdir, &dlls, name_is_dll, alphasort);
               if (num_dlls < 0 && errno == ENOMEM)
                 xalloc_die ();
               if (num_dlls <= 0)
@@ -317,6 +304,10 @@ execute_csharp_using_dotnet (const char *assembly_path,
           free (assembly_dir);
         }
 
+      bool err = false;
+
+      char *assembly_path_converted = cygpath_w (assembly_path);
+
       /* Test whether alongside FOO.exe, a file FOO.runtimeconfig.json already
          exists.  */
       char *runtimeconfig_filename =
@@ -337,7 +328,6 @@ execute_csharp_using_dotnet (const char *assembly_path,
         {
           const char **argv =
             (const char **) xmalloca ((3 + nargs + 1) * sizeof (const char *));
-
           argv[0] = "dotnet";
           argv[1] = "exec";
           argv[2] = assembly_path_converted;
@@ -499,10 +489,10 @@ execute_csharp_using_dotnet (const char *assembly_path,
                         {
                           char *runtimeconfig_converted =
                             cygpath_w (runtimeconfig);
+
                           const char **argv =
                             (const char **)
                             xmalloca ((5 + nargs + 1) * sizeof (const char *));
-
                           argv[0] = "dotnet";
                           argv[1] = "exec";
                           argv[2] = "--runtimeconfig";
@@ -563,13 +553,11 @@ execute_csharp_using_sscli (const char *assembly_path,
       /* Test for presence of clix:
          "clix >/dev/null 2>/dev/null ; test $? = 1"  */
       const char *argv[2];
-      int exitstatus;
-
       argv[0] = "clix";
       argv[1] = NULL;
-      exitstatus = execute ("clix", "clix", argv, NULL, NULL,
-                            false, false, true, true,
-                            true, false, NULL);
+      int exitstatus = execute ("clix", "clix", argv, NULL, NULL,
+                                false, false, true, true,
+                                true, false, NULL);
       clix_present = (exitstatus == 0 || exitstatus == 1);
       clix_tested = true;
     }
@@ -579,14 +567,12 @@ execute_csharp_using_sscli (const char *assembly_path,
       /* Here, we assume that 'clix' is a native Windows program, therefore
          we need to use cygpath_w.  */
       char *assembly_path_converted = cygpath_w (assembly_path);
-      char *old_clixpath;
-      const char **argv =
-        (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
-      bool err;
 
       /* Set clix' PATH variable.  */
-      old_clixpath = set_clixpath (libdirs, libdirs_count, false, verbose);
+      char *old_clixpath = set_clixpath (libdirs, libdirs_count, false, verbose);
 
+      const char **argv =
+        (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
       argv[0] = "clix";
       argv[1] = assembly_path_converted;
       for (unsigned int i = 0; i <= nargs; i++)
@@ -599,12 +585,13 @@ execute_csharp_using_sscli (const char *assembly_path,
           free (command);
         }
 
-      err = executer ("clix", "clix", argv, private_data);
+      bool err = executer ("clix", "clix", argv, private_data);
+
+      freea (argv);
 
       /* Reset clix' PATH variable.  */
       reset_clixpath (old_clixpath);
 
-      freea (argv);
       free (assembly_path_converted);
 
       return err;
@@ -621,10 +608,8 @@ execute_csharp_program (const char *assembly_path,
                         bool verbose, bool quiet,
                         execute_fn *executer, void *private_data)
 {
-  unsigned int nargs;
-  int result;
-
   /* Count args.  */
+  unsigned int nargs;
   {
     const char * const *arg;
 
@@ -632,6 +617,8 @@ execute_csharp_program (const char *assembly_path,
      ;
   }
 
+  int result;
+
   /* First try the C# implementation specified through --enable-csharp.  */
 #if CSHARP_CHOICE_MONO
   result = execute_csharp_using_mono (assembly_path, libdirs, libdirs_count,
index 5969018c43678a931f866c3d1461f73232948b67..a1d089814dce6f3cf4b0c9906f5e577d42c14d66 100644 (file)
@@ -82,27 +82,22 @@ static char *
 execute_and_read_line (const char *progname,
                        const char *prog_path, const char * const *prog_argv)
 {
-  pid_t child;
-  int fd[1];
-  FILE *fp;
-  char *line;
-  size_t linesize;
-  size_t linelen;
-
   /* Open a pipe to the program.  */
-  child = create_pipe_in (progname, prog_path, prog_argv, NULL, NULL,
-                          DEV_NULL, false, true, false, fd);
+  int fd[1];
+  pid_t child = create_pipe_in (progname, prog_path, prog_argv, NULL, NULL,
+                                DEV_NULL, false, true, false, fd);
 
   if (child == -1)
     return NULL;
 
   /* Retrieve its result.  */
-  fp = fdopen (fd[0], "r");
+  FILE *fp = fdopen (fd[0], "r");
   if (fp == NULL)
     error (EXIT_FAILURE, errno, _("fdopen() failed"));
 
-  line = NULL; linesize = 0;
-  linelen = getline (&line, &linesize, fp);
+  char *line = NULL;
+  size_t linesize = 0;
+  size_t linelen = getline (&line, &linesize, fp);
   if (linelen == (size_t)(-1))
     {
       error (0, 0, _("%s subprocess I/O error"), progname);
@@ -111,8 +106,6 @@ execute_and_read_line (const char *progname,
     }
   else
     {
-      int exitstatus;
-
       if (linelen > 0 && line[linelen - 1] == '\n')
         line[linelen - 1] = '\0';
 
@@ -123,7 +116,7 @@ execute_and_read_line (const char *progname,
       fclose (fp);
 
       /* Remove zombie process from process list, and retrieve exit status.  */
-      exitstatus =
+      int exitstatus =
         wait_subprocess (child, progname, true, false, true, false, NULL);
       if (exitstatus == 0)
         return line;
@@ -136,7 +129,6 @@ char *
 cygpath_w (const char *filename)
 {
   const char *argv[4];
-
   argv[0] = "cygpath";
   argv[1] = "-w";
   argv[2] = filename;
index 90d80628ca99ba95c935b3d6b4bdc17a791900e3..cd710234013b9336ad4852568cad3f043104ada8 100644 (file)
--- a/lib/des.c
+++ b/lib/des.c
@@ -320,20 +320,20 @@ bool
 gl_des_is_weak_key (const char * key)
 {
   char work[8];
-  int left, right, middle, cmp_result;
 
   /* clear parity bits */
   for (int i = 0; i < 8; ++i)
     work[i] = ((unsigned char)key[i]) & 0xfe;
 
   /* binary search in the weak key table */
-  left = 0;
-  right = 63;
+  int left = 0;
+  int right = 63;
   while (left <= right)
     {
-      middle = (left + right) / 2;
+      int middle = (left + right) / 2;
 
-      if (!(cmp_result = memcmp (work, weak_keys[middle], 8)))
+      int cmp_result = memcmp (work, weak_keys[middle], 8);
+      if (!cmp_result)
         return -1;
 
       if (cmp_result > 0)
@@ -616,10 +616,8 @@ gl_3des_ecb_crypt (gl_3des_ctx *ctx,
 {
   const unsigned char *from = (const unsigned char *) _from;
   unsigned char *to = (unsigned char *) _to;
+  uint32_t *keys = mode ? ctx->decrypt_subkeys : ctx->encrypt_subkeys;
   uint32_t left, right, work;
-  uint32_t *keys;
-
-  keys = mode ? ctx->decrypt_subkeys : ctx->encrypt_subkeys;
 
   READ_64BIT_DATA (from, left, right)
     INITIAL_PERMUTATION (left, work, right)
index 11309ab36bcc1b924399d6081ae7e2aac228782b..f606de734e4514c469a5d59fad4d99858a0db871 100644 (file)
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -1995,18 +1995,20 @@ closure (struct dfa *dfa)
           addtok (dfa, PLUS);
         if (dfa->lex.minrep == 0)
           addtok (dfa, QMARK);
-        int i;
-        for (i = 1; i < dfa->lex.minrep; i++)
-          {
-            copytoks (dfa, tindex, ntokens);
-            addtok (dfa, CAT);
-          }
-        for (; i < dfa->lex.maxrep; i++)
-          {
-            copytoks (dfa, tindex, ntokens);
-            addtok (dfa, QMARK);
-            addtok (dfa, CAT);
-          }
+        {
+          int i;
+          for (i = 1; i < dfa->lex.minrep; i++)
+            {
+              copytoks (dfa, tindex, ntokens);
+              addtok (dfa, CAT);
+            }
+          for (; i < dfa->lex.maxrep; i++)
+            {
+              copytoks (dfa, tindex, ntokens);
+              addtok (dfa, QMARK);
+              addtok (dfa, CAT);
+            }
+        }
         dfa->parse.tok = lex (dfa);
       }
     else if (dfa->parse.tok == REPMN)
@@ -4192,12 +4194,11 @@ dfamust (struct dfa const *d)
 
         case OR:
           {
-            char **new;
             must *rmp = mp;
             assume_nonnull (rmp);
             must *lmp = mp = mp->prev;
             assume_nonnull (lmp);
-            idx_t j, ln, rn, n;
+            idx_t ln, rn, n;
 
             /* Guaranteed to be.  Unlikely, but ...  */
             if (streq (lmp->is, rmp->is))
@@ -4212,23 +4213,28 @@ dfamust (struct dfa const *d)
                 lmp->endline = false;
               }
             /* Left side--easy */
-            idx_t i = 0;
-            while (lmp->left[i] != '\0' && lmp->left[i] == rmp->left[i])
-              ++i;
-            lmp->left[i] = '\0';
+            {
+              idx_t i = 0;
+              while (lmp->left[i] != '\0' && lmp->left[i] == rmp->left[i])
+                ++i;
+              lmp->left[i] = '\0';
+            }
             /* Right side */
             ln = strlen (lmp->right);
             rn = strlen (rmp->right);
             n = ln;
             if (n > rn)
               n = rn;
-            for (i = 0; i < n; ++i)
-              if (lmp->right[ln - i - 1] != rmp->right[rn - i - 1])
-                break;
-            for (j = 0; j < i; ++j)
-              lmp->right[j] = lmp->right[(ln - i) + j];
-            lmp->right[j] = '\0';
-            new = inboth (lmp->in, rmp->in);
+            {
+              idx_t i, j;
+              for (i = 0; i < n; ++i)
+                if (lmp->right[ln - i - 1] != rmp->right[rn - i - 1])
+                  break;
+              for (j = 0; j < i; ++j)
+                lmp->right[j] = lmp->right[(ln - i) + j];
+              lmp->right[j] = '\0';
+            }
+            char **new = inboth (lmp->in, rmp->in);
             freelist (lmp->in);
             free (lmp->in);
             lmp->in = new;
index 5ef5269edc2861ac083cdf8c7555c62ccdb3fe70..767cbe17ffa4b55e6fa4d82409192aa32b9dc866 100644 (file)
@@ -155,7 +155,6 @@ static struct hash_table *
 map_device (struct di_set *dis, dev_t dev)
 {
   /* Find space for the probe, reusing the cache if available.  */
-  struct di_ent *ent;
   struct di_ent *probe = dis->probe;
   if (probe)
     {
@@ -172,7 +171,7 @@ map_device (struct di_set *dis, dev_t dev)
 
   /* Probe for the device.  */
   probe->dev = dev;
-  ent = hash_insert (dis->dev_map, probe);
+  struct di_ent *ent = hash_insert (dis->dev_map, probe);
   if (! ent)
     return NULL;
 
@@ -221,15 +220,13 @@ map_inode_number (struct di_set *dis, ino_t ino)
 int
 di_set_insert (struct di_set *dis, dev_t dev, ino_t ino)
 {
-  hashint i;
-
   /* Map the device number to a set of inodes.  */
   struct hash_table *ino_set = map_device (dis, dev);
   if (! ino_set)
     return -1;
 
   /* Map the inode number to a small representative I.  */
-  i = map_inode_number (dis, ino);
+  hashint i = map_inode_number (dis, ino);
   if (i == INO_MAP_INSERT_FAILURE)
     return -1;
 
@@ -243,15 +240,13 @@ di_set_insert (struct di_set *dis, dev_t dev, ino_t ino)
 int
 di_set_lookup (struct di_set *dis, dev_t dev, ino_t ino)
 {
-  hashint i;
-
   /* Map the device number to a set of inodes.  */
   struct hash_table *ino_set = map_device (dis, dev);
   if (! ino_set)
     return -1;
 
   /* Map the inode number to a small representative I.  */
-  i = map_inode_number (dis, ino);
+  hashint i = map_inode_number (dis, ino);
   if (i == INO_MAP_INSERT_FAILURE)
     return -1;
 
index 9e0ec565ef8156a859d24e143c62244bd8b75275..2e7529997cb1a9039201d5c9b48bdadc9c9e077a 100644 (file)
@@ -32,7 +32,6 @@ size_t
 dir_len (char const *file)
 {
   size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file);
-  size_t length;
 
   /* Advance prefix_length beyond important leading slashes.  */
   prefix_length += (prefix_length != 0
@@ -45,8 +44,10 @@ dir_len (char const *file)
                        : 0));
 
   /* Strip the basename and any redundant slashes before it.  */
+  size_t length;
   for (length = last_component (file) - file;
-       prefix_length < length; length--)
+       prefix_length < length;
+       length--)
     if (! ISSLASH (file[length - 1]))
       break;
   return length;
index b1a310c49944b0feefe637fc8dacb226107dfd19..4d9ac2991e022fda7473906253dde9485af58826 100644 (file)
@@ -31,10 +31,8 @@ int
 dprintf (int fd, const char *format, ...)
 {
   va_list args;
-  off64_t ret;
-
   va_start (args, format);
-  ret = vdzprintf (fd, format, args);
+  off64_t ret = vdzprintf (fd, format, args);
   va_end (args);
 
   if (TYPE_MAXIMUM (off64_t) > INT_MAX && ret > INT_MAX)
index a2bfa2680b585512229243d77990227de2c66e2a..2b435f43895e5107f53b0b7de4acd0c36a712988 100644 (file)
--- a/lib/dup.c
+++ b/lib/dup.c
@@ -61,17 +61,19 @@ static int
 dup_nothrow (int fd)
 {
   int dupfd;
-  struct stat sbuf;
 
   dupfd = dup (fd);
-  if (dupfd == -1 && errno == ENOTSUP \
-      && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode))
+  if (dupfd == -1 && errno == ENOTSUP)
     {
-      char path[_MAX_PATH];
-
-      /* Get a path from fd */
-      if (!__libc_Back_ioFHToPath (fd, path, sizeof (path)))
-        dupfd = open (path, O_RDONLY);
+      struct stat sbuf;
+      if (!fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode))
+        {
+          char path[_MAX_PATH];
+
+          /* Get a path from fd */
+          if (!__libc_Back_ioFHToPath (fd, path, sizeof (path)))
+            dupfd = open (path, O_RDONLY);
+        }
     }
 
   return dupfd;
index 434e78c2bc67a00b2d09935244b9eefbf7886ac2..65a43087c02cc70274915c60898b21126a496a85 100644 (file)
@@ -70,8 +70,6 @@ dup2_nothrow (int fd, int desired_fd)
 static int
 ms_windows_dup2 (int fd, int desired_fd)
 {
-  int result;
-
   /* If fd is closed, mingw hangs on dup2 (fd, fd).  If fd is open,
      dup2 (fd, fd) returns 0, but all further attempts to use fd in
      future dup2 calls will hang.  */
@@ -93,7 +91,7 @@ ms_windows_dup2 (int fd, int desired_fd)
       return -1;
     }
 
-  result = dup2_nothrow (fd, desired_fd);
+  int result = dup2_nothrow (fd, desired_fd);
 
   if (result == 0)
     result = desired_fd;
@@ -110,10 +108,7 @@ ms_windows_dup2 (int fd, int desired_fd)
 static int
 klibc_dup2dirfd (int fd, int desired_fd)
 {
-  int tempfd;
-  int dupfd;
-
-  tempfd = open ("NUL", O_RDONLY);
+  int tempfd = open ("NUL", O_RDONLY);
   if (tempfd < 0)
     return tempfd;
 
@@ -129,7 +124,7 @@ klibc_dup2dirfd (int fd, int desired_fd)
         {
           close (desired_fd);
 
-          dupfd = open (path, O_RDONLY);
+          int dupfd = open (path, O_RDONLY);
           if (dupfd < 0)
             return dupfd;
 
@@ -150,7 +145,7 @@ klibc_dup2dirfd (int fd, int desired_fd)
         }
     }
 
-  dupfd = klibc_dup2dirfd (fd, desired_fd);
+  int dupfd = klibc_dup2dirfd (fd, desired_fd);
 
   close (tempfd);
 
@@ -160,13 +155,17 @@ klibc_dup2dirfd (int fd, int desired_fd)
 static int
 klibc_dup2 (int fd, int desired_fd)
 {
-  int dupfd;
-  struct stat sbuf;
+  int dupfd = dup2 (fd, desired_fd);
+  if (dupfd < 0 && errno == ENOTSUP)
+    {
+      struct stat sbuf;
+      if (!fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode))
+        {
+          close (desired_fd);
 
-  dupfd = dup2 (fd, desired_fd);
-  if (dupfd < 0 && errno == ENOTSUP \
-      && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode))
-    return klibc_dup2dirfd (fd, desired_fd);
+          return klibc_dup2dirfd (fd, desired_fd);
+        }
+    }
 
   return dupfd;
 }
@@ -177,8 +176,6 @@ klibc_dup2 (int fd, int desired_fd)
 int
 rpl_dup2 (int fd, int desired_fd)
 {
-  int result;
-
 #ifdef F_GETFL
   /* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF.
      On Cygwin 1.5.x, dup2 (1, 1) returns 0.
@@ -194,7 +191,7 @@ rpl_dup2 (int fd, int desired_fd)
     return fcntl (fd, F_GETFL) == -1 ? -1 : fd;
 #endif
 
-  result = dup2 (fd, desired_fd);
+  int result = dup2 (fd, desired_fd);
 
   /* Correct an errno value on FreeBSD 6.1 and Cygwin 1.5.x.  */
   if (result < 0 && errno == EMFILE)
index 2d5d51a7699eef451a97929ed025a32789275027..0c11e885f8541d4575152291e299f05082ca5d01 100644 (file)
@@ -90,9 +90,8 @@ dup3 (int oldfd, int newfd, int flags)
 
   if (flags & O_CLOEXEC)
     {
-      int result;
       close (newfd);
-      result = fcntl (oldfd, F_DUPFD_CLOEXEC, newfd);
+      int result = fcntl (oldfd, F_DUPFD_CLOEXEC, newfd);
       if (newfd < result)
         {
           close (result);
index ad93ae9834dc72a64cb561867517ddf844f73e44..190c218da3010872db7dd9ed6373434be675e76a 100644 (file)
@@ -69,16 +69,16 @@ duplocale (locale_t locale)
 #endif
         };
       char base_name[SETLOCALE_NULL_MAX];
-      int err;
-      locale_t base_copy;
 
-      err = setlocale_null_r (LC_CTYPE, base_name, sizeof (base_name));
-      if (err)
-        {
-          errno = err;
-          return NULL;
-        }
-      base_copy = newlocale (LC_ALL_MASK, base_name, NULL);
+      {
+        int err = setlocale_null_r (LC_CTYPE, base_name, sizeof (base_name));
+        if (err)
+          {
+            errno = err;
+            return NULL;
+          }
+      }
+      locale_t base_copy = newlocale (LC_ALL_MASK, base_name, NULL);
       if (base_copy == NULL)
         return NULL;
 
@@ -88,12 +88,14 @@ duplocale (locale_t locale)
           int category_mask = categories[i].mask;
           char name[SETLOCALE_NULL_MAX];
 
-          err = setlocale_null_r (category, name, sizeof (name));
-          if (err)
-            {
-              errno = err;
-              return NULL;
-            }
+          {
+            int err = setlocale_null_r (category, name, sizeof (name));
+            if (err)
+              {
+                errno = err;
+                return NULL;
+              }
+          }
           if (!streq (name, base_name))
             {
               locale_t copy = newlocale (category_mask, name, base_copy);
@@ -122,11 +124,10 @@ duplocale (locale_t locale)
       return NULL;
     }
 
-  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);
+      int err;
 
       result->category[i].name = strdup (locale->category[i].name);
       if (result->category[i].name == NULL)
@@ -158,26 +159,30 @@ duplocale (locale_t locale)
             }
         }
 # 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);
+            }
+          free (result);
+          errno = err;
+          return NULL;
+        }
     }
 
   /* Success.  */
   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);
-    }
-  free (result);
-  errno = err;
-  return NULL;
 
 #else
 
index ba9937ead58c728980556a8c424901fc5b20f608..f3c03ab1717f0034bd63044cd887fa28baf96040 100644 (file)
@@ -33,14 +33,13 @@ off64_t
 dzprintf (int fd, const char *format, ...)
 {
   va_list args;
+  va_start (args, format);
+
   char buf[2000];
-  char *output;
-  size_t len;
   size_t lenbuf = sizeof (buf);
+  char *output = vasnprintf (buf, &lenbuf, format, args);
+  size_t len = lenbuf;
 
-  va_start (args, format);
-  output = vasnprintf (buf, &lenbuf, format, args);
-  len = lenbuf;
   va_end (args);
 
   if (!output)
index 67b9a94544f8aef339d63a3adaa9a6ebf7390ca3..78610402dd6742751f2f5bf36c0d6de76a86662a 100644 (file)
@@ -111,16 +111,13 @@ euidaccess (const char *file, int mode)
     }
   else
     {
-      int result;
-      int saved_errno;
-
       if (uid != euid)
         setreuid (euid, uid);
       if (gid != egid)
         setregid (egid, gid);
 
-      result = access (file, mode);
-      saved_errno = errno;
+      int result = access (file, mode);
+      int saved_errno = errno;
 
       /* Restore them.  */
       if (uid != euid)
@@ -138,7 +135,6 @@ euidaccess (const char *file, int mode)
      correct on systems that have ACLs or the like.  However, it's
      better than nothing, and it is reentrant.  */
 
-  unsigned int granted;
   if (uid == euid && gid == egid)
     /* If we are not set-uid or set-gid, access does the same.  */
     return access (file, mode);
@@ -165,6 +161,7 @@ euidaccess (const char *file, int mode)
     return 0;                   /* The file exists.  */
 
   /* Convert the file's permission bits to traditional form.  */
+  unsigned int granted;
   if (S_IRUSR == (4 << 6) && S_IWUSR == (2 << 6) && S_IXUSR == (1 << 6)
       && S_IRGRP == (4 << 3) && S_IWGRP == (2 << 3) && S_IXGRP == (1 << 3)
       && S_IROTH == (4 << 0) && S_IWOTH == (2 << 0) && S_IXOTH == (1 << 0))
@@ -206,16 +203,12 @@ weak_alias (__euidaccess, euidaccess)
 int
 main (int argc, char **argv)
 {
-  char *file;
-  int mode;
-  int err;
-
   if (argc < 3)
     abort ();
-  file = argv[1];
-  mode = atoi (argv[2]);
+  char *file = argv[1];
+  int mode = atoi (argv[2]);
 
-  err = euidaccess (file, mode);
+  int err = euidaccess (file, mode);
   printf ("%d\n", err);
   if (err != 0)
     error (0, errno, "%s", file);
index 0faa188533032da03aa8d98604406425427e86b1..8174196c25a4d4d36281a1ac140f9d4edab2ef36 100644 (file)
@@ -524,10 +524,10 @@ add_exclude (struct exclude *ex, char const *pattern, int options)
       patopts->options = options;
       if (options & EXCLUDE_REGEX)
         {
-          int rc;
           int cflags = (REG_NOSUB | REG_EXTENDED
                         | (options & FNM_CASEFOLD ? REG_ICASE : 0));
 
+          int rc;
           if (! (options & FNM_LEADING_DIR))
             rc = regcomp (&patopts->v.re, pattern, cflags);
           else
index 17b7f91d2eabe6e583f5d6e3a303edc921c54062..e992fbfa3829341ec6c51d50ce447bc8e5a69592 100644 (file)
@@ -33,8 +33,6 @@
 int
 execl (const char *program, const char *arg0, ...)
 {
-  va_list args;
-
   /* The callee is not expecting a NULL argv[0].  */
   if (arg0 == NULL)
     {
@@ -44,14 +42,17 @@ execl (const char *program, const char *arg0, ...)
 
   /* Count the number of arguments (including arg0 and the trailing NULL).  */
   size_t count = 1;
-  va_start (args, arg0);
-  for (;;)
-    {
-      count++;
-      if (va_arg (args, const char *) == NULL)
-        break;
-    }
-  va_end (args);
+  {
+    va_list args;
+    va_start (args, arg0);
+    for (;;)
+      {
+        count++;
+        if (va_arg (args, const char *) == NULL)
+          break;
+      }
+    va_end (args);
+  }
 
   /* Allocate the argument vector.  */
   const char **argv = (const char **) malloca (count * sizeof (const char *));
@@ -65,6 +66,7 @@ execl (const char *program, const char *arg0, ...)
   {
     size_t i = 0;
     argv[i++] = arg0;
+    va_list args;
     va_start (args, arg0);
     for (; i < count;)
       argv[i++] = va_arg (args, const char *);
index d524c40fb7453919b76e0a94edcac2366e2ac843..e4a97cd7ad79bb42428e84888ae15380227a4dff 100644 (file)
@@ -33,7 +33,6 @@
 int
 execle (const char *program, const char *arg0, ...)
 {
-  va_list args;
 
   /* The callee is not expecting a NULL argv[0].  */
   if (arg0 == NULL)
@@ -44,14 +43,17 @@ execle (const char *program, const char *arg0, ...)
 
   /* Count the number of arguments (including arg0 and the trailing NULL).  */
   size_t count = 1;
-  va_start (args, arg0);
-  for (;;)
-    {
-      count++;
-      if (va_arg (args, const char *) == NULL)
-        break;
-    }
-  va_end (args);
+  {
+    va_list args;
+    va_start (args, arg0);
+    for (;;)
+      {
+        count++;
+        if (va_arg (args, const char *) == NULL)
+          break;
+      }
+    va_end (args);
+  }
 
   /* Allocate the argument vector.  */
   const char **argv = (const char **) malloca (count * sizeof (const char *));
@@ -62,6 +64,7 @@ execle (const char *program, const char *arg0, ...)
     }
 
   /* Copy the arguments into the argument vector.  */
+  va_list args;
   {
     size_t i = 0;
     argv[i++] = arg0;
index 7e9963f097549f29580ce10567263e1161528e86..04fb3eaf0b60075adccd07791a103b43da321e62 100644 (file)
@@ -33,8 +33,6 @@
 int
 execlp (const char *program, const char *arg0, ...)
 {
-  va_list args;
-
   /* The callee is not expecting a NULL argv[0].  */
   if (arg0 == NULL)
     {
@@ -44,14 +42,17 @@ execlp (const char *program, const char *arg0, ...)
 
   /* Count the number of arguments (including arg0 and the trailing NULL).  */
   size_t count = 1;
-  va_start (args, arg0);
-  for (;;)
-    {
-      count++;
-      if (va_arg (args, const char *) == NULL)
-        break;
-    }
-  va_end (args);
+  {
+    va_list args;
+    va_start (args, arg0);
+    for (;;)
+      {
+        count++;
+        if (va_arg (args, const char *) == NULL)
+          break;
+      }
+    va_end (args);
+  }
 
   /* Allocate the argument vector.  */
   const char **argv = (const char **) malloca (count * sizeof (const char *));
@@ -65,6 +66,7 @@ execlp (const char *program, const char *arg0, ...)
   {
     size_t i = 0;
     argv[i++] = arg0;
+    va_list args;
     va_start (args, arg0);
     for (; i < count;)
       argv[i++] = va_arg (args, const char *);
index 2d09750c7a86811e453805af9aa0cef4c522fee3..00fcdf0cb26692dca7bcbffa0c613bef6f5b4111 100644 (file)
@@ -121,7 +121,6 @@ execute (const char *progname,
          bool slave_process, bool exit_on_error,
          int *termsigp)
 {
-  int saved_errno;
   char *prog_path_to_free = NULL;
 
   if (directory != NULL)
@@ -170,6 +169,8 @@ execute (const char *progname,
         }
     }
 
+  int saved_errno;
+
 #if (defined _WIN32 && !defined __CYGWIN__) && EXECUTE_IMPL_AVOID_POSIX_SPAWN
 
   /* Native Windows API.  */
index 73c1a8462adea7370a852f0d79ff5365816ff2d5..961479c6d98a2823e5ae7772234a8c62375ba2d3 100644 (file)
@@ -62,13 +62,10 @@ ensure_dirs_slot (size_t fd)
     free (dirs[fd].name);
   else
     {
-      size_t new_allocated;
-      dir_info_t *new_dirs;
-
-      new_allocated = 2 * dirs_allocated + 1;
+      size_t new_allocated = 2 * dirs_allocated + 1;
       if (new_allocated <= fd)
         new_allocated = fd + 1;
-      new_dirs =
+      dir_info_t *new_dirs =
         (dirs != NULL
          ? (dir_info_t *) realloc (dirs, new_allocated * sizeof *dirs)
          : (dir_info_t *) malloc (new_allocated * sizeof *dirs));
@@ -87,18 +84,15 @@ ensure_dirs_slot (size_t fd)
 static char *
 get_name (char const *dir)
 {
-  char *cwd;
-  char *result;
-
   if (IS_ABSOLUTE_FILE_NAME (dir))
     return strdup (dir);
 
   /* We often encounter "."; treat it as a special case.  */
-  cwd = getcwd (NULL, 0);
+  char *cwd = getcwd (NULL, 0);
   if (!cwd || (dir[0] == '.' && dir[1] == '\0'))
     return cwd;
 
-  result = mfile_name_concat (cwd, dir, NULL);
+  char *result = mfile_name_concat (cwd, dir, NULL);
   free (cwd);
   return result;
 }
@@ -126,9 +120,9 @@ _gl_unregister_fd (int fd)
 int
 _gl_register_fd (int fd, const char *filename)
 {
-  struct stat statbuf;
-
   assure (0 <= fd);
+
+  struct stat statbuf;
   if (REPLACE_OPEN_DIRECTORY
       || (fstat (fd, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)))
     {
index ca7ecb2072a01c6d1795f72109dee1957941a3aa..cd036b9c11139497d2a5a375cb44c0c159be3a21 100644 (file)
@@ -58,11 +58,9 @@ int
 rpl_fclose (FILE *fp)
 {
   int saved_errno = 0;
-  int fd;
-  int result = 0;
 
   /* Don't change behavior on memstreams.  */
-  fd = fileno (fp);
+  int fd = fileno (fp);
   if (fd < 0)
     return fclose_nothrow (fp);
 
@@ -73,6 +71,8 @@ rpl_fclose (FILE *fp)
       && fflush (fp))
     saved_errno = errno;
 
+  int result = 0;
+
   /* fclose() calls close(), but we need to also invoke all hooks that our
      overridden close() function invokes.  See lib/close.c.  */
 #if WINDOWS_SOCKETS
index abdd7b89890571d869723f7327566d59159e7c76..15220c554f055845dad7870b24aa8a8a3e816889 100644 (file)
@@ -56,19 +56,15 @@ dupfd (int oldfd, int newfd, int flags)
 {
   /* Mingw has no way to create an arbitrary fd.  Iterate until all
      file descriptors less than newfd are filled up.  */
-  HANDLE curr_process = GetCurrentProcess ();
-  HANDLE old_handle = (HANDLE) _get_osfhandle (oldfd);
-  unsigned char fds_to_close[OPEN_MAX_MAX / CHAR_BIT];
-  unsigned int fds_to_close_bound = 0;
-  int result;
-  BOOL inherit = flags & O_CLOEXEC ? FALSE : TRUE;
-  int mode;
 
   if (newfd < 0 || getdtablesize () <= newfd)
     {
       errno = EINVAL;
       return -1;
     }
+
+  HANDLE old_handle = (HANDLE) _get_osfhandle (oldfd);
+  int mode;
   if (old_handle == INVALID_HANDLE_VALUE
       || (mode = _setmode (oldfd, O_BINARY)) == -1)
     {
@@ -80,6 +76,11 @@ dupfd (int oldfd, int newfd, int flags)
   _setmode (oldfd, mode);
   flags |= mode;
 
+  HANDLE curr_process = GetCurrentProcess ();
+  BOOL inherit = flags & O_CLOEXEC ? FALSE : TRUE;
+  unsigned char fds_to_close[OPEN_MAX_MAX / CHAR_BIT];
+  unsigned int fds_to_close_bound = 0;
+  int result;
   for (;;)
     {
       HANDLE new_handle;
@@ -205,8 +206,9 @@ fcntl (int fd, int action, /* arg */...)
 #endif
 {
   va_list arg;
-  int result = -1;
   va_start (arg, action);
+
+  int result = -1;
   switch (action)
     {
     case F_DUPFD:
@@ -432,7 +434,9 @@ fcntl (int fd, int action, /* arg */...)
         break;
       }
     }
+
   va_end (arg);
+
   return result;
 }
 
@@ -542,10 +546,7 @@ rpl_fcntl_DUPFD_CLOEXEC (int fd, int target)
 static int
 klibc_dupdirfd (int fd, int minfd)
 {
-  int tempfd;
-  int dupfd;
-
-  tempfd = open ("NUL", O_RDONLY);
+  int tempfd = open ("NUL", O_RDONLY);
   if (tempfd == -1)
     return -1;
 
@@ -557,7 +558,7 @@ klibc_dupdirfd (int fd, int minfd)
       if (__libc_Back_ioFHToPath (fd, path, sizeof (path)))
         return -1;
 
-      dupfd = open (path, O_RDONLY);
+      int dupfd = open (path, O_RDONLY);
       if (dupfd == -1)
         return -1;
 
@@ -568,7 +569,7 @@ klibc_dupdirfd (int fd, int minfd)
       tempfd = dupfd;
     }
 
-  dupfd = klibc_dupdirfd (fd, minfd);
+  int dupfd = klibc_dupdirfd (fd, minfd);
 
   close (tempfd);
 
@@ -579,77 +580,78 @@ static int
 klibc_fcntl (int fd, int action, /* arg */...)
 {
   va_list arg_ptr;
-  int arg;
-  struct stat sbuf;
-  int result;
-
   va_start (arg_ptr, action);
-  arg = va_arg (arg_ptr, int);
-  result = fcntl (fd, action, arg);
+
+  int arg = va_arg (arg_ptr, int);
+  int result = fcntl (fd, action, arg);
   /* EPERM for F_DUPFD, ENOTSUP for others */
-  if (result == -1 && (errno == EPERM || errno == ENOTSUP)
-      && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode))
+  if (result == -1 && (errno == EPERM || errno == ENOTSUP))
     {
-      PLIBCFH pFH;
-      unsigned fFlags;
-
-      switch (action)
+      struct stat sbuf;
+      if (!fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode))
         {
-        case F_DUPFD:
-          result = klibc_dupdirfd (fd, arg);
-          break;
-
-        case F_GETFD:
-          pFH = __libc_FH (fd);
-          if (!pFH)
+          switch (action)
             {
-              errno = EBADF;
+            case F_DUPFD:
+              result = klibc_dupdirfd (fd, arg);
               break;
-            }
-
-          result = (pFH->fFlags & ((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT )
-                                   | O_NOINHERIT)) ? FD_CLOEXEC : 0;
-          break;
 
-        case F_SETFD:
-          if (arg & ~FD_CLOEXEC)
-            break;
-
-          pFH = __libc_FH (fd);
-          if (!pFH)
-            {
-              errno = EBADF;
+            case F_GETFD:
+              {
+                PLIBCFH pFH = __libc_FH (fd);
+                if (!pFH)
+                  {
+                    errno = EBADF;
+                    break;
+                }
+
+                result = (pFH->fFlags & ((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT )
+                                         | O_NOINHERIT)) ? FD_CLOEXEC : 0;
+              }
               break;
-            }
-
-          fFlags = pFH->fFlags;
-          if (arg & FD_CLOEXEC)
-            fFlags |= (FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT;
-          else
-            fFlags &= ~((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT);
 
-          result = __libc_FHSetFlags (pFH, fd, fFlags);
-          if (result < 0)
-            {
-              errno = -result;
-              result = -1;
-            }
-          break;
+            case F_SETFD:
+              {
+                if (arg & ~FD_CLOEXEC)
+                  break;
+
+                PLIBCFH pFH = __libc_FH (fd);
+                if (!pFH)
+                  {
+                    errno = EBADF;
+                    break;
+                  }
+
+                unsigned fFlags = pFH->fFlags;
+                if (arg & FD_CLOEXEC)
+                  fFlags |= (FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT;
+                else
+                  fFlags &= ~((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT);
+
+                result = __libc_FHSetFlags (pFH, fd, fFlags);
+                if (result < 0)
+                  {
+                    errno = -result;
+                    result = -1;
+                  }
+              }
+              break;
 
-        case F_GETFL:
-          result = 0;
-          break;
+            case F_GETFL:
+              result = 0;
+              break;
 
-        case F_SETFL:
-          if (arg != 0)
-            break;
+            case F_SETFL:
+              if (arg != 0)
+                break;
 
-          result = 0;
-          break;
+              result = 0;
+              break;
 
-        default:
-          errno = EINVAL;
-          break;
+            default:
+              errno = EINVAL;
+              break;
+            }
         }
     }
 
index 5476532a094807c08bdb73eacea05bba8a82ad9e..b504701710ee1edbda2d1e4a84683ddc64aa3b45 100644 (file)
@@ -57,10 +57,9 @@ FILE *
 rpl_fdopen (int fd, const char *mode)
 {
   int saved_errno = errno;
-  FILE *fp;
 
   errno = 0;
-  fp = fdopen_nothrow (fd, mode);
+  FILE *fp = fdopen_nothrow (fd, mode);
   if (fp == NULL)
     {
       if (errno == 0)
index 9a5a18aabcfbc889697daf7142652f058d90eff5..d5a52b5b2f88545c798cc114d99a90df378aa1c8 100644 (file)
@@ -161,7 +161,6 @@ aclinfo_has_xattr (struct aclinfo const *ai, char const *xattr)
 static void
 get_aclinfo (int fd, char const *name, struct aclinfo *ai, int flags)
 {
-  int scontext_err = ENOTSUP;
   ai->buf = ai->u.__gl_acl_ch;
   ssize_t acl_alloc = sizeof ai->u.__gl_acl_ch;
 
@@ -221,6 +220,7 @@ get_aclinfo (int fd, char const *name, struct aclinfo *ai, int flags)
     }
 
   /* A security context can exist only if extended attributes do.  */
+  int scontext_err = ENOTSUP;
   if (flags & ACL_GET_SCONTEXT
       && (0 < ai->size || aclinfo_may_indicate_xattr (ai)))
     {
@@ -781,11 +781,9 @@ fdfile_has_aclinfo (MAYBE_UNUSED int fd,
 
       {
         struct acl_entry entries[NACLENTRIES];
-        int count;
-
-        count = (fd < 0
-                 ? getacl (name, NACLENTRIES, entries)
-                 : fgetacl (fd, NACLENTRIES, entries));
+        int count = (fd < 0
+                     ? getacl (name, NACLENTRIES, entries)
+                     : fgetacl (fd, NACLENTRIES, entries));
 
         if (count < 0)
           {
@@ -827,10 +825,9 @@ fdfile_has_aclinfo (MAYBE_UNUSED int fd,
 
       {
         struct acl entries[NACLVENTRIES];
-        int count;
 
         /* Ignore FD, unfortunately.  */
-        count = acl ((char *) name, ACL_GET, NACLVENTRIES, entries);
+        int count = acl ((char *) name, ACL_GET, NACLVENTRIES, entries);
 
         if (count < 0)
           {
@@ -867,13 +864,13 @@ fdfile_has_aclinfo (MAYBE_UNUSED int fd,
       char aclbuf[1024];
       void *acl = aclbuf;
       size_t aclsize = sizeof (aclbuf);
-      mode_t mode;
 
       for (;;)
         {
           /* The docs say that type being 0 is equivalent to ACL_ANY, but it
              is not true, in AIX 5.3.  */
           type.u64 = ACL_ANY;
+          mode_t mode;
           if (0 <= (fd < 0
                     ? aclx_get (name, 0, &type, aclbuf, &aclsize, &mode)
                     : aclx_fget (fd, 0, &type, aclbuf, &aclsize, &mode)))
@@ -934,10 +931,9 @@ fdfile_has_aclinfo (MAYBE_UNUSED int fd,
 
       {
         struct acl entries[NACLENTRIES];
-        int count;
 
         /* Ignore FD, unfortunately.  */
-        count = acl ((char *) name, ACL_GET, NACLENTRIES, entries);
+        int count = acl ((char *) name, ACL_GET, NACLENTRIES, entries);
 
         if (count < 0)
           {
index 98325554fab6c5dab4fbf9eb9b869dc50c72d1e3..437a05787cc90787116884e023eb102e882b79ca 100644 (file)
@@ -305,9 +305,7 @@ file_is_remote (const char *file)
 int
 main (int argc, char *argv[])
 {
-  int i;
-
-  for (i = 1; i < argc; i++)
+  for (int i = 1; i < argc; i++)
     {
       const char *file = argv[i];
       int ret = file_is_remote (file);
index 6d4f02554a7c8662c3795a62c790a93c7aafc643..c1d63c897dd2cfc4748cfdbad50ca3123241b95c 100644 (file)
 void
 record_file (Hash_table *ht, char const *file, struct stat const *stats)
 {
-  struct F_triple *ent;
-
   if (ht == NULL)
     return;
 
-  ent = xmalloc (sizeof *ent);
+  struct F_triple *ent = xmalloc (sizeof *ent);
   ent->name = xstrdup (file);
   ent->st_ino = stats->st_ino;
   ent->st_dev = stats->st_dev;
@@ -61,11 +59,11 @@ bool
 seen_file (Hash_table const *ht, char const *file,
            struct stat const *stats)
 {
-  struct F_triple new_ent;
 
   if (ht == NULL)
     return false;
 
+  struct F_triple new_ent;
   new_ent.name = (char *) file;
   new_ent.st_ino = stats->st_ino;
   new_ent.st_dev = stats->st_dev;
index cc86f1d16d414072201c4e0f899b0e516fee1db0..1d58288d8e691a4a536a490c1b1bde87b80af72c 100644 (file)
@@ -94,17 +94,13 @@ 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;
-
             const char *directory_as_prefix =
               (directory != NULL && IS_RELATIVE_FILE_NAME (progname)
                ? directory
                : "");
 
             #if defined _WIN32 && !defined __CYGWIN__ /* Native Windows */
-            const char *progbasename;
-
-            progbasename = progname;
+            const char *progbasename = progname;
             for (const char *p = progname; *p != '\0'; p++)
               if (ISSLASH (*p))
                 progbasename = p + 1;
@@ -113,7 +109,7 @@ find_in_given_path (const char *progname, const char *path,
             #endif
 
             /* Try all platform-dependent suffixes.  */
-            failure_errno = ENOENT;
+            int failure_errno = ENOENT;
             for (size_t i = 0; i < sizeof (suffixes) / sizeof (suffixes[0]); i++)
               {
                 const char *suffix = suffixes[i];
@@ -214,26 +210,19 @@ find_in_given_path (const char *progname, const char *path,
     if (path_copy == NULL)
       return NULL; /* errno is set here */
 
-    int failure_errno;
-    char *cp;
-
     #if defined _WIN32 && !defined __CYGWIN__ /* Native Windows */
     bool progname_has_dot = (strchr (progname, '.') != NULL);
     #endif
 
-    failure_errno = ENOENT;
-    for (char *path_rest = path_copy; ; path_rest = cp + 1)
+    int failure_errno = ENOENT;
+    for (char *path_rest = path_copy; ; )
       {
-        const char *dir;
-        bool last;
-        char *dir_as_prefix_to_free;
-        const char *dir_as_prefix;
-
         /* Extract next directory in PATH.  */
-        dir = path_rest;
+        const char *dir = path_rest;
+        char *cp;
         for (cp = path_rest; *cp != '\0' && *cp != PATH_SEPARATOR; cp++)
           ;
-        last = (*cp == '\0');
+        bool last = (*cp == '\0');
         *cp = '\0';
 
         /* Empty PATH components designate the current directory.  */
@@ -241,6 +230,8 @@ find_in_given_path (const char *progname, const char *path,
           dir = ".";
 
         /* Concatenate directory and dir.  */
+        char *dir_as_prefix_to_free;
+        const char *dir_as_prefix;
         if (directory != NULL && IS_RELATIVE_FILE_NAME (dir))
           {
             dir_as_prefix_to_free =
@@ -375,6 +366,8 @@ find_in_given_path (const char *progname, const char *path,
 
         if (last)
           break;
+
+        path_rest = cp + 1;
       }
 
    failed:
index e117ba3986e665a1aa4cdac0d88688626d0dad18..b6bd776b26f9eea4a4633d8807a732e84d227561 100644 (file)
@@ -47,15 +47,12 @@ find_in_path (const char *progname)
   return progname;
 #else
   /* Unix */
-  char *path;
-  char *cp;
-
   if (strchr (progname, '/') != NULL)
     /* If progname contains a slash, it is either absolute or relative to
        the current directory.  PATH is not used.  */
     return progname;
 
-  path = getenv ("PATH");
+  char *path = getenv ("PATH");
   if (path == NULL || *path == '\0')
     /* If PATH is not set, the default search path is implementation
        dependent.  */
@@ -70,17 +67,14 @@ find_in_path (const char *progname)
     /* Out of memory.  */
     return progname;
 # endif
-  for (char *path_rest = path; ; path_rest = cp + 1)
+  for (char *path_rest = path; ; )
     {
-      const char *dir;
-      bool last;
-      char *progpathname;
-
       /* Extract next directory in PATH.  */
-      dir = path_rest;
+      const char *dir = path_rest;
+      char *cp;
       for (cp = path_rest; *cp != '\0' && *cp != ':'; cp++)
         ;
-      last = (*cp == '\0');
+      bool last = (*cp == '\0');
       *cp = '\0';
 
       /* Empty PATH components designate the current directory.  */
@@ -88,6 +82,7 @@ find_in_path (const char *progname)
         dir = ".";
 
       /* Concatenate dir and progname.  */
+      char *progpathname;
 # if !IN_FINDPROG_LGPL
       progpathname = xconcatenated_filename (dir, progname, NULL);
 # else
@@ -145,6 +140,8 @@ find_in_path (const char *progname)
 
       if (last)
         break;
+
+      path_rest = cp + 1;
     }
 
   /* Not found in PATH.  An error will be signalled at the first call.  */
index 43c0c0b8b799d53df7733f2ce3ccc29fbd2ae707..4c0cd8348f4083ae673c74cd6cb74df5ccdab274 100644 (file)
@@ -59,19 +59,17 @@ file_size (HANDLE h, DWORD * lower, DWORD * upper)
 static BOOL
 do_lock (HANDLE h, int non_blocking, int exclusive)
 {
-  BOOL res;
-  DWORD size_lower, size_upper;
-  OVERLAPPED ovlp;
-  int flags = 0;
-
   /* We're going to lock the whole file, so get the file size. */
-  res = file_size (h, &size_lower, &size_upper);
+  DWORD size_lower, size_upper;
+  BOOL res = file_size (h, &size_lower, &size_upper);
   if (!res)
     return 0;
 
   /* Start offset is 0, and also zero the remaining members of this struct. */
+  OVERLAPPED ovlp;
   memset (&ovlp, 0, sizeof ovlp);
 
+  int flags = 0;
   if (non_blocking)
     flags |= LOCKFILE_FAIL_IMMEDIATELY;
   if (exclusive)
@@ -84,10 +82,8 @@ do_lock (HANDLE h, int non_blocking, int exclusive)
 static BOOL
 do_unlock (HANDLE h)
 {
-  int res;
   DWORD size_lower, size_upper;
-
-  res = file_size (h, &size_lower, &size_upper);
+  int res = file_size (h, &size_lower, &size_upper);
   if (!res)
     return 0;
 
@@ -99,18 +95,16 @@ int
 flock (int fd, int operation)
 {
   HANDLE h = (HANDLE) _get_osfhandle (fd);
-  DWORD res;
-  int non_blocking;
-
   if (h == INVALID_HANDLE_VALUE)
     {
       errno = EBADF;
       return -1;
     }
 
-  non_blocking = operation & LOCK_NB;
+  int non_blocking = operation & LOCK_NB;
   operation &= ~LOCK_NB;
 
+  DWORD res;
   switch (operation)
     {
     case LOCK_SH:
@@ -179,15 +173,14 @@ flock (int fd, int operation)
 int
 flock (int fd, int operation)
 {
-  int cmd, r;
-  struct flock fl;
-
+  int cmd;
   if (operation & LOCK_NB)
     cmd = F_SETLK;
   else
     cmd = F_SETLKW;
   operation &= ~LOCK_NB;
 
+  struct flock fl;
   memset (&fl, 0, sizeof fl);
   fl.l_whence = SEEK_SET;
   /* l_start & l_len are 0, which as a special case means "whole file". */
@@ -208,7 +201,7 @@ flock (int fd, int operation)
       return -1;
     }
 
-  r = fcntl (fd, cmd, &fl);
+  int r = fcntl (fd, cmd, &fl);
   if (r == -1 && errno == EACCES)
     errno = EAGAIN;
 
index 6175c448ad820a4d18ae9749fa6a7c489bcb774a..485fc127182bcf843999f9e93d37b834566b6d8a 100644 (file)
--- a/lib/fma.c
+++ b/lib/fma.c
@@ -128,9 +128,8 @@ decode (DOUBLE x, mp_limb_t limbs[NLIMBS1])
     {
       /* Here we still have MANT_BIT-0*31 bits to extract from x.  */
       enum { chunk_bits = MIN (31, MANT_BIT - 0 * 31) }; /* > 0, <= 31 */
-      mp_limb_t d;
       x *= (mp_limb_t) 1 << chunk_bits;
-      d = (int) x; /* 0 <= d < 2^chunk_bits.  */
+      mp_limb_t d = (int) x; /* 0 <= d < 2^chunk_bits.  */
       x -= d;
       if (!(x >= L_(0.0) && x < L_(1.0)))
         abort ();
@@ -166,9 +165,8 @@ decode (DOUBLE x, mp_limb_t limbs[NLIMBS1])
     {
       /* Here we still have MANT_BIT-1*31 bits to extract from x.  */
       enum { chunk_bits = MIN (31, MAX (MANT_BIT - 1 * 31, 0)) }; /* > 0, <= 31 */
-      mp_limb_t d;
       x *= (mp_limb_t) 1 << chunk_bits;
-      d = (int) x; /* 0 <= d < 2^chunk_bits.  */
+      mp_limb_t d = (int) x; /* 0 <= d < 2^chunk_bits.  */
       x -= d;
       if (!(x >= L_(0.0) && x < L_(1.0)))
         abort ();
@@ -204,9 +202,8 @@ decode (DOUBLE x, mp_limb_t limbs[NLIMBS1])
     {
       /* Here we still have MANT_BIT-2*31 bits to extract from x.  */
       enum { chunk_bits = MIN (31, MAX (MANT_BIT - 2 * 31, 0)) }; /* > 0, <= 31 */
-      mp_limb_t d;
       x *= (mp_limb_t) 1 << chunk_bits;
-      d = (int) x; /* 0 <= d < 2^chunk_bits.  */
+      mp_limb_t d = (int) x; /* 0 <= d < 2^chunk_bits.  */
       x -= d;
       if (!(x >= L_(0.0) && x < L_(1.0)))
         abort ();
@@ -242,9 +239,8 @@ decode (DOUBLE x, mp_limb_t limbs[NLIMBS1])
     {
       /* Here we still have MANT_BIT-3*31 bits to extract from x.  */
       enum { chunk_bits = MIN (31, MAX (MANT_BIT - 3 * 31, 0)) }; /* > 0, <= 31 */
-      mp_limb_t d;
       x *= (mp_limb_t) 1 << chunk_bits;
-      d = (int) x; /* 0 <= d < 2^chunk_bits.  */
+      mp_limb_t d = (int) x; /* 0 <= d < 2^chunk_bits.  */
       x -= d;
       if (!(x >= L_(0.0) && x < L_(1.0)))
         abort ();
@@ -283,9 +279,8 @@ decode (DOUBLE x, mp_limb_t limbs[NLIMBS1])
       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;
           x *= (mp_limb_t) 1 << chunk_bits;
-          d = (int) x; /* 0 <= d < 2^chunk_bits.  */
+          mp_limb_t d = (int) x; /* 0 <= d < 2^chunk_bits.  */
           x -= d;
           if (!(x >= L_(0.0) && x < L_(1.0)))
             abort ();
index 0b72a61cc8ba7060829b9353ce831ea4755b107e..a6e05294c9787bfbf6d75ff8368aabdc7ce98798 100644 (file)
@@ -45,24 +45,18 @@ orig_fopen (const char *filename, const char *mode)
 FILE *
 rpl_fopen (const char *filename, const char *mode)
 {
-  int open_direction;
-  int open_flags;
-#if GNULIB_FOPEN_GNU
-  bool open_flags_gnu;
-# define BUF_SIZE 80
-  char fdopen_mode_buf[BUF_SIZE + 1];
-#endif
-
 #if defined _WIN32 && ! defined __CYGWIN__
   if (streq (filename, "/dev/null"))
     filename = "NUL";
 #endif
 
   /* Parse the mode.  */
-  open_direction = 0;
-  open_flags = 0;
+  int open_direction = 0;
+  int open_flags = 0;
 #if GNULIB_FOPEN_GNU
-  open_flags_gnu = false;
+  bool open_flags_gnu = false;
+# define BUF_SIZE 80
+  char fdopen_mode_buf[BUF_SIZE + 1];
 #endif
   {
     const char *p = mode;
@@ -163,21 +157,18 @@ rpl_fopen (const char *filename, const char *mode)
     size_t len = strlen (filename);
     if (len > 0 && filename[len - 1] == '/')
       {
-        int fd;
-        struct stat statbuf;
-        FILE *fp;
-
         if (open_direction != O_RDONLY)
           {
             errno = EISDIR;
             return NULL;
           }
 
-        fd = open (filename, open_direction | open_flags,
-                   S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
+        int fd = open (filename, open_direction | open_flags,
+                       S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
         if (fd < 0)
           return NULL;
 
+        struct stat statbuf;
         if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
           {
             close (fd);
@@ -185,6 +176,7 @@ rpl_fopen (const char *filename, const char *mode)
             return NULL;
           }
 
+        FILE *fp;
 # if GNULIB_FOPEN_GNU
         fp = fdopen (fd, fdopen_mode_buf);
 # else
@@ -204,15 +196,12 @@ rpl_fopen (const char *filename, const char *mode)
 #if GNULIB_FOPEN_GNU
   if (open_flags_gnu)
     {
-      int fd;
-      FILE *fp;
-
-      fd = open (filename, open_direction | open_flags,
-                 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
+      int fd = open (filename, open_direction | open_flags,
+                     S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
       if (fd < 0)
         return NULL;
 
-      fp = fdopen (fd, fdopen_mode_buf);
+      FILE *fp = fdopen (fd, fdopen_mode_buf);
       if (fp == NULL)
         {
           int saved_errno = errno;
index f022c975502f89b323a0b6d1e18d52f72bafc9b9..a68370d33100f03ff54ce90d67c332fa6e7955bf 100644 (file)
@@ -43,12 +43,13 @@ int
 forkpty (int *amaster, char *name,
          const struct termios *termp, const struct winsize *winp)
 {
-  int master, slave, pid;
+  int master, slave;
 
   if (openpty (&master, &slave, name, termp, winp) == -1)
     return -1;
 
-  switch (pid = fork ())
+  int pid = fork ();
+  switch (pid)
     {
     case -1:
       close (master);
index 4498be86260674f874d8e02396694868c8394ebe..2b3e870669196a0fbe677a497ece840b98665154 100644 (file)
@@ -32,10 +32,8 @@ int
 fprintf (FILE *fp, const char *format, ...)
 {
   va_list args;
-  off64_t ret;
-
   va_start (args, format);
-  ret = vfzprintf (fp, format, args);
+  off64_t ret = vfzprintf (fp, format, args);
   va_end (args);
 
   if (TYPE_MAXIMUM (off64_t) > INT_MAX && ret > INT_MAX)
index 18881e32ff63643c33d42344ec5ec79656ff6ee9..6a21b36e010edd280dc1a935d4850db80f96365c 100644 (file)
@@ -73,15 +73,12 @@ freadptrinc (FILE *fp, size_t increment)
 int
 freadseek (FILE *fp, size_t offset)
 {
-  size_t total_buffered;
-  int fd;
-
   if (offset == 0)
     return 0;
 
   /* Seek over the already read and buffered input as quickly as possible,
      without doing any system calls.  */
-  total_buffered = freadahead (fp);
+  size_t total_buffered = freadahead (fp);
   /* This loop is usually executed at most twice: once for ungetc buffer (if
      present) and once for the main buffer.  */
   while (total_buffered > 0)
@@ -111,7 +108,7 @@ freadseek (FILE *fp, size_t offset)
     }
 
   /* Test whether the stream is seekable or not.  */
-  fd = fileno (fp);
+  int fd = fileno (fp);
   if (fd >= 0 && lseek (fd, 0, SEEK_CUR) >= 0)
     {
       /* FP refers to a regular file.  fseek is most efficient in this case.  */
@@ -121,10 +118,9 @@ freadseek (FILE *fp, size_t offset)
     {
       /* FP is a non-seekable stream, possibly not even referring to a file
          descriptor.  Read OFFSET bytes explicitly and discard them.  */
-      char buf[4096];
-
       do
         {
+          char buf[4096];
           size_t count = (sizeof (buf) < offset ? sizeof (buf) : offset);
           if (fread (buf, 1, count, fp) < count)
             goto eof;
index 304bdc2ab930a6b3ead80a2fd7eb8cda3826c6c4..4a9bdc6ac020982c7d4fb9fbe4902ea0b5d10916 100644 (file)
@@ -68,7 +68,6 @@ freopen_safer (char const *name, char const *mode, FILE *f)
   bool protect_in = false;
   bool protect_out = false;
   bool protect_err = false;
-  int saved_errno;
 
   switch (fileno (f))
     {
@@ -96,7 +95,7 @@ freopen_safer (char const *name, char const *mode, FILE *f)
     f = NULL;
   else
     f = freopen (name, mode, f);
-  saved_errno = errno;
+  int saved_errno = errno;
   if (protect_err)
     close (STDERR_FILENO);
   if (protect_out)
index 14c94d989f28e872cdbbc2bd8ba7fb3100196255..899b8d47cd45f96af40106d56e6e3270f20b9530 100644 (file)
@@ -44,7 +44,6 @@ orig_freopen (const char *filename, const char *mode, FILE *stream)
 FILE *
 rpl_freopen (const char *filename, const char *mode, FILE *stream)
 {
-  FILE *result;
 #if defined _WIN32 && ! defined __CYGWIN__
   char const *null_device = "NUL";
   if (filename && streq (filename, "/dev/null"))
@@ -57,7 +56,7 @@ rpl_freopen (const char *filename, const char *mode, FILE *stream)
   errno = 0;
 #endif
 
-  result = orig_freopen (filename, mode, stream);
+  FILE *result = orig_freopen (filename, mode, stream);
 
   if (!result)
     {
index 18b95f6c8243491eb1136c9be0ac037ddfe8f4d7..3ac638211320db1971b839a98d68ae049944f8fc 100644 (file)
@@ -57,8 +57,6 @@
 DOUBLE
 FUNC (DOUBLE x, int *expptr)
 {
-  int sign;
-  int exponent;
   DECL_ROUNDING
 
   /* Test for NaN, infinity, and zero.  */
@@ -68,7 +66,7 @@ FUNC (DOUBLE x, int *expptr)
       return x;
     }
 
-  sign = 0;
+  int sign = 0;
   if (x < 0)
     {
       x = - x;
@@ -77,6 +75,8 @@ FUNC (DOUBLE x, int *expptr)
 
   BEGIN_ROUNDING ();
 
+  int exponent;
+
   {
     /* Since the exponent is an 'int', it fits in 64 bits.  Therefore the
        loops are executed no more than 64 times.  */
index 40aca95c8ebf6bd7284294a3eaf0e05393c3da2b..e84516f4236409c7a5de31543740af847eee5e9a 100644 (file)
@@ -59,14 +59,10 @@ fseterr (FILE *fp)
      Not activated on any system, because there is no way to repair FP when
      the sequence of system calls fails, and library code should not call
      abort().  */
-  int saved_errno;
-  int fd;
-  int fd2;
-
-  saved_errno = errno;
+  int saved_errno = errno;
   fflush (fp);
-  fd = fileno (fp);
-  fd2 = dup (fd);
+  int fd = fileno (fp);
+  int fd2 = dup (fd);
   if (fd2 >= 0)
     {
       close (fd);
index 6029de78842691ddcd4ed7f6d552864cb6de640d..d72c09932fdecbbae5cec89ac4ae167d6cd05ec0 100644 (file)
@@ -71,11 +71,10 @@ int
 rpl_fstatat (int fd, char const *file, struct stat *st, int flag)
 {
   int result = normal_fstatat (fd, file, st, flag);
-  size_t len;
-
   if (LSTAT_FOLLOWS_SLASHED_SYMLINK || result != 0)
     return result;
-  len = strlen (file);
+
+  size_t len = strlen (file);
   if (flag & AT_SYMLINK_NOFOLLOW)
     {
       /* Fix lstat behavior.  */
index 24c54e7069257e8849ae2c3a0c96c72f43c15090..33e8a9e38c7d5e5ed54952691981d561bf32e49d 100644 (file)
@@ -77,10 +77,8 @@ gl_once_define(static, keys_init_once)
 void
 fstrcmp_free_resources (void)
 {
-  ptrdiff_t *buffer;
-
   gl_once (keys_init_once, keys_init);
-  buffer = gl_tls_get (buffer_key);
+  ptrdiff_t *buffer = gl_tls_get (buffer_key);
   if (buffer != NULL)
     {
       gl_tls_set (buffer_key, NULL);
@@ -100,15 +98,10 @@ fstrcmp_free_resources (void)
 double
 fstrcmp_bounded (const char *string1, const char *string2, double lower_bound)
 {
-  struct context ctxt;
   size_t xvec_length = strlen (string1);
   size_t yvec_length = strlen (string2);
   size_t length_sum = xvec_length + yvec_length;
 
-  ptrdiff_t fdiag_len;
-  ptrdiff_t *buffer;
-  uintptr_t bufmax;
-
   /* short-circuit obvious comparisons */
   if (xvec_length == 0 || yvec_length == 0) /* Prob: 1% */
     return length_sum == 0;
@@ -166,8 +159,6 @@ fstrcmp_bounded (const char *string1, const char *string2, double lower_bound)
                     / (xvec_length + yvec_length).
            */
           ptrdiff_t occ_diff[UCHAR_MAX + 1]; /* array C -> OCC(X,C) - OCC(Y,C) */
-          ptrdiff_t sum;
-          double dsum;
 
           /* Determine the occurrence counts in X.  */
           memset (occ_diff, 0, sizeof (occ_diff));
@@ -177,14 +168,14 @@ fstrcmp_bounded (const char *string1, const char *string2, double lower_bound)
           for (ptrdiff_t i = yvec_length - 1; i >= 0; i--)
             occ_diff[(unsigned char) string2[i]]--;
           /* Sum up the absolute values.  */
-          sum = 0;
+          ptrdiff_t sum = 0;
           for (ptrdiff_t i = 0; i <= UCHAR_MAX; i++)
             {
               ptrdiff_t d = occ_diff[i];
               sum += (d >= 0 ? d : -d);
             }
 
-          dsum = sum;
+          double dsum = sum;
           upper_bound = 1.0 - dsum / length_sum;
 
           if (upper_bound < lower_bound) /* Prob: 66% */
@@ -195,6 +186,7 @@ fstrcmp_bounded (const char *string1, const char *string2, double lower_bound)
     }
 
   /* set the info for each string.  */
+  struct context ctxt;
   ctxt.xvec = string1;
   ctxt.yvec = string2;
 
@@ -207,10 +199,10 @@ fstrcmp_bounded (const char *string1, const char *string2, double lower_bound)
     ctxt.too_expensive = 4096;
 
   /* Allocate memory for fdiag and bdiag from a thread-local pool.  */
-  fdiag_len = length_sum + 3;
+  ptrdiff_t fdiag_len = length_sum + 3;
   gl_once (keys_init_once, keys_init);
-  buffer = gl_tls_get (buffer_key);
-  bufmax = (uintptr_t) gl_tls_get (bufmax_key);
+  ptrdiff_t *buffer = gl_tls_get (buffer_key);
+  uintptr_t bufmax = (uintptr_t) gl_tls_get (bufmax_key);
   if (fdiag_len > bufmax)
     {
       /* Need more memory.  */
index 64a12c5d48e4102021a5d916fcee87874591856a..bd23b443dc0cde8277040cb9460a7f60d928bba7 100644 (file)
@@ -91,10 +91,12 @@ static int
 statvfs_works (void)
 {
   static int statvfs_works_cache = -1;
-  struct utsname name;
   if (statvfs_works_cache < 0)
-    statvfs_works_cache = (uname (&name) == 0
-                           && 0 <= strverscmp (name.release, "2.6.36"));
+    {
+      struct utsname name;
+      statvfs_works_cache = (uname (&name) == 0
+                             && 0 <= strverscmp (name.release, "2.6.36"));
+    }
   return statvfs_works_cache;
 }
 # endif
index dcb2d6377457aaec70806023c7834ddc340cc2ae..5b7183c8737f4e10df288d562f92795ad0c5e4e1 100644 (file)
@@ -44,7 +44,6 @@ int
 fsync (int fd)
 {
   HANDLE h = (HANDLE) _get_osfhandle (fd);
-  DWORD err;
 
   if (h == INVALID_HANDLE_VALUE)
     {
@@ -58,7 +57,7 @@ fsync (int fd)
        * errors.  MSDN is useless as usual - in this case it doesn't
        * document the full range of errors.
        */
-      err = GetLastError ();
+      DWORD err = GetLastError ();
       switch (err)
         {
         case ERROR_ACCESS_DENIED:
index b0a20bf3215b3d15075e726668d13c21dea99355..5dc08447a5425bd07768bc5fad2280595ff6c2d7 100644 (file)
@@ -124,13 +124,11 @@ ftello (FILE *fp)
      gets confused by this.  */
   if (fp_->_flag & _IOWRT)
     {
-      off_t pos;
-
       /* Call ftello nevertheless, for the side effects that it does on fp.  */
       ftello (fp);
 
       /* Compute the file position ourselves.  */
-      pos = lseek (fileno (fp), (off_t) 0, SEEK_CUR);
+      off_t pos = lseek (fileno (fp), (off_t) 0, SEEK_CUR);
       if (pos >= 0)
         {
           if ((fp_->_flag & _IONBF) == 0 && fp_->_base != NULL)
index ca19f21e3040cc8124bc16eef941e48b3afab691..2d071dc7247d2ba2003f89dab1714ca403defa49 100644 (file)
@@ -96,14 +96,13 @@ SetFileSize (HANDLE h, LONGLONG size)
           static char zero_bytes[1024];
           LONG pos_hi = 0;
           LONG pos_lo = SetFilePointer (tmph, (LONG) 0, &pos_hi, FILE_END);
-          LONGLONG pos;
           if (pos_lo == INVALID_SET_FILE_POINTER
               && GetLastError() != NO_ERROR)
             {
               CloseHandle (tmph);
               return FALSE;
             }
-          pos = ((LONGLONG) pos_hi << 32) | (ULONGLONG) (ULONG) pos_lo;
+          LONGLONG pos = ((LONGLONG) pos_hi << 32) | (ULONGLONG) (ULONG) pos_lo;
           while (pos < size)
             {
               DWORD written;
index f2e672f9afa87a7be4d3ccc0017662343ea57ab5..c44ebde870e50d515ca30da9b4ead5914fa5186d 100644 (file)
@@ -75,13 +75,11 @@ enter_dir (FTS *fts, FTSENT *ent)
 {
   if (fts->fts_options & (FTS_TIGHT_CYCLE_CHECK | FTS_LOGICAL))
     {
-      struct stat const *st = ent->fts_statp;
       struct Active_dir *ad = malloc (sizeof *ad);
-      struct Active_dir *ad_from_table;
-
       if (!ad)
         return false;
 
+      struct stat const *st = ent->fts_statp;
       ad->dev = st->st_dev;
       ad->ino = st->st_ino;
       ad->fts_ent = ent;
@@ -89,7 +87,7 @@ enter_dir (FTS *fts, FTSENT *ent)
       /* See if we've already encountered this directory.
          This can happen when following symlinks as well as
          with a corrupted directory hierarchy. */
-      ad_from_table = hash_insert (fts->fts_cycle.ht, ad);
+      struct Active_dir *ad_from_table = hash_insert (fts->fts_cycle.ht, ad);
 
       if (ad_from_table != ad)
         {
@@ -128,10 +126,9 @@ leave_dir (FTS *fts, FTSENT *ent)
   if (fts->fts_options & (FTS_TIGHT_CYCLE_CHECK | FTS_LOGICAL))
     {
       struct Active_dir obj;
-      void *found;
       obj.dev = st->st_dev;
       obj.ino = st->st_ino;
-      found = hash_remove (fts->fts_cycle.ht, &obj);
+      void *found = hash_remove (fts->fts_cycle.ht, &obj);
       if (!found)
         abort ();
       free (found);
index 2adce8fa443fbf299dc44bcc9d720bb981b1ff02..e7e0be5a98a0c9210f65d4c1d39c10fff245dd9e 100644 (file)
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -361,13 +361,6 @@ fts_open (char * const *argv,
           register int options,
           int (*compar) (FTSENT const **, FTSENT const **))
 {
-        register FTS *sp;
-        register FTSENT *p, *root;
-        register size_t nitems;
-        FTSENT *parent = NULL;
-        FTSENT *tmp = NULL;     /* pacify gcc */
-        bool defer_stat;
-
         /* Options check. */
         if (options & ~FTS_OPTIONMASK) {
                 __set_errno (EINVAL);
@@ -383,7 +376,7 @@ fts_open (char * const *argv,
         }
 
         /* Allocate/initialize the stream */
-        sp = calloc (1, sizeof *sp);
+        register FTS *sp = calloc (1, sizeof *sp);
         if (sp == NULL)
                 return (NULL);
         sp->fts_compar = compar;
@@ -443,6 +436,7 @@ fts_open (char * const *argv,
         }
 
         /* Allocate/initialize root's parent. */
+        FTSENT *parent = NULL;
         if (*argv != NULL) {
                 if ((parent = fts_alloc(sp, "", 0)) == NULL)
                         goto mem2;
@@ -460,9 +454,12 @@ fts_open (char * const *argv,
            without genuine i-nodes.  If you specify FTS_DEFER_STAT along
            with a comparison function, that function must not access any
            data via the fts_statp pointer.  */
-        defer_stat = (compar == NULL || ISSET(FTS_DEFER_STAT));
+        bool defer_stat = (compar == NULL || ISSET(FTS_DEFER_STAT));
 
         /* Allocate/initialize root(s). */
+        register FTSENT *root;
+        register size_t nitems;
+        FTSENT *tmp = NULL;     /* pacify gcc */
         for (root = NULL, nitems = 0; *argv != NULL; ++argv, ++nitems) {
                 /* *Do* allow zero-length file names. */
                 size_t len = strlen(*argv);
@@ -477,7 +474,8 @@ fts_open (char * const *argv,
                         --len;
                   }
 
-                if ((p = fts_alloc(sp, *argv, len)) == NULL)
+                register FTSENT *p = fts_alloc(sp, *argv, len);
+                if (p == NULL)
                         goto mem3;
                 p->fts_level = FTS_ROOTLEVEL;
                 p->fts_parent = parent;
@@ -550,9 +548,6 @@ static void
 internal_function
 fts_load (FTS *sp, register FTSENT *p)
 {
-        register size_t len;
-        register char *cp;
-
         /*
          * Load the stream structure for the next traversal.  Since we don't
          * actually enter the directory until after the preorder visit, set
@@ -560,9 +555,10 @@ fts_load (FTS *sp, register FTSENT *p)
          * place and the user can access the first node.  From fts_open it's
          * known that the file name will fit.
          */
-        len = p->fts_pathlen = p->fts_namelen;
+        register size_t len = p->fts_pathlen = p->fts_namelen;
         memmove(sp->fts_path, p->fts_name, len + 1);
-        if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) {
+        register char *cp = strrchr(p->fts_name, '/');
+        if (cp && (cp != p->fts_name || cp[1])) {
                 len = strlen(++cp);
                 memmove(p->fts_name, cp, len + 1);
                 p->fts_namelen = len;
@@ -573,17 +569,15 @@ fts_load (FTS *sp, register FTSENT *p)
 int
 fts_close (FTS *sp)
 {
-        register FTSENT *freep, *p;
-        int saved_errno = 0;
-
         /*
          * This still works if we haven't read anything -- the dummy structure
          * points to the root list, so we step through to the end of the root
          * list which has a valid parent pointer.
          */
         if (sp->fts_cur) {
+                register FTSENT *p;
                 for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {
-                        freep = p;
+                        register FTSENT *freep = p;
                         p = p->fts_link != NULL ? p->fts_link : p->fts_parent;
                         free(freep);
                 }
@@ -596,6 +590,7 @@ fts_close (FTS *sp)
         free(sp->fts_array);
         free(sp->fts_path);
 
+        int saved_errno = 0;
         if (ISSET(FTS_CWDFD))
           {
             if (0 <= sp->fts_cwd_fd)
@@ -703,29 +698,29 @@ static fsword
 filesystem_type (FTSENT const *p, int fd)
 {
   FTS *sp = p->fts_fts;
-  Hash_table *h = sp->fts_leaf_optimization_works_ht;
-  struct dev_type *ent;
-  struct statfs fs_buf;
 
   /* If we're not in CWDFD mode, don't bother with this optimization,
      since the caller is not serious about performance.  */
   if (!ISSET (FTS_CWDFD))
     return 0;
 
+  Hash_table *h = sp->fts_leaf_optimization_works_ht;
   if (! h)
     h = sp->fts_leaf_optimization_works_ht
       = hash_initialize (DEV_TYPE_HT_INITIAL_SIZE, NULL, dev_type_hash,
                          dev_type_compare, free);
+
   if (h)
     {
       struct dev_type tmp;
       tmp.st_dev = p->fts_statp->st_dev;
-      ent = hash_lookup (h, &tmp);
+      struct dev_type *ent = hash_lookup (h, &tmp);
       if (ent)
         return ent->f_type;
     }
 
   /* Look-up failed.  Query directly and cache the result.  */
+  struct statfs fs_buf;
   if (fd < 0 || fstatfs (fd, &fs_buf) != 0)
     return 0;
 
@@ -737,7 +732,7 @@ filesystem_type (FTSENT const *p, int fd)
           t2->st_dev = p->fts_statp->st_dev;
           t2->f_type = fs_buf.f_type;
 
-          ent = hash_insert (h, t2);
+          struct dev_type *ent = hash_insert (h, t2);
           if (ent)
             fts_assert (ent == t2);
           else
@@ -837,19 +832,15 @@ leaf_optimization (_GL_UNUSED FTSENT const *p, _GL_UNUSED int dir_fd)
 FTSENT *
 fts_read (register FTS *sp)
 {
-        register FTSENT *p, *tmp;
-        register unsigned short int instr;
-        register char *t;
-
         /* If finished or unrecoverable error, return NULL. */
         if (sp->fts_cur == NULL || ISSET(FTS_STOP))
                 return (NULL);
 
         /* Set current node pointer. */
-        p = sp->fts_cur;
+        register FTSENT *p = sp->fts_cur;
 
         /* Save and zero out user instructions. */
-        instr = p->fts_instr;
+        register unsigned short int instr = p->fts_instr;
         p->fts_instr = FTS_NOINSTR;
 
         /* Any type of file may be re-visited; re-stat and re-turn. */
@@ -940,7 +931,8 @@ fts_read (register FTS *sp)
         }
 
         /* Move to the next node on this level. */
-next:   tmp = p;
+next: ;
+        register FTSENT *tmp = p;
 
         /* If we have so many directory entries that we're reading them
            in batches, and we've reached the end of the current batch,
@@ -1004,9 +996,11 @@ next:   tmp = p;
                         p->fts_instr = FTS_NOINSTR;
                 }
 
-name:           t = sp->fts_path + NAPPEND(p->fts_parent);
-                *t++ = '/';
-                memmove(t, p->fts_name, p->fts_namelen + 1);
+name:           {
+                  register char *t = sp->fts_path + NAPPEND(p->fts_parent);
+                  *t++ = '/';
+                  memmove(t, p->fts_name, p->fts_namelen + 1);
+                }
 check_for_dir:
                 sp->fts_cur = p;
                 if (p->fts_info == FTS_NSOK)
@@ -1115,16 +1109,13 @@ fts_set(_GL_UNUSED FTS *sp, FTSENT *p, int instr)
 FTSENT *
 fts_children (register FTS *sp, int instr)
 {
-        register FTSENT *p;
-        int fd;
-
         if (instr != 0 && instr != FTS_NAMEONLY) {
                 __set_errno (EINVAL);
                 return (NULL);
         }
 
         /* Set current node pointer. */
-        p = sp->fts_cur;
+        register FTSENT *p = sp->fts_cur;
 
         /*
          * Errno set to 0 so user can distinguish empty directory from
@@ -1169,7 +1160,8 @@ fts_children (register FTS *sp, int instr)
             ISSET(FTS_NOCHDIR))
                 return (sp->fts_child = fts_build(sp, instr));
 
-        if ((fd = diropen (sp, ".")) < 0)
+        int fd = diropen (sp, ".");
+        if (fd < 0)
                 return (sp->fts_child = NULL);
         sp->fts_child = fts_build(sp, instr);
         if (ISSET(FTS_CWDFD))
@@ -1272,24 +1264,13 @@ static FTSENT *
 internal_function
 fts_build (register FTS *sp, int type)
 {
-        register FTSENT *p, *head;
-        register size_t nitems;
-        FTSENT *tail;
-        int saved_errno;
-        bool descend;
-        bool doadjust;
-        ptrdiff_t level;
-        size_t len, maxlen, new_len;
-        char *cp;
-        int dir_fd;
         FTSENT *cur = sp->fts_cur;
         bool continue_readdir = !!cur->fts_dirp;
-        bool sort_by_inode = false;
-        size_t max_entries;
 
         /* When cur->fts_dirp is non-NULL, that means we should
            continue calling readdir on that existing DIR* pointer
            rather than opening a new one.  */
+        int dir_fd;
         if (continue_readdir)
           {
             DIR *dp = cur->fts_dirp;
@@ -1365,7 +1346,7 @@ fts_build (register FTS *sp, int type)
            function.  But when no such function is specified, we can read
            entries in batches that are large enough to help us with inode-
            sorting, yet not so large that we risk exhausting memory.  */
-        max_entries = sp->fts_compar ? SIZE_MAX : FTS_MAX_READDIR_ENTRIES;
+        size_t max_entries = sp->fts_compar ? SIZE_MAX : FTS_MAX_READDIR_ENTRIES;
 
         /*
          * If we're going to need to stat anything or we want to descend
@@ -1382,6 +1363,7 @@ fts_build (register FTS *sp, int type)
          * needed sorted entries or stat information, they had better be
          * checking FTS_NS on the returned nodes.
          */
+        bool descend;
         if (continue_readdir)
           {
             /* When resuming a short readdir run, we already have
@@ -1426,7 +1408,8 @@ fts_build (register FTS *sp, int type)
          * If not changing directories set a pointer so that can just append
          * each new component into the file name.
          */
-        len = NAPPEND(cur);
+        size_t len = NAPPEND(cur);
+        char *cp;
         if (ISSET(FTS_NOCHDIR)) {
                 cp = sp->fts_path + len;
                 *cp++ = '/';
@@ -1435,17 +1418,17 @@ fts_build (register FTS *sp, int type)
                 cp = NULL;
         }
         len++;
-        maxlen = sp->fts_pathlen - len;
+        size_t maxlen = sp->fts_pathlen - len;
 
-        level = cur->fts_level + 1;
+        ptrdiff_t level = cur->fts_level + 1;
 
         /* Read the directory, attaching each entry to the "link" pointer. */
-        doadjust = false;
-        head = NULL;
-        tail = NULL;
-        nitems = 0;
+        bool doadjust = false;
+        register FTSENT *head = NULL;
+        FTSENT *tail = NULL;
+        register size_t nitems = 0;
+        bool sort_by_inode = false;
         while (cur->fts_dirp) {
-                size_t d_namelen;
                 __set_errno (0);
                 struct dirent *dp = readdir(cur->fts_dirp);
                 if (dp == NULL) {
@@ -1469,8 +1452,8 @@ fts_build (register FTS *sp, int type)
                 if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
                         continue;
 
-                d_namelen = _D_EXACT_NAMLEN (dp);
-                p = fts_alloc (sp, dp->d_name, d_namelen);
+                size_t d_namelen = _D_EXACT_NAMLEN (dp);
+                register FTSENT *p = fts_alloc (sp, dp->d_name, d_namelen);
                 if (!p)
                         goto mem1;
                 if (d_namelen >= maxlen) {
@@ -1482,7 +1465,8 @@ fts_build (register FTS *sp, int type)
                                  * errno, free up the current structure and the
                                  * structures already allocated.
                                  */
-mem1:                           saved_errno = errno;
+mem1: ;
+                                int saved_errno = errno;
                                 free(p);
                                 fts_lfree(head);
                                 closedir_and_clear(cur->fts_dirp);
@@ -1500,7 +1484,7 @@ mem1:                           saved_errno = errno;
                         maxlen = sp->fts_pathlen - len;
                 }
 
-                new_len = len + d_namelen;
+                size_t new_len = len + d_namelen;
                 if (new_len < len) {
                         /*
                          * In the unlikely event that we would end up
@@ -1694,10 +1678,11 @@ find_matching_ancestor (FTSENT const *e_curr, struct Active_dir const *ad)
 void
 fts_cross_check (FTS const *sp)
 {
-  FTSENT const *ent = sp->fts_cur;
   if ( ! ISSET (FTS_TIGHT_CYCLE_CHECK))
     return;
 
+  FTSENT const *ent = sp->fts_cur;
+
   Dprintf (("fts-cross-check cur=%s\n", ent->fts_path));
   /* Make sure every parent dir is in the tree.  */
   for (FTSENT const *t = ent->fts_parent;
@@ -1739,12 +1724,12 @@ fd_ring_print (FTS const *sp, FILE *stream, char const *msg)
   if (!fts_debug)
     return;
   I_ring const *fd_ring = &sp->fts_fd_ring;
-  unsigned int i = fd_ring->ir_front;
   struct devino cwd = getdevino (sp->fts_cwd_fd);
   fprintf (stream, "=== %s ========== "PRINT_DEVINO"\n", msg, cwd.dev, cwd.ino);
   if (i_ring_empty (fd_ring))
     return;
 
+  unsigned int i = fd_ring->ir_front;
   while (true)
     {
       int fd = fd_ring->ir_data[i];
@@ -1809,12 +1794,12 @@ static unsigned short int
 internal_function
 fts_stat(FTS *sp, register FTSENT *p, bool follow)
 {
-        struct stat *sbp = p->fts_statp;
-
         if (ISSET (FTS_LOGICAL)
             || (ISSET (FTS_COMFOLLOW) && p->fts_level == FTS_ROOTLEVEL))
                 follow = true;
 
+        struct stat *sbp = p->fts_statp;
+
         /*
          * If doing a logical walk, or application requested FTS_FOLLOW, do
          * a stat(2).  If that fails, check for a nonexistent symlink.  If
@@ -1892,9 +1877,8 @@ fts_sort (FTS *sp, FTSENT *head, register size_t nitems)
          * 40 so don't realloc one entry at a time.
          */
         if (nitems > sp->fts_nitems) {
-                FTSENT **a;
-
                 sp->fts_nitems = nitems + 40;
+                FTSENT **a;
                 if (SIZE_MAX / sizeof *a < sp->fts_nitems
                     || ! (a = realloc (sp->fts_array,
                                        sp->fts_nitems * sizeof *a))) {
@@ -1918,15 +1902,13 @@ static FTSENT *
 internal_function
 fts_alloc (FTS *sp, const char *name, register size_t namelen)
 {
-        register FTSENT *p;
-        size_t len;
-
         /*
          * The file name is a variable length array.  Allocate the FTSENT
          * structure and the file name in one chunk.
          */
-        len = FLEXSIZEOF(FTSENT, fts_name, namelen + 1);
-        if ((p = malloc(len)) == NULL)
+        size_t len = FLEXSIZEOF(FTSENT, fts_name, namelen + 1);
+        register FTSENT *p = malloc(len);
+        if (p == NULL)
                 return (NULL);
 
         /* Copy the name and guarantee NUL termination. */
@@ -1949,10 +1931,10 @@ static void
 internal_function
 fts_lfree (register FTSENT *head)
 {
-        register FTSENT *p;
         int saved_errno = errno;
 
         /* Free a linked list of structures. */
+        register FTSENT *p;
         while ((p = head)) {
                 head = head->fts_link;
                 if (p->fts_dirp)
@@ -1974,7 +1956,6 @@ static bool
 internal_function
 fts_palloc (FTS *sp, size_t more)
 {
-        char *p;
         size_t new_len = sp->fts_pathlen + more + 256;
 
         /*
@@ -1987,7 +1968,7 @@ fts_palloc (FTS *sp, size_t more)
                 return false;
         }
         sp->fts_pathlen = new_len;
-        p = realloc(sp->fts_path, sp->fts_pathlen);
+        char *p = realloc(sp->fts_path, sp->fts_pathlen);
         if (p == NULL) {
                 free(sp->fts_path);
                 sp->fts_path = NULL;
@@ -2005,7 +1986,6 @@ static void
 internal_function
 fts_padjust (FTS *sp, FTSENT *head)
 {
-        FTSENT *p;
         char *addr = sp->fts_path;
 
         /* This code looks at bit-patterns of freed pointers to
@@ -2021,11 +2001,11 @@ fts_padjust (FTS *sp, FTSENT *head)
         (p)->fts_path = addr;                                           \
 } while (0)
         /* Adjust the current set of children. */
-        for (p = sp->fts_child; p; p = p->fts_link)
+        for (FTSENT *p = sp->fts_child; p; p = p->fts_link)
                 ADJUST(p);
 
         /* Adjust the rest of the tree, including the current level. */
-        for (p = head; p->fts_level >= FTS_ROOTLEVEL;) {
+        for (FTSENT *p = head; p->fts_level >= FTS_ROOTLEVEL;) {
                 ADJUST(p);
                 p = p->fts_link ? p->fts_link : p->fts_parent;
         }
@@ -2035,11 +2015,13 @@ static size_t
 internal_function _GL_ATTRIBUTE_PURE
 fts_maxarglen (char * const *argv)
 {
-        size_t len, max;
+        size_t max;
 
-        for (max = 0; *argv; ++argv)
-                if ((len = strlen(*argv)) > max)
+        for (max = 0; *argv; ++argv) {
+                size_t len = strlen(*argv);
+                if (len > max)
                         max = len;
+        }
         return (max + 1);
 }
 
@@ -2057,9 +2039,7 @@ internal_function
 fts_safe_changedir (FTS *sp, FTSENT *p, int fd, char const *dir)
 {
         fts_assert (0 <= fd || dir != NULL);
-        int ret;
         bool is_dotdot = dir && streq (dir, "..");
-        int newfd;
 
         /* This clause handles the unusual case in which FTS_NOCHDIR
            is specified, along with FTS_CWDFD.  In that case, there is
@@ -2092,7 +2072,7 @@ fts_safe_changedir (FTS *sp, FTSENT *p, int fd, char const *dir)
               }
           }
 
-        newfd = fd;
+        int newfd = fd;
         if (fd < 0 && (newfd = diropen (sp, dir)) < 0)
           return -1;
 
@@ -2103,6 +2083,7 @@ fts_safe_changedir (FTS *sp, FTSENT *p, int fd, char const *dir)
            name "..", O_NOFOLLOW can't help.  In general, when the target is
            not "..", diropen's use of O_NOFOLLOW ensures we don't mistakenly
            follow a symlink, so we can avoid the expense of this fstat.  */
+        int ret;
         if (ISSET(FTS_LOGICAL) || ! HAVE_WORKING_O_NOFOLLOW
             || (dir && streq (dir, "..")))
           {
index 71e55f5de8b438312173131a83ec1c7758aaa36a..1cb2f0b502ae7b63603428d51202cc4a198406d8 100644 (file)
@@ -33,14 +33,13 @@ off64_t
 fzprintf (FILE *fp, const char *format, ...)
 {
   va_list args;
+  va_start (args, format);
+
   char buf[2000];
-  char *output;
-  size_t len;
   size_t lenbuf = sizeof (buf);
+  char *output = vasnprintf (buf, &lenbuf, format, args);
+  size_t len = lenbuf;
 
-  va_start (args, format);
-  output = vasnprintf (buf, &lenbuf, format, args);
-  len = lenbuf;
   va_end (args);
 
   if (!output)
index 326dc9057ac0b3b8afc3b9e1678963998ecfbf6c..590c3f6f719df426331019d52cdd09ec633f31d0 100644 (file)
@@ -171,16 +171,14 @@ Gc_rc
 gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode,
                 gc_cipher_handle * outhandle)
 {
-  _gc_cipher_ctx *ctx;
-  Gc_rc rc = GC_OK;
-
-  ctx = calloc (1, sizeof (*ctx));
+  _gc_cipher_ctx *ctx = calloc (1, sizeof (*ctx));
   if (!ctx)
     return GC_MALLOC_ERROR;
 
   ctx->alg = alg;
   ctx->mode = mode;
 
+  Gc_rc rc = GC_OK;
   switch (alg)
     {
 #if GNULIB_GC_ARCTWO
@@ -285,25 +283,31 @@ gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char *key)
     case GC_AES192:
     case GC_AES256:
       {
-        rijndael_rc rc;
         char keyMaterial[RIJNDAEL_MAX_KEY_SIZE + 1];
 
         for (size_t i = 0; i < keylen; i++)
           sprintf (&keyMaterial[2 * i], "%02x", key[i] & 0xFFU);
 
-        rc = rijndaelMakeKey (&ctx->aesEncKey, RIJNDAEL_DIR_ENCRYPT,
-                              keylen * 8, keyMaterial);
-        if (rc < 0)
-          return GC_INVALID_CIPHER;
-
-        rc = rijndaelMakeKey (&ctx->aesDecKey, RIJNDAEL_DIR_DECRYPT,
-                              keylen * 8, keyMaterial);
-        if (rc < 0)
-          return GC_INVALID_CIPHER;
-
-        rc = rijndaelCipherInit (&ctx->aesContext, RIJNDAEL_MODE_ECB, NULL);
-        if (rc < 0)
-          return GC_INVALID_CIPHER;
+        {
+          rijndael_rc rc =
+            rijndaelMakeKey (&ctx->aesEncKey, RIJNDAEL_DIR_ENCRYPT,
+                             keylen * 8, keyMaterial);
+          if (rc < 0)
+            return GC_INVALID_CIPHER;
+        }
+        {
+          rijndael_rc rc =
+            rijndaelMakeKey (&ctx->aesDecKey, RIJNDAEL_DIR_DECRYPT,
+                             keylen * 8, keyMaterial);
+          if (rc < 0)
+            return GC_INVALID_CIPHER;
+        }
+        {
+          rijndael_rc rc =
+            rijndaelCipherInit (&ctx->aesContext, RIJNDAEL_MODE_ECB, NULL);
+          if (rc < 0)
+            return GC_INVALID_CIPHER;
+        }
       }
       break;
 #endif
@@ -342,14 +346,13 @@ gc_cipher_setiv (gc_cipher_handle handle, size_t ivlen, const char *iv)
 
         case GC_CBC:
           {
-            rijndael_rc rc;
             char ivMaterial[2 * RIJNDAEL_MAX_IV_SIZE + 1];
-
             for (size_t i = 0; i < ivlen; i++)
               sprintf (&ivMaterial[2 * i], "%02x", iv[i] & 0xFFU);
 
-            rc = rijndaelCipherInit (&ctx->aesContext, RIJNDAEL_MODE_CBC,
-                                     ivMaterial);
+            rijndael_rc rc =
+              rijndaelCipherInit (&ctx->aesContext, RIJNDAEL_MODE_CBC,
+                                  ivMaterial);
             if (rc < 0)
               return GC_INVALID_CIPHER;
           }
@@ -420,10 +423,9 @@ gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char *data)
     case GC_AES192:
     case GC_AES256:
       {
-        int nblocks;
-
-        nblocks = rijndaelBlockEncrypt (&ctx->aesContext, &ctx->aesEncKey,
-                                        data, 8 * len, data);
+        int nblocks =
+          rijndaelBlockEncrypt (&ctx->aesContext, &ctx->aesEncKey,
+                                data, 8 * len, data);
         if (nblocks < 0)
           return GC_INVALID_CIPHER;
       }
@@ -491,10 +493,9 @@ gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char *data)
     case GC_AES192:
     case GC_AES256:
       {
-        int nblocks;
-
-        nblocks = rijndaelBlockDecrypt (&ctx->aesContext, &ctx->aesDecKey,
-                                        data, 8 * len, data);
+        int nblocks =
+          rijndaelBlockDecrypt (&ctx->aesContext, &ctx->aesDecKey,
+                                data, 8 * len, data);
         if (nblocks < 0)
           return GC_INVALID_CIPHER;
       }
@@ -553,19 +554,17 @@ typedef struct _gc_hash_ctx
 Gc_rc
 gc_hash_open (Gc_hash hash, Gc_hash_mode mode, gc_hash_handle * outhandle)
 {
-  _gc_hash_ctx *ctx;
-  Gc_rc rc = GC_OK;
-
   if (mode != 0)
     return GC_INVALID_HASH;
 
-  ctx = calloc (1, sizeof (*ctx));
+  _gc_hash_ctx *ctx = calloc (1, sizeof (*ctx));
   if (!ctx)
     return GC_MALLOC_ERROR;
 
   ctx->alg = hash;
   ctx->mode = mode;
 
+  Gc_rc rc = GC_OK;
   switch (hash)
     {
 #if GNULIB_GC_MD2
@@ -628,9 +627,7 @@ Gc_rc
 gc_hash_clone (gc_hash_handle handle, gc_hash_handle * outhandle)
 {
   _gc_hash_ctx *in = handle;
-  _gc_hash_ctx *out;
-
-  out = calloc (1, sizeof (*out));
+  _gc_hash_ctx *out = calloc (1, sizeof (*out));
   if (!out)
     return GC_MALLOC_ERROR;
 
index 4881f02cf454d36d8edba56a6276ca3fabda183e..f583faf8613a75d7c0e30e22ebbef8fe37101710 100644 (file)
 Gc_rc
 gc_init (void)
 {
-  gcry_error_t err;
-
-  err = gcry_control (GCRYCTL_ANY_INITIALIZATION_P);
-  if (err == GPG_ERR_NO_ERROR)
+  if (gcry_control (GCRYCTL_ANY_INITIALIZATION_P) == GPG_ERR_NO_ERROR)
     {
       if (gcry_control (GCRYCTL_DISABLE_SECMEM, NULL, 0))
         return GC_INIT_ERROR;
@@ -59,8 +56,8 @@ gc_init (void)
       if (gcry_check_version (MIN_GCRYPT_VERSION) == NULL)
         return GC_INIT_ERROR;
 
-      err = gcry_control (GCRYCTL_INITIALIZATION_FINISHED, NULL, 0);
-      if (err != GPG_ERR_NO_ERROR)
+      if (gcry_control (GCRYCTL_INITIALIZATION_FINISHED, NULL, 0)
+          != GPG_ERR_NO_ERROR)
         return GC_INIT_ERROR;
     }
 
@@ -118,9 +115,7 @@ Gc_rc
 gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode,
                 gc_cipher_handle * outhandle)
 {
-  int gcryalg, gcrymode;
-  gcry_error_t err;
-
+  int gcryalg;
   switch (alg)
     {
     case GC_AES128:
@@ -166,6 +161,7 @@ gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode,
       return GC_INVALID_CIPHER;
     }
 
+  int gcrymode;
   switch (mode)
     {
     case GC_ECB:
@@ -184,8 +180,8 @@ gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode,
       return GC_INVALID_CIPHER;
     }
 
-  err = gcry_cipher_open ((gcry_cipher_hd_t *) outhandle,
-                          gcryalg, gcrymode, 0);
+  gcry_error_t err = gcry_cipher_open ((gcry_cipher_hd_t *) outhandle,
+                                       gcryalg, gcrymode, 0);
   if (gcry_err_code (err))
     return GC_INVALID_CIPHER;
 
@@ -195,9 +191,7 @@ gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode,
 Gc_rc
 gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char *key)
 {
-  gcry_error_t err;
-
-  err = gcry_cipher_setkey ((gcry_cipher_hd_t) handle, key, keylen);
+  gcry_error_t err = gcry_cipher_setkey ((gcry_cipher_hd_t) handle, key, keylen);
   if (gcry_err_code (err))
     return GC_INVALID_CIPHER;
 
@@ -207,9 +201,7 @@ gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char *key)
 Gc_rc
 gc_cipher_setiv (gc_cipher_handle handle, size_t ivlen, const char *iv)
 {
-  gcry_error_t err;
-
-  err = gcry_cipher_setiv ((gcry_cipher_hd_t) handle, iv, ivlen);
+  gcry_error_t err = gcry_cipher_setiv ((gcry_cipher_hd_t) handle, iv, ivlen);
   if (gcry_err_code (err))
     return GC_INVALID_CIPHER;
 
@@ -267,18 +259,16 @@ typedef struct _gc_hash_ctx {
 Gc_rc
 gc_hash_open (Gc_hash hash, Gc_hash_mode mode, gc_hash_handle * outhandle)
 {
-  _gc_hash_ctx *ctx;
-  int gcryalg = 0, gcrymode = 0;
-  gcry_error_t err;
-  Gc_rc rc = GC_OK;
-
-  ctx = calloc (1, sizeof (*ctx));
+  _gc_hash_ctx *ctx = calloc (1, sizeof (*ctx));
   if (!ctx)
     return GC_MALLOC_ERROR;
 
   ctx->alg = hash;
   ctx->mode = mode;
 
+  Gc_rc rc = GC_OK;
+
+  int gcryalg = 0;
   switch (hash)
     {
 #if GNULIB_GC_MD2
@@ -336,6 +326,7 @@ gc_hash_open (Gc_hash hash, Gc_hash_mode mode, gc_hash_handle * outhandle)
       rc = GC_INVALID_HASH;
     }
 
+  int gcrymode = 0;
   switch (mode)
     {
     case GC_NULL:
@@ -352,7 +343,7 @@ gc_hash_open (Gc_hash hash, Gc_hash_mode mode, gc_hash_handle * outhandle)
 
   if (rc == GC_OK && gcryalg != GCRY_MD_NONE)
     {
-      err = gcry_md_open (&ctx->gch, gcryalg, gcrymode);
+      gcry_error_t err = gcry_md_open (&ctx->gch, gcryalg, gcrymode);
       if (gcry_err_code (err))
         rc = GC_INVALID_HASH;
     }
@@ -369,16 +360,14 @@ Gc_rc
 gc_hash_clone (gc_hash_handle handle, gc_hash_handle * outhandle)
 {
   _gc_hash_ctx *in = handle;
-  _gc_hash_ctx *out;
-  int err;
+  _gc_hash_ctx *out = calloc (1, sizeof (*out));
 
-  out = calloc (1, sizeof (*out));
   if (!out)
     return GC_MALLOC_ERROR;
 
   memcpy (out, in, sizeof (*out));
 
-  err = gcry_md_copy (&out->gch, in->gch);
+  int err = gcry_md_copy (&out->gch, in->gch);
   if (err)
     {
       free (out);
@@ -478,8 +467,8 @@ const char *
 gc_hash_read (gc_hash_handle handle)
 {
   _gc_hash_ctx *ctx = handle;
-  const char *digest;
 
+  const char *digest;
 #if GNULIB_GC_MD2
   if (ctx->alg == GC_MD2)
     {
@@ -617,19 +606,16 @@ Gc_rc
 gc_md4 (const void *in, size_t inlen, void *resbuf)
 {
   size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_MD4);
-  gcry_md_hd_t hd;
-  gpg_error_t err;
-  unsigned char *p;
-
   assert (outlen == GC_MD4_DIGEST_SIZE);
 
-  err = gcry_md_open (&hd, GCRY_MD_MD4, 0);
+  gcry_md_hd_t hd;
+  gpg_error_t err = gcry_md_open (&hd, GCRY_MD_MD4, 0);
   if (err != GPG_ERR_NO_ERROR)
     return GC_INVALID_HASH;
 
   gcry_md_write (hd, in, inlen);
 
-  p = gcry_md_read (hd, GCRY_MD_MD4);
+  unsigned char *p = gcry_md_read (hd, GCRY_MD_MD4);
   if (p == NULL)
     {
       gcry_md_close (hd);
@@ -649,19 +635,16 @@ Gc_rc
 gc_md5 (const void *in, size_t inlen, void *resbuf)
 {
   size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_MD5);
-  gcry_md_hd_t hd;
-  gpg_error_t err;
-  unsigned char *p;
-
   assert (outlen == GC_MD5_DIGEST_SIZE);
 
-  err = gcry_md_open (&hd, GCRY_MD_MD5, 0);
+  gcry_md_hd_t hd;
+  gpg_error_t err = gcry_md_open (&hd, GCRY_MD_MD5, 0);
   if (err != GPG_ERR_NO_ERROR)
     return GC_INVALID_HASH;
 
   gcry_md_write (hd, in, inlen);
 
-  p = gcry_md_read (hd, GCRY_MD_MD5);
+  unsigned char *p = gcry_md_read (hd, GCRY_MD_MD5);
   if (p == NULL)
     {
       gcry_md_close (hd);
@@ -681,19 +664,16 @@ Gc_rc
 gc_sha1 (const void *in, size_t inlen, void *resbuf)
 {
   size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_SHA1);
-  gcry_md_hd_t hd;
-  gpg_error_t err;
-  unsigned char *p;
-
   assert (outlen == GC_SHA1_DIGEST_SIZE);
 
-  err = gcry_md_open (&hd, GCRY_MD_SHA1, 0);
+  gcry_md_hd_t hd;
+  gpg_error_t err = gcry_md_open (&hd, GCRY_MD_SHA1, 0);
   if (err != GPG_ERR_NO_ERROR)
     return GC_INVALID_HASH;
 
   gcry_md_write (hd, in, inlen);
 
-  p = gcry_md_read (hd, GCRY_MD_SHA1);
+  unsigned char *p = gcry_md_read (hd, GCRY_MD_SHA1);
   if (p == NULL)
     {
       gcry_md_close (hd);
@@ -713,19 +693,16 @@ Gc_rc
 gc_sha256 (const void *in, size_t inlen, void *resbuf)
 {
   size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_SHA256);
-  gcry_md_hd_t hd;
-  gpg_error_t err;
-  unsigned char *p;
-
   assert (outlen == GC_SHA256_DIGEST_SIZE);
 
-  err = gcry_md_open (&hd, GCRY_MD_SHA256, 0);
+  gcry_md_hd_t hd;
+  gpg_error_t err = gcry_md_open (&hd, GCRY_MD_SHA256, 0);
   if (err != GPG_ERR_NO_ERROR)
     return GC_INVALID_HASH;
 
   gcry_md_write (hd, in, inlen);
 
-  p = gcry_md_read (hd, GCRY_MD_SHA256);
+  unsigned char *p = gcry_md_read (hd, GCRY_MD_SHA256);
   if (p == NULL)
     {
       gcry_md_close (hd);
@@ -745,19 +722,16 @@ Gc_rc
 gc_sha512 (const void *in, size_t inlen, void *resbuf)
 {
   size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_SHA512);
-  gcry_md_hd_t hd;
-  gpg_error_t err;
-  unsigned char *p;
-
   assert (outlen == GC_SHA512_DIGEST_SIZE);
 
-  err = gcry_md_open (&hd, GCRY_MD_SHA512, 0);
+  gcry_md_hd_t hd;
+  gpg_error_t err = gcry_md_open (&hd, GCRY_MD_SHA512, 0);
   if (err != GPG_ERR_NO_ERROR)
     return GC_INVALID_HASH;
 
   gcry_md_write (hd, in, inlen);
 
-  p = gcry_md_read (hd, GCRY_MD_SHA512);
+  unsigned char *p = gcry_md_read (hd, GCRY_MD_SHA512);
   if (p == NULL)
     {
       gcry_md_close (hd);
@@ -781,19 +755,16 @@ gc_sm3  (const void *in, size_t inlen, void *resbuf)
   return GC_OK;
 # else
   size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_SM3);
-  gcry_md_hd_t hd;
-  gpg_error_t err;
-  unsigned char *p;
-
   assert (outlen == GC_SM3_DIGEST_SIZE);
 
-  err = gcry_md_open (&hd, GCRY_MD_SM3, 0);
+  gcry_md_hd_t hd;
+  gpg_error_t err = gcry_md_open (&hd, GCRY_MD_SM3, 0);
   if (err != GPG_ERR_NO_ERROR)
     return GC_INVALID_HASH;
 
   gcry_md_write (hd, in, inlen);
 
-  p = gcry_md_read (hd, GCRY_MD_SM3);
+  unsigned char *p = gcry_md_read (hd, GCRY_MD_SM3);
   if (p == NULL)
     {
       gcry_md_close (hd);
@@ -815,18 +786,13 @@ gc_hmac_md5 (const void *key, size_t keylen,
              const void *in, size_t inlen, char *resbuf)
 {
   size_t hlen = gcry_md_get_algo_dlen (GCRY_MD_MD5);
-  gcry_md_hd_t mdh;
-  unsigned char *hash;
-  gpg_error_t err;
-
   assert (hlen == GC_MD5_DIGEST_SIZE);
 
-  err = gcry_md_open (&mdh, GCRY_MD_MD5, GCRY_MD_FLAG_HMAC);
-  if (err != GPG_ERR_NO_ERROR)
+  gcry_md_hd_t mdh;
+  if (gcry_md_open (&mdh, GCRY_MD_MD5, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR)
     return GC_INVALID_HASH;
 
-  err = gcry_md_setkey (mdh, key, keylen);
-  if (err != GPG_ERR_NO_ERROR)
+  if (gcry_md_setkey (mdh, key, keylen) != GPG_ERR_NO_ERROR)
     {
       gcry_md_close (mdh);
       return GC_INVALID_HASH;
@@ -834,7 +800,7 @@ gc_hmac_md5 (const void *key, size_t keylen,
 
   gcry_md_write (mdh, in, inlen);
 
-  hash = gcry_md_read (mdh, GCRY_MD_MD5);
+  unsigned char *hash = gcry_md_read (mdh, GCRY_MD_MD5);
   if (hash == NULL)
     {
       gcry_md_close (mdh);
@@ -855,18 +821,13 @@ gc_hmac_sha1 (const void *key, size_t keylen,
               const void *in, size_t inlen, char *resbuf)
 {
   size_t hlen = gcry_md_get_algo_dlen (GCRY_MD_SHA1);
-  gcry_md_hd_t mdh;
-  unsigned char *hash;
-  gpg_error_t err;
-
   assert (hlen == GC_SHA1_DIGEST_SIZE);
 
-  err = gcry_md_open (&mdh, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC);
-  if (err != GPG_ERR_NO_ERROR)
+  gcry_md_hd_t mdh;
+  if (gcry_md_open (&mdh, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR)
     return GC_INVALID_HASH;
 
-  err = gcry_md_setkey (mdh, key, keylen);
-  if (err != GPG_ERR_NO_ERROR)
+  if (gcry_md_setkey (mdh, key, keylen) != GPG_ERR_NO_ERROR)
     {
       gcry_md_close (mdh);
       return GC_INVALID_HASH;
@@ -874,7 +835,7 @@ gc_hmac_sha1 (const void *key, size_t keylen,
 
   gcry_md_write (mdh, in, inlen);
 
-  hash = gcry_md_read (mdh, GCRY_MD_SHA1);
+  unsigned char *hash = gcry_md_read (mdh, GCRY_MD_SHA1);
   if (hash == NULL)
     {
       gcry_md_close (mdh);
@@ -895,18 +856,13 @@ gc_hmac_sha256 (const void *key, size_t keylen,
              const void *in, size_t inlen, char *resbuf)
 {
   size_t hlen = gcry_md_get_algo_dlen (GCRY_MD_SHA256);
-  gcry_md_hd_t mdh;
-  unsigned char *hash;
-  gpg_error_t err;
-
   assert (hlen == GC_SHA256_DIGEST_SIZE);
 
-  err = gcry_md_open (&mdh, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC);
-  if (err != GPG_ERR_NO_ERROR)
+  gcry_md_hd_t mdh;
+  if (gcry_md_open (&mdh, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR)
     return GC_INVALID_HASH;
 
-  err = gcry_md_setkey (mdh, key, keylen);
-  if (err != GPG_ERR_NO_ERROR)
+  if (gcry_md_setkey (mdh, key, keylen) != GPG_ERR_NO_ERROR)
     {
       gcry_md_close (mdh);
       return GC_INVALID_HASH;
@@ -914,7 +870,7 @@ gc_hmac_sha256 (const void *key, size_t keylen,
 
   gcry_md_write (mdh, in, inlen);
 
-  hash = gcry_md_read (mdh, GCRY_MD_SHA256);
+  unsigned char *hash = gcry_md_read (mdh, GCRY_MD_SHA256);
   if (hash == NULL)
     {
       gcry_md_close (mdh);
@@ -935,18 +891,13 @@ gc_hmac_sha512 (const void *key, size_t keylen,
               const void *in, size_t inlen, char *resbuf)
 {
   size_t hlen = gcry_md_get_algo_dlen (GCRY_MD_SHA512);
-  gcry_md_hd_t mdh;
-  unsigned char *hash;
-  gpg_error_t err;
-
   assert (hlen == GC_SHA512_DIGEST_SIZE);
 
-  err = gcry_md_open (&mdh, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC);
-  if (err != GPG_ERR_NO_ERROR)
+  gcry_md_hd_t mdh;
+  if (gcry_md_open (&mdh, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC) != GPG_ERR_NO_ERROR)
     return GC_INVALID_HASH;
 
-  err = gcry_md_setkey (mdh, key, keylen);
-  if (err != GPG_ERR_NO_ERROR)
+  if (gcry_md_setkey (mdh, key, keylen) != GPG_ERR_NO_ERROR)
     {
       gcry_md_close (mdh);
       return GC_INVALID_HASH;
@@ -954,7 +905,7 @@ gc_hmac_sha512 (const void *key, size_t keylen,
 
   gcry_md_write (mdh, in, inlen);
 
-  hash = gcry_md_read (mdh, GCRY_MD_SHA512);
+  unsigned char *hash = gcry_md_read (mdh, GCRY_MD_SHA512);
   if (hash == NULL)
     {
       gcry_md_close (mdh);
index 33cd2181ddd6c0e9894a8fdd99f61f757cd0049c..b5cf4fdca795e1be696d10a97e86c665a3b3ef7c 100644 (file)
@@ -33,14 +33,6 @@ gc_pbkdf2_prf (gc_prf_func prf, size_t hLen,
                unsigned int c,
                char *DK, size_t dkLen)
 {
-  char U[GC_MAX_DIGEST_SIZE];
-  char T[GC_MAX_DIGEST_SIZE];
-  unsigned int l;
-  unsigned int r;
-  int rc;
-  char *tmp;
-  size_t tmplen = Slen + 4;
-
   if (c == 0)
     return GC_PKCS5_INVALID_ITERATION_COUNT;
 
@@ -50,15 +42,19 @@ gc_pbkdf2_prf (gc_prf_func prf, size_t hLen,
   if (dkLen > 4294967295U)
     return GC_PKCS5_DERIVED_KEY_TOO_LONG;
 
-  l = ((dkLen - 1) / hLen) + 1;
-  r = dkLen - (l - 1) * hLen;
+  unsigned int l = ((dkLen - 1) / hLen) + 1;
+  unsigned int r = dkLen - (l - 1) * hLen;
 
-  tmp = malloc (tmplen);
+  size_t tmplen = Slen + 4;
+  char *tmp = malloc (tmplen);
   if (tmp == NULL)
     return GC_MALLOC_ERROR;
 
   memcpy (tmp, S, Slen);
 
+  char U[GC_MAX_DIGEST_SIZE];
+  char T[GC_MAX_DIGEST_SIZE];
+  int rc;
   for (unsigned int i = 1; i <= l; i++)
     {
       memset (T, 0, hLen);
index 67f9ec20169026d4357990c837e1b245860e3fe1..13bf40d8cd319ca24ab362a11bab9cd94969a0e7 100644 (file)
@@ -189,8 +189,6 @@ getfield (FILE *stream, char *buffer, int delim)
 static void
 fill_attributes (const char *unicodedata_filename)
 {
-  unsigned int j;
-  FILE *stream;
   char field0[FIELDLEN];
   char field1[FIELDLEN];
   char field2[FIELDLEN];
@@ -211,7 +209,7 @@ fill_attributes (const char *unicodedata_filename)
   for (unsigned int i = 0; i < 0x110000; i++)
     unicode_attributes[i].name = NULL;
 
-  stream = fopen (unicodedata_filename, "r");
+  FILE *stream = fopen (unicodedata_filename, "r");
   if (stream == NULL)
     {
       fprintf (stderr, "error during fopen of '%s'\n", unicodedata_filename);
@@ -283,7 +281,7 @@ fill_attributes (const char *unicodedata_filename)
               exit (1);
             }
           field1[strlen (field1) - 7] = '\0';
-          j = strtoul (field0, NULL, 16);
+          unsigned int j = strtoul (field0, NULL, 16);
           for (; i <= j; i++)
             fill_attribute (i, field1+1, field2, field3, field4, field5,
                                field6, field7, field8, field9, field10,
@@ -681,9 +679,7 @@ is_category_Cn (unsigned int ch)
 static void
 debug_output_predicate (const char *filename, bool (*predicate) (unsigned int))
 {
-  FILE *stream;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -701,11 +697,10 @@ debug_output_predicate (const char *filename, bool (*predicate) (unsigned int))
     if (predicate (ch))
       {
         unsigned int first = ch;
-        unsigned int last;
 
         while (ch + 1 < 0x110000 && predicate (ch + 1))
           ch++;
-        last = ch;
+        unsigned int last = ch;
         if (first < last)
           fprintf (stream, "0x%04X..0x%04X\n", first, last);
         else
@@ -724,10 +719,7 @@ debug_output_predicate (const char *filename, bool (*predicate) (unsigned int))
 static void
 output_predicate_test (const char *filename, bool (*predicate) (unsigned int), const char *expression)
 {
-  FILE *stream;
-  bool need_comma;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -743,16 +735,15 @@ output_predicate_test (const char *filename, bool (*predicate) (unsigned int), c
   fprintf (stream, "#include \"test-predicate-part1.h\"\n");
   fprintf (stream, "\n");
 
-  need_comma = false;
+  bool need_comma = false;
   for (unsigned int ch = 0; ch < 0x110000; ch++)
     if (predicate (ch))
       {
         unsigned int first = ch;
-        unsigned int last;
 
         while (ch + 1 < 0x110000 && predicate (ch + 1))
           ch++;
-        last = ch;
+        unsigned int last = ch;
         if (need_comma)
           fprintf (stream, ",\n");
         fprintf (stream, "    { 0x%04X, 0x%04X }", first, last);
@@ -782,11 +773,7 @@ output_predicate_test (const char *filename, bool (*predicate) (unsigned int), c
 static void
 output_predicate (const char *filename, bool (*predicate) (unsigned int), const char *name, const char *comment, const char *version)
 {
-  FILE *stream;
-  struct predicate_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -807,6 +794,7 @@ output_predicate (const char *filename, bool (*predicate) (unsigned int), const
                           || streq (filename, "uniwidth/width2.h"));
   fprintf (stream, "\n");
 
+  struct predicate_table t;
   t.p = 4; /* or: 5 */
   t.q = 7; /* or: 6 */
   predicate_table_init (&t);
@@ -818,12 +806,12 @@ output_predicate (const char *filename, bool (*predicate) (unsigned int), const
   predicate_table_finalize (&t);
 
   /* Offsets in t.result, in memory of this process.  */
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -849,10 +837,9 @@ output_predicate (const char *filename, bool (*predicate) (unsigned int), const
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 1) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -869,10 +856,9 @@ output_predicate (const char *filename, bool (*predicate) (unsigned int), const
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 1) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -1096,12 +1082,7 @@ general_category_byname (const char *category_name)
 static void
 output_category (const char *filename, const char *version)
 {
-  FILE *stream;
-  struct category_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-  uint16_t *level3_packed;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -1119,6 +1100,7 @@ output_category (const char *filename, const char *version)
   output_library_license (stream, true);
   fprintf (stream, "\n");
 
+  struct category_table t;
   t.p = 7;
   t.q = 9;
   category_table_init (&t);
@@ -1126,8 +1108,6 @@ output_category (const char *filename, const char *version)
   for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value;
-      unsigned int log2_value;
-
       if (is_category_Cs (ch))
         value = UC_CATEGORY_MASK_Cs;
       else if (unicode_attributes[ch].name != NULL)
@@ -1138,6 +1118,7 @@ output_category (const char *filename, const char *version)
       /* Now value should contain exactly one bit.  */
       assert (value != 0 && (value & (value - 1)) == 0);
 
+      unsigned int log2_value;
       for (log2_value = 0; value > 1; value >>= 1, log2_value++);
 
       assert (log2_value <= 0x1f);
@@ -1148,12 +1129,12 @@ output_category (const char *filename, const char *version)
   category_table_finalize (&t);
 
   /* Offsets in t.result, in memory of this process.  */
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -1176,10 +1157,9 @@ output_category (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -1196,10 +1176,9 @@ output_category (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       /* To make the level2 values fit in 16 bits, we use 'unsigned short'
          instead of 'short' and add 1 to each value.  */
       if (offset == 0)
@@ -1215,7 +1194,7 @@ output_category (const char *filename, const char *version)
   fprintf (stream, " },\n");
   /* Pack the level3 array.  Each entry needs 5 bits only.  Use 16-bit units,
      not 32-bit units, in order to make the lookup function easier.  */
-  level3_packed =
+  uint16_t *level3_packed =
     (uint16_t *)
     calloc ((t.level3_size << t.p) * 5 / 16 + 1, sizeof (uint16_t));
   for (unsigned int i = 0; i < t.level3_size << t.p; i++)
@@ -1269,11 +1248,7 @@ output_category (const char *filename, const char *version)
 static void
 output_combclass (const char *filename, const char *version)
 {
-  FILE *stream;
-  struct combclass_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -1291,6 +1266,7 @@ output_combclass (const char *filename, const char *version)
   output_library_license (stream, true);
   fprintf (stream, "\n");
 
+  struct combclass_table t;
   t.p = 7;
   t.q = 9;
   combclass_table_init (&t);
@@ -1306,12 +1282,12 @@ output_combclass (const char *filename, const char *version)
   combclass_table_finalize (&t);
 
   /* Offsets in t.result, in memory of this process.  */
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -1333,10 +1309,9 @@ output_combclass (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -1353,10 +1328,9 @@ output_combclass (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -1641,12 +1615,7 @@ get_bidi_category (unsigned int ch)
 static void
 output_bidi_category (const char *filename, const char *version)
 {
-  FILE *stream;
-  struct bidi_category_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-  uint16_t *level3_packed;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -1664,6 +1633,7 @@ output_bidi_category (const char *filename, const char *version)
   output_library_license (stream, true);
   fprintf (stream, "\n");
 
+  struct bidi_category_table t;
   t.p = 7;
   t.q = 9;
   bidi_category_table_init (&t);
@@ -1680,12 +1650,12 @@ output_bidi_category (const char *filename, const char *version)
   bidi_category_table_finalize (&t);
 
   /* Offsets in t.result, in memory of this process.  */
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -1708,10 +1678,9 @@ output_bidi_category (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -1728,10 +1697,9 @@ output_bidi_category (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -1745,7 +1713,7 @@ output_bidi_category (const char *filename, const char *version)
   fprintf (stream, " },\n");
   /* Pack the level3 array.  Each entry needs 5 bits only.  Use 16-bit units,
      not 32-bit units, in order to make the lookup function easier.  */
-  level3_packed =
+  uint16_t *level3_packed =
     (uint16_t *)
     calloc ((t.level3_size << t.p) * 5 / 16 + 1, sizeof (uint16_t));
   for (unsigned int i = 0; i < t.level3_size << t.p; i++)
@@ -1807,10 +1775,7 @@ get_decdigit_value (unsigned int ch)
 static void
 output_decimal_digit_test (const char *filename, const char *version)
 {
-  FILE *stream;
-  bool need_comma;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -1828,7 +1793,7 @@ output_decimal_digit_test (const char *filename, const char *version)
   output_tests_license (stream);
   fprintf (stream, "\n");
 
-  need_comma = false;
+  bool need_comma = false;
   for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value = get_decdigit_value (ch);
@@ -1857,11 +1822,7 @@ output_decimal_digit_test (const char *filename, const char *version)
 static void
 output_decimal_digit (const char *filename, const char *version)
 {
-  FILE *stream;
-  struct decdigit_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -1879,6 +1840,7 @@ output_decimal_digit (const char *filename, const char *version)
   output_library_license (stream, false);
   fprintf (stream, "\n");
 
+  struct decdigit_table t;
   t.p = 7;
   t.q = 9;
   decdigit_table_init (&t);
@@ -1895,12 +1857,12 @@ output_decimal_digit (const char *filename, const char *version)
   decdigit_table_finalize (&t);
 
   /* Offsets in t.result, in memory of this process.  */
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -1923,10 +1885,9 @@ output_decimal_digit (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -1943,10 +1904,9 @@ output_decimal_digit (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -2002,10 +1962,7 @@ get_digit_value (unsigned int ch)
 static void
 output_digit_test (const char *filename, const char *version)
 {
-  FILE *stream;
-  bool need_comma;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -2023,7 +1980,7 @@ output_digit_test (const char *filename, const char *version)
   output_tests_license (stream);
   fprintf (stream, "\n");
 
-  need_comma = false;
+  bool need_comma = false;
   for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value = get_digit_value (ch);
@@ -2052,11 +2009,7 @@ output_digit_test (const char *filename, const char *version)
 static void
 output_digit (const char *filename, const char *version)
 {
-  FILE *stream;
-  struct decdigit_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -2074,6 +2027,7 @@ output_digit (const char *filename, const char *version)
   output_library_license (stream, false);
   fprintf (stream, "\n");
 
+  struct decdigit_table t;
   t.p = 7;
   t.q = 9;
   decdigit_table_init (&t);
@@ -2090,12 +2044,12 @@ output_digit (const char *filename, const char *version)
   decdigit_table_finalize (&t);
 
   /* Offsets in t.result, in memory of this process.  */
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -2118,10 +2072,9 @@ output_digit (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -2138,10 +2091,9 @@ output_digit (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -2214,10 +2166,7 @@ get_numeric_value (unsigned int ch)
 static void
 output_numeric_test (const char *filename, const char *version)
 {
-  FILE *stream;
-  bool need_comma;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -2235,7 +2184,7 @@ output_numeric_test (const char *filename, const char *version)
   output_tests_license (stream);
   fprintf (stream, "\n");
 
-  need_comma = false;
+  bool need_comma = false;
   for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       uc_fraction_t value = get_numeric_value (ch);
@@ -2271,14 +2220,7 @@ output_numeric_test (const char *filename, const char *version)
 static void
 output_numeric (const char *filename, const char *version)
 {
-  FILE *stream;
-  uc_fraction_t fractions[160];
-  unsigned int nfractions;
-  struct numeric_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-  uint16_t *level3_packed;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -2297,7 +2239,8 @@ output_numeric (const char *filename, const char *version)
   fprintf (stream, "\n");
 
   /* Create table of occurring fractions.  */
-  nfractions = 0;
+  uc_fraction_t fractions[160];
+  unsigned int nfractions = 0;
   for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       uc_fraction_t value = get_numeric_value (ch);
@@ -2335,6 +2278,7 @@ output_numeric (const char *filename, const char *version)
     }
   fprintf (stream, "};\n");
 
+  struct numeric_table t;
   t.p = 7;
   t.q = 9;
   numeric_table_init (&t);
@@ -2356,12 +2300,12 @@ output_numeric (const char *filename, const char *version)
   numeric_table_finalize (&t);
 
   /* Offsets in t.result, in memory of this process.  */
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -2384,10 +2328,9 @@ output_numeric (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -2404,10 +2347,9 @@ output_numeric (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -2421,7 +2363,7 @@ output_numeric (const char *filename, const char *version)
   fprintf (stream, " },\n");
   /* Pack the level3 array.  Each entry needs 8 bits only.  Use 16-bit units,
      not 32-bit units, in order to make the lookup function easier.  */
-  level3_packed =
+  uint16_t *level3_packed =
     (uint16_t *)
     calloc ((t.level3_size << t.p) * 8 / 16 + 1, sizeof (uint16_t));
   for (unsigned int i = 0; i < t.level3_size << t.p; i++)
@@ -2476,29 +2418,23 @@ static unsigned int mirror_pairs_count;
 static void
 fill_mirror (const char *bidimirroring_filename)
 {
-  FILE *stream;
-  char field0[FIELDLEN];
-  char field1[FIELDLEN];
-  char field2[FIELDLEN];
-  int lineno = 0;
-
-  stream = fopen (bidimirroring_filename, "r");
+  FILE *stream = fopen (bidimirroring_filename, "r");
   if (stream == NULL)
     {
       fprintf (stderr, "error during fopen of '%s'\n", bidimirroring_filename);
       exit (1);
     }
 
+  char field0[FIELDLEN];
+  char field1[FIELDLEN];
+  char field2[FIELDLEN];
+  int lineno = 0;
+
   mirror_pairs_count = 0;
   for (;;)
     {
-      int n;
-      int c;
-      unsigned int uc1;
-      unsigned int uc2;
-
       lineno++;
-      c = getc (stream);
+      int c = getc (stream);
       if (c == EOF)
         break;
       if (c == '\n')
@@ -2509,7 +2445,7 @@ fill_mirror (const char *bidimirroring_filename)
           continue;
         }
       ungetc (c, stream);
-      n = getfield (stream, field0, ';');
+      int n = getfield (stream, field0, ';');
       do c = getc (stream); while (c == ' ');
       ungetc (c, stream);
       n += getfield (stream, field1, '#');
@@ -2526,8 +2462,8 @@ fill_mirror (const char *bidimirroring_filename)
       while (strlen (field1) > 0 && field1[strlen (field1) - 1] == ' ')
         field1[strlen (field1) - 1] = '\0';
       /* The line should contain two characters.  */
-      uc1 = strtoul (field0, NULL, 16);
-      uc2 = strtoul (field1, NULL, 16);
+      unsigned int uc1 = strtoul (field0, NULL, 16);
+      unsigned int uc2 = strtoul (field1, NULL, 16);
       if (uc1 == 0 || uc2 == 0 || uc1 == uc2)
         {
           fprintf (stderr, "parse error at '%s':%d\n",
@@ -2630,12 +2566,10 @@ fill_mirror (const char *bidimirroring_filename)
 static int
 get_mirror_value (unsigned int ch)
 {
-  bool mirrored;
-  unsigned int mirror_char;
+  bool mirrored = (unicode_attributes[ch].name != NULL
+                   && unicode_attributes[ch].mirrored);
 
-  mirrored = (unicode_attributes[ch].name != NULL
-              && unicode_attributes[ch].mirrored);
-  mirror_char = 0xfffd;
+  unsigned int mirror_char = 0xfffd;
   for (unsigned int i = 0; i < mirror_pairs_count; i++)
     if (ch == mirror_pairs[i].uc[0])
       {
@@ -2668,11 +2602,7 @@ get_mirror_value (unsigned int ch)
 static void
 output_mirror (const char *filename, const char *version)
 {
-  FILE *stream;
-  struct mirror_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -2690,6 +2620,7 @@ output_mirror (const char *filename, const char *version)
   output_library_license (stream, false);
   fprintf (stream, "\n");
 
+  struct mirror_table t;
   t.p = 7;
   t.q = 9;
   mirror_table_init (&t);
@@ -2704,12 +2635,12 @@ output_mirror (const char *filename, const char *version)
   mirror_table_finalize (&t);
 
   /* Offsets in t.result, in memory of this process.  */
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -2731,10 +2662,9 @@ output_mirror (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -2751,10 +2681,9 @@ output_mirror (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -2905,9 +2834,7 @@ clear_properties (void)
 static void
 fill_properties (const char *proplist_filename)
 {
-  FILE *stream;
-
-  stream = fopen (proplist_filename, "r");
+  FILE *stream = fopen (proplist_filename, "r");
   if (stream == NULL)
     {
       fprintf (stderr, "error during fopen of '%s'\n", proplist_filename);
@@ -2917,18 +2844,16 @@ fill_properties (const char *proplist_filename)
   for (;;)
     {
       char buf[200+1];
-      unsigned int i1, i2;
-      char padding[200+1];
-      char propname[200+1];
-      char rest_of_line[200+1];
-      unsigned int propcode;
-
       if (fscanf (stream, "%200[^\n]\n", buf) < 1)
         break;
 
       if (buf[0] == '\0' || buf[0] == '#')
         continue;
 
+      unsigned int i1, i2;
+      char padding[200+1];
+      char propname[200+1];
+      char rest_of_line[200+1];
       if (sscanf (buf, "%X..%X%[ ;]%[^ #]%200s", &i1, &i2, padding, propname, rest_of_line) != 5)
         {
           if (sscanf (buf, "%X%[ ;]%[^ #]%200s", &i1, padding, propname, rest_of_line) != 4)
@@ -2938,6 +2863,7 @@ fill_properties (const char *proplist_filename)
             }
           i2 = i1;
         }
+      unsigned int propcode;
 #define PROP(name,code) \
       if (streq (propname, name)) propcode = code; else
       /* PropList.txt */
@@ -3011,7 +2937,6 @@ fill_properties (const char *proplist_filename)
       if (streq (propname, "InCB;"))
         {
           char valuename[200+1];
-          unsigned int valuecode;
 
           if (sscanf (rest_of_line, "%[^ #]", valuename) != 1)
             {
@@ -3019,6 +2944,7 @@ fill_properties (const char *proplist_filename)
               exit (1);
             }
 
+          unsigned int valuecode;
           if (streq (valuename, "None"))
             valuecode = UC_INDIC_CONJUNCT_BREAK_NONE;
           else if (streq (valuename, "Consonant"))
@@ -3066,13 +2992,11 @@ fill_properties (const char *proplist_filename)
 static void
 fill_property30 (char array[0x110000], const char *proplist_filename, const char *property_name)
 {
-  FILE *stream;
-  char buf[100+1];
 
   for (unsigned int i = 0; i < 0x110000; i++)
     array[i] = 0;
 
-  stream = fopen (proplist_filename, "r");
+  FILE *stream = fopen (proplist_filename, "r");
   if (stream == NULL)
     {
       fprintf (stderr, "error during fopen of '%s'\n", proplist_filename);
@@ -3080,6 +3004,7 @@ fill_property30 (char array[0x110000], const char *proplist_filename, const char
     }
 
   /* Search for the "Property dump for: ..." line.  */
+  char buf[100+1];
   do
     {
       if (fscanf (stream, "%100[^\n]\n", buf) < 1)
@@ -3092,12 +3017,11 @@ fill_property30 (char array[0x110000], const char *proplist_filename, const char
 
   for (;;)
     {
-      unsigned int i1, i2;
-
       if (fscanf (stream, "%100[^\n]\n", buf) < 1)
         break;
       if (buf[0] == '*')
         break;
+      unsigned int i1, i2;
       if (strlen (buf) >= 10 && buf[4] == '.' && buf[5] == '.')
         {
           if (sscanf (buf, "%4X..%4X", &i1, &i2) < 2)
@@ -4122,10 +4046,7 @@ indic_conjunct_break_as_c_identifier (int indic_conjunct_break)
 static void
 output_indic_conjunct_break_test (const char *filename, const char *version)
 {
-  FILE *stream;
-  bool need_comma;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -4143,7 +4064,7 @@ output_indic_conjunct_break_test (const char *filename, const char *version)
   output_tests_license (stream);
   fprintf (stream, "\n");
 
-  need_comma = false;
+  bool need_comma = false;
   for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value = unicode_indic_conjunct_break[ch];
@@ -4177,11 +4098,7 @@ output_indic_conjunct_break_test (const char *filename, const char *version)
 static void
 output_indic_conjunct_break (const char *filename, const char *version)
 {
-  FILE *stream;
-  struct indic_conjunct_break_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -4199,6 +4116,7 @@ output_indic_conjunct_break (const char *filename, const char *version)
   output_library_license (stream, false);
   fprintf (stream, "\n");
 
+  struct indic_conjunct_break_table t;
   t.p = 6; /* or 5 */
   t.q = 4; /* or 5 */
   indic_conjunct_break_table_init (&t);
@@ -4216,12 +4134,12 @@ output_indic_conjunct_break (const char *filename, const char *version)
   indic_conjunct_break_table_finalize (&t);
 
   /* Offsets in t.result, in memory of this process.  */
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -4244,10 +4162,9 @@ output_indic_conjunct_break (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -4264,10 +4181,9 @@ output_indic_conjunct_break (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -4442,10 +4358,7 @@ static uint8_t unicode_joining_group[0x110000];
 static void
 fill_arabicshaping (const char *arabicshaping_filename)
 {
-  FILE *stream;
-  int lineno;
-
-  stream = fopen (arabicshaping_filename, "r");
+  FILE *stream = fopen (arabicshaping_filename, "r");
   if (stream == NULL)
     {
       fprintf (stderr, "error during fopen of '%s'\n", arabicshaping_filename);
@@ -4458,20 +4371,11 @@ fill_arabicshaping (const char *arabicshaping_filename)
       unicode_joining_group[i] = UC_JOINING_GROUP_NONE;
     }
 
-  lineno = 0;
+  int lineno = 0;
   for (;;)
     {
-      char buf[200+1];
-      char separator1[200+1];
-      char schematic_name[200+1];
-      char separator2[200+1];
-      char joining_type_name[200+1];
-      char separator3[200+1];
-      char joining_group_name[200+1];
-      int joining_type;
-      int joining_group;
-
       lineno++;
+      char buf[200+1];
       if (fscanf (stream, "%200[^\n]\n", buf) < 1)
         break;
 
@@ -4479,6 +4383,12 @@ fill_arabicshaping (const char *arabicshaping_filename)
         continue;
 
       unsigned int i;
+      char separator1[200+1];
+      char schematic_name[200+1];
+      char separator2[200+1];
+      char joining_type_name[200+1];
+      char separator3[200+1];
+      char joining_group_name[200+1];
       if (sscanf (buf, "%X%[; ]%[^;]%[; ]%[^;]%[; ]%100[^\n]",
                   &i, separator1, schematic_name, separator2, joining_type_name,
                   separator3, joining_group_name) != 7)
@@ -4489,6 +4399,7 @@ fill_arabicshaping (const char *arabicshaping_filename)
         }
       assert (i < 0x110000);
 
+      int joining_type;
 #define TRY(name) else if (streq (joining_type_name, #name + 16)) joining_type = name;
       if (false) {}
       TRY(UC_JOINING_TYPE_U)
@@ -4510,6 +4421,7 @@ fill_arabicshaping (const char *arabicshaping_filename)
              && joining_group_name[strlen (joining_group_name) - 1] == ' ')
         joining_group_name[strlen (joining_group_name) - 1] = '\0';
 
+      int joining_group;
 #define TRY(value,name) else if (streq (joining_group_name, name)) joining_group = value;
       if (false) {}
       TRY(UC_JOINING_GROUP_NONE,                     "No_Joining_Group")
@@ -4655,10 +4567,7 @@ joining_type_as_c_identifier (int joining_type)
 static void
 output_joining_type_test (const char *filename, const char *version)
 {
-  FILE *stream;
-  bool need_comma;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -4676,7 +4585,7 @@ output_joining_type_test (const char *filename, const char *version)
   output_tests_license (stream);
   fprintf (stream, "\n");
 
-  need_comma = false;
+  bool need_comma = false;
   for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value = unicode_joining_type[ch];
@@ -4710,12 +4619,7 @@ output_joining_type_test (const char *filename, const char *version)
 static void
 output_joining_type (const char *filename, const char *version)
 {
-  FILE *stream;
-  struct joining_type_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-  uint8_t *level3_packed;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -4733,6 +4637,7 @@ output_joining_type (const char *filename, const char *version)
   output_library_license (stream, true);
   fprintf (stream, "\n");
 
+  struct joining_type_table t;
   t.p = 7;
   t.q = 9;
   joining_type_table_init (&t);
@@ -4749,12 +4654,12 @@ output_joining_type (const char *filename, const char *version)
   joining_type_table_finalize (&t);
 
   /* Offsets in t.result, in memory of this process.  */
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -4777,10 +4682,9 @@ output_joining_type (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -4797,10 +4701,9 @@ output_joining_type (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -4813,7 +4716,7 @@ output_joining_type (const char *filename, const char *version)
     fprintf (stream, "\n ");
   fprintf (stream, " },\n");
   /* Pack the level3 array.  Each entry needs 4 bits only.  */
-  level3_packed =
+  uint8_t *level3_packed =
     (uint8_t *) calloc ((t.level3_size << t.p) * 4 / 8, sizeof (uint8_t));
   for (unsigned int i = 0; i < t.level3_size << t.p; i++)
     {
@@ -4964,10 +4867,7 @@ joining_group_as_c_identifier (int joining_group)
 static void
 output_joining_group_test (const char *filename, const char *version)
 {
-  FILE *stream;
-  bool need_comma;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -4985,7 +4885,7 @@ output_joining_group_test (const char *filename, const char *version)
   output_tests_license (stream);
   fprintf (stream, "\n");
 
-  need_comma = false;
+  bool need_comma = false;
   for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int value = unicode_joining_group[ch];
@@ -5019,12 +4919,7 @@ output_joining_group_test (const char *filename, const char *version)
 static void
 output_joining_group (const char *filename, const char *version)
 {
-  FILE *stream;
-  struct joining_group_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-  uint16_t *level3_packed;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -5042,6 +4937,7 @@ output_joining_group (const char *filename, const char *version)
   output_library_license (stream, false);
   fprintf (stream, "\n");
 
+  struct joining_group_table t;
   t.p = 7;
   t.q = 9;
   joining_group_table_init (&t);
@@ -5058,12 +4954,12 @@ output_joining_group (const char *filename, const char *version)
   joining_group_table_finalize (&t);
 
   /* Offsets in t.result, in memory of this process.  */
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -5086,10 +4982,9 @@ output_joining_group (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -5106,10 +5001,9 @@ output_joining_group (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -5123,7 +5017,7 @@ output_joining_group (const char *filename, const char *version)
   fprintf (stream, " },\n");
   /* Pack the level3 array.  Each entry needs 7 bits only.  Use 16-bit units,
      not 32-bit units, in order to make the lookup function easier.  */
-  level3_packed =
+  uint16_t *level3_packed =
     (uint16_t *)
     calloc ((t.level3_size << t.p) * 7 / 16 + 1, sizeof (uint16_t));
   for (unsigned int i = 0; i < t.level3_size << t.p; i++)
@@ -5171,9 +5065,7 @@ static uint8_t unicode_scripts[0x110000];
 static void
 fill_scripts (const char *scripts_filename)
 {
-  FILE *stream;
-
-  stream = fopen (scripts_filename, "r");
+  FILE *stream = fopen (scripts_filename, "r");
   if (stream == NULL)
     {
       fprintf (stderr, "error during fopen of '%s'\n", scripts_filename);
@@ -5188,17 +5080,15 @@ fill_scripts (const char *scripts_filename)
   for (;;)
     {
       char buf[200+1];
-      unsigned int i1, i2;
-      char padding[200+1];
-      char scriptname[200+1];
-      int script;
-
       if (fscanf (stream, "%200[^\n]\n", buf) < 1)
         break;
 
       if (buf[0] == '\0' || buf[0] == '#')
         continue;
 
+      unsigned int i1, i2;
+      char padding[200+1];
+      char scriptname[200+1];
       if (sscanf (buf, "%X..%X%[ ;]%[^ ]", &i1, &i2, padding, scriptname) != 4)
         {
           if (sscanf (buf, "%X%[ ;]%[^ ]", &i1, padding, scriptname) != 3)
@@ -5211,6 +5101,7 @@ fill_scripts (const char *scripts_filename)
       assert (i2 >= i1);
       assert (i2 < 0x110000);
 
+      int script;
       for (script = numscripts - 1; script >= 0; script--)
         if (streq (scripts[script], scriptname))
           break;
@@ -5249,9 +5140,6 @@ static void
 output_scripts (const char *version)
 {
   const char *filename = "unictype/scripts.h";
-  FILE *stream;
-  struct script_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
 
   typedef struct
   {
@@ -5260,7 +5148,7 @@ output_scripts (const char *version)
   scriptinfo_t;
   scriptinfo_t scriptinfo[256];
 
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -5298,13 +5186,10 @@ output_scripts (const char *version)
       for (unsigned int ch = 0; ch < 0x110000; ch++)
         if (unicode_scripts[ch] == s)
           {
-            unsigned int start;
-            unsigned int end;
-
-            start = ch;
+            unsigned int start = ch;
             while (ch + 1 < 0x110000 && unicode_scripts[ch + 1] == s)
               ch++;
-            end = ch;
+            unsigned int end = ch;
 
             if (i > 0)
               fprintf (stream, ",\n");
@@ -5336,6 +5221,7 @@ output_scripts (const char *version)
     }
   fprintf (stream, "};\n");
 
+  struct script_table t;
   t.p = 7;
   t.q = 9;
   script_table_init (&t);
@@ -5350,12 +5236,12 @@ output_scripts (const char *version)
   script_table_finalize (&t);
 
   /* Offsets in t.result, in memory of this process.  */
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -5377,10 +5263,9 @@ output_scripts (const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -5397,10 +5282,9 @@ output_scripts (const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       /* To make the level2 values fit in 16 bits, we use 'unsigned short'
          instead of 'short' and add 1 to each value.  */
       if (offset == 0)
@@ -5441,9 +5325,8 @@ static void
 output_scripts_byname (const char *version)
 {
   const char *filename = "unictype/scripts_byname.gperf";
-  FILE *stream;
 
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -5494,9 +5377,7 @@ static unsigned int numblocks;
 static void
 fill_blocks (const char *blocks_filename)
 {
-  FILE *stream;
-
-  stream = fopen (blocks_filename, "r");
+  FILE *stream = fopen (blocks_filename, "r");
   if (stream == NULL)
     {
       fprintf (stderr, "error during fopen of '%s'\n", blocks_filename);
@@ -5506,16 +5387,15 @@ fill_blocks (const char *blocks_filename)
   for (;;)
     {
       char buf[200+1];
-      unsigned int i1, i2;
-      char padding[200+1];
-      char blockname[200+1];
-
       if (fscanf (stream, "%200[^\n]\n", buf) < 1)
         break;
 
       if (buf[0] == '\0' || buf[0] == '#')
         continue;
 
+      unsigned int i1, i2;
+      char padding[200+1];
+      char blockname[200+1];
       if (sscanf (buf, "%X..%X%[ ;]%[^\r]", &i1, &i2, padding, blockname) != 4)
         {
           fprintf (stderr, "parse error in '%s'\n", blocks_filename);
@@ -5586,9 +5466,8 @@ output_blocks (const char *version)
   const char *filename = "unictype/blocks.h";
   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;
 
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -6006,11 +5885,7 @@ java_ident_category (unsigned int ch)
 static void
 output_ident_category (const char *filename, int (*predicate) (unsigned int), const char *name, const char *version)
 {
-  FILE *stream;
-  struct identsyntax_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -6028,6 +5903,7 @@ output_ident_category (const char *filename, int (*predicate) (unsigned int), co
   output_library_license (stream, false);
   fprintf (stream, "\n");
 
+  struct identsyntax_table t;
   t.p = 7; /* or 8 */
   t.q = 5; /* or 4 */
   identsyntax_table_init (&t);
@@ -6045,12 +5921,12 @@ output_ident_category (const char *filename, int (*predicate) (unsigned int), co
   identsyntax_table_finalize (&t);
 
   /* Offsets in t.result, in memory of this process.  */
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -6073,10 +5949,9 @@ output_ident_category (const char *filename, int (*predicate) (unsigned int), co
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -6093,10 +5968,9 @@ output_ident_category (const char *filename, int (*predicate) (unsigned int), co
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -6443,31 +6317,27 @@ output_charclass (FILE *stream, const char *classname,
                   bool (*func) (unsigned int))
 {
   char table[0x110000];
-  bool need_semicolon;
-  const int max_column = 75;
-  int column;
 
   for (unsigned int i = 0; i < 0x110000; i++)
     table[i] = (int) func (i);
 
   fprintf (stream, "%s ", classname);
-  need_semicolon = false;
-  column = 1000;
+  const int max_column = 75;
+  bool need_semicolon = false;
+  int column = 1000;
   for (unsigned int i = 0; i < 0x110000; )
     {
       if (!table[i])
         i++;
       else
         {
-          unsigned int low, high;
-          char buf[25];
-
-          low = i;
+          unsigned int low = i;
           do
             i++;
           while (i < 0x110000 && table[i]);
-          high = i - 1;
+          unsigned int high = i - 1;
 
+          char buf[25];
           if (low == high)
             strcpy (buf, ucs_symbol (low));
           else
@@ -6500,16 +6370,14 @@ output_charmap (FILE *stream, const char *mapname,
                 unsigned int (*func) (unsigned int))
 {
   char table[0x110000];
-  bool need_semicolon;
-  const int max_column = 75;
-  int column;
 
   for (unsigned int i = 0; i < 0x110000; i++)
     table[i] = (func (i) != i);
 
   fprintf (stream, "%s ", mapname);
-  need_semicolon = false;
-  column = 1000;
+  const int max_column = 75;
+  bool need_semicolon = false;
+  int column = 1000;
   for (unsigned int i = 0; i < 0x110000; i++)
     if (table[i])
       {
@@ -6552,9 +6420,7 @@ output_widthmap (FILE *stream)
 static void
 output_tables (const char *filename, const char *version)
 {
-  FILE *stream;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -6580,9 +6446,8 @@ output_tables (const char *filename, const char *version)
   fprintf (stream, "territory \"Earth\"\n");
   fprintf (stream, "revision  \"%s\"\n", version);
   {
-    time_t now;
+    time_t now = time (NULL);
     char date[11];
-    now = time (NULL);
     strftime (date, sizeof (date), "%Y-%m-%d", gmtime (&now));
     fprintf (stream, "date      \"%s\"\n", date);
   }
@@ -6716,29 +6581,24 @@ const char * unicode_width[0x110000];
 static void
 fill_width (const char *width_filename)
 {
-  FILE *stream;
-  char field0[FIELDLEN];
-  char field1[FIELDLEN];
-  char field2[FIELDLEN];
-  int lineno = 0;
-
   for (unsigned int i = 0; i < 0x110000; i++)
     unicode_width[i] = (unicode_attributes[i].name != NULL ? "N" : NULL);
 
-  stream = fopen (width_filename, "r");
+  FILE *stream = fopen (width_filename, "r");
   if (stream == NULL)
     {
       fprintf (stderr, "error during fopen of '%s'\n", width_filename);
       exit (1);
     }
 
+  char field0[FIELDLEN];
+  char field1[FIELDLEN];
+  char field2[FIELDLEN];
+  int lineno = 0;
   for (;;)
     {
-      int n;
-      int c;
-
       lineno++;
-      c = getc (stream);
+      int c = getc (stream);
       if (c == EOF)
         break;
       if (c == '\n')
@@ -6749,7 +6609,7 @@ fill_width (const char *width_filename)
           continue;
         }
       ungetc (c, stream);
-      n = getfield (stream, field0, ';');
+      int n = getfield (stream, field0, ';');
       do c = getc (stream); while (c == ' ');
       ungetc (c, stream);
       n += getfield (stream, field1, '#');
@@ -6839,12 +6699,7 @@ is_nonspacing (unsigned int ch)
 static void
 output_nonspacing_property (const char *filename, const char *version)
 {
-  FILE *stream;
-  int ind[0x110000 / 0x200];
-  unsigned int i_max;
-  int next_ind;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -6862,7 +6717,8 @@ output_nonspacing_property (const char *filename, const char *version)
   output_library_license (stream, true);
   fprintf (stream, "\n");
 
-  next_ind = 0;
+  int ind[0x110000 / 0x200];
+  int next_ind = 0;
   for (unsigned int i = 0; i < 0x110000 / 0x200; i++)
     {
       bool nontrivial = false;
@@ -6882,7 +6738,7 @@ 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;
+  unsigned int i_max = 0;
   for (unsigned int i = 0; i < 0x110000 / 0x200; i++)
     {
       bool nontrivial = (ind[i] >= 0);
@@ -7103,18 +6959,15 @@ symbolic_width (unsigned int ch)
 static void
 output_width_property_test (const char *filename)
 {
-  FILE *stream;
-  unsigned int interval_start, interval_end;
-  char interval_value;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
       exit (1);
     }
 
-  interval_value = 0;
+  unsigned int interval_start, interval_end;
+  char interval_value = 0;
   interval_start = interval_end = 0; /* avoid GCC warning */
   for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
@@ -8715,9 +8568,7 @@ debug_output_lbp (FILE *stream)
 static void
 debug_output_lbrk_tables (const char *filename)
 {
-  FILE *stream;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -8741,12 +8592,6 @@ int unicode_org_lbp[0x110000];
 static void
 fill_org_lbp (const char *linebreak_filename)
 {
-  FILE *stream;
-  char field0[FIELDLEN];
-  char field1[FIELDLEN];
-  char field2[FIELDLEN];
-  int lineno = 0;
-
   /* For unassigned characters (General Category "Cn") that have property
      Extended_Pictographic, the LineBreak.txt files is inconsistent:
      For some of them, such as U+1F02C, it specifies LBP_ID, which then triggers
@@ -8762,21 +8607,21 @@ fill_org_lbp (const char *linebreak_filename)
     unicode_org_lbp[i] =
       (is_property_extended_pictographic (i) ? LBP_EBF : LBP_XX);
 
-  stream = fopen (linebreak_filename, "r");
+  FILE *stream = fopen (linebreak_filename, "r");
   if (stream == NULL)
     {
       fprintf (stderr, "error during fopen of '%s'\n", linebreak_filename);
       exit (1);
     }
 
+  char field0[FIELDLEN];
+  char field1[FIELDLEN];
+  char field2[FIELDLEN];
+  int lineno = 0;
   for (;;)
     {
-      int n;
-      int c;
-      int value;
-
       lineno++;
-      c = getc (stream);
+      int c = getc (stream);
       if (c == EOF)
         break;
       if (c == '\n')
@@ -8787,7 +8632,7 @@ fill_org_lbp (const char *linebreak_filename)
           continue;
         }
       ungetc (c, stream);
-      n = getfield (stream, field0, ';');
+      int n = getfield (stream, field0, ';');
       do c = getc (stream); while (c == ' ');
       ungetc (c, stream);
       n += getfield (stream, field1, '#');
@@ -8806,6 +8651,7 @@ fill_org_lbp (const char *linebreak_filename)
       /* Remove trailing spaces from field1.  */
       while (strlen (field1) > 0 && field1[strlen (field1) - 1] == ' ')
         field1[strlen (field1) - 1] = '\0';
+      int value;
 #define TRY(bit) else if (streq (field1, #bit + 4)) value = bit;
       if (false) {}
       TRY(LBP_BK)
@@ -8964,9 +8810,7 @@ debug_output_org_lbp (FILE *stream)
 static void
 debug_output_org_lbrk_tables (const char *filename)
 {
-  FILE *stream;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -9062,8 +8906,6 @@ static void
 output_lbpea (FILE *stream1, FILE *stream2)
 {
   struct lbpea_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-
   t.p = 7;
   t.q = 9;
   lbpea_table_init (&t);
@@ -9087,12 +8929,12 @@ output_lbpea (FILE *stream1, FILE *stream2)
 
   lbpea_table_finalize (&t);
 
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -9117,10 +8959,9 @@ output_lbpea (FILE *stream1, FILE *stream2)
     fprintf (stream2, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream2, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream2, " %5d", -1);
       else
@@ -9137,10 +8978,9 @@ output_lbpea (FILE *stream1, FILE *stream2)
     fprintf (stream2, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream2, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       if (offset == 0)
         fprintf (stream2, " %5d", -1);
       else
@@ -9174,11 +9014,10 @@ static void
 output_lbrk_tables (const char *filename1, const char *filename2, const char *version)
 {
   const char *filenames[2];
-  FILE *streams[2];
-
   filenames[0] = filename1;
   filenames[1] = filename2;
 
+  FILE *streams[2];
   for (size_t i = 0; i < 2; i++)
     {
       streams[i] = fopen (filenames[i], "w");
@@ -9220,9 +9059,7 @@ output_lbrk_tables (const char *filename1, const char *filename2, const char *ve
 static void
 output_lbrk_rules_as_tables (const char *filename, const char *version)
 {
-  FILE *stream;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -9820,9 +9657,7 @@ debug_output_wbp (FILE *stream)
 static void
 debug_output_wbrk_tables (const char *filename)
 {
-  FILE *stream;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -9846,12 +9681,10 @@ int unicode_org_wbp[0x110000];
 static void
 fill_org_wbp (const char *wordbreakproperty_filename)
 {
-  FILE *stream;
-
   for (unsigned int i = 0; i < 0x110000; i++)
     unicode_org_wbp[i] = WBP_OTHER;
 
-  stream = fopen (wordbreakproperty_filename, "r");
+  FILE *stream = fopen (wordbreakproperty_filename, "r");
   if (stream == NULL)
     {
       fprintf (stderr, "error during fopen of '%s'\n", wordbreakproperty_filename);
@@ -9861,17 +9694,15 @@ fill_org_wbp (const char *wordbreakproperty_filename)
   for (;;)
     {
       char buf[200+1];
-      unsigned int i1, i2;
-      char padding[200+1];
-      char propname[200+1];
-      int propvalue;
-
       if (fscanf (stream, "%200[^\n]\n", buf) < 1)
         break;
 
       if (buf[0] == '\0' || buf[0] == '#')
         continue;
 
+      unsigned int i1, i2;
+      char padding[200+1];
+      char propname[200+1];
       if (sscanf (buf, "%X..%X%[ ;]%[^ ]", &i1, &i2, padding, propname) != 4)
         {
           if (sscanf (buf, "%X%[ ;]%[^ ]", &i1, padding, propname) != 3)
@@ -9882,6 +9713,7 @@ fill_org_wbp (const char *wordbreakproperty_filename)
             }
           i2 = i1;
         }
+      int propvalue;
 #define PROP(name,value) \
       if (streq (propname, name)) propvalue = value; else
       PROP ("CR", WBP_CR)
@@ -9961,9 +9793,7 @@ debug_output_org_wbp (FILE *stream)
 static void
 debug_output_org_wbrk_tables (const char *filename)
 {
-  FILE *stream;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -9991,8 +9821,6 @@ static void
 output_wbp (FILE *stream)
 {
   struct wbp_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-
   t.p = 7;
   t.q = 9;
   wbp_table_init (&t);
@@ -10015,12 +9843,12 @@ output_wbp (FILE *stream)
 
   wbp_table_finalize (&t);
 
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -10043,10 +9871,9 @@ output_wbp (FILE *stream)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -10063,10 +9890,9 @@ output_wbp (FILE *stream)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -10125,9 +9951,7 @@ output_wbp (FILE *stream)
 static void
 output_wbrk_tables (const char *filename, const char *version)
 {
-  FILE *stream;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -10197,10 +10021,7 @@ int unicode_org_gbp[0x110000];
 static void
 output_gbp_test (const char *filename)
 {
-  FILE *stream;
-  bool need_comma;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -10214,15 +10035,15 @@ output_gbp_test (const char *filename)
   output_tests_license (stream);
   fprintf (stream, "\n");
 
-  need_comma = false;
+  bool need_comma = false;
   for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       int gbp = unicode_org_gbp[ch];
-      const char *gbp_string;
 
       while (ch + 1 < 0x110000 && unicode_org_gbp[ch + 1] == gbp)
         ch++;
 
+      const char *gbp_string;
       switch (gbp)
         {
 #define CASE(x) case x: gbp_string = #x; break;
@@ -10268,11 +10089,7 @@ output_gbp_test (const char *filename)
 static void
 output_gbp_table (const char *filename, const char *version)
 {
-  FILE *stream;
-  struct gbp_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -10290,6 +10107,7 @@ output_gbp_table (const char *filename, const char *version)
   output_library_license (stream, false);
   fprintf (stream, "\n");
 
+  struct gbp_table t;
   t.p = 7;
   t.q = 9;
   gbp_table_init (&t);
@@ -10300,12 +10118,12 @@ output_gbp_table (const char *filename, const char *version)
   gbp_table_finalize (&t);
 
   /* Offsets in t.result, in memory of this process.  */
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -10328,10 +10146,9 @@ output_gbp_table (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -10348,10 +10165,9 @@ output_gbp_table (const char *filename, const char *version)
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -10417,13 +10233,10 @@ output_gbp_table (const char *filename, const char *version)
 static void
 fill_org_gbp (const char *graphemebreakproperty_filename)
 {
-  FILE *stream;
-  int lineno = 0;
-
   for (unsigned int i = 0; i < 0x110000; i++)
     unicode_org_gbp[i] = GBP_OTHER;
 
-  stream = fopen (graphemebreakproperty_filename, "r");
+  FILE *stream = fopen (graphemebreakproperty_filename, "r");
   if (stream == NULL)
     {
       fprintf (stderr, "error during fopen of '%s'\n",
@@ -10431,21 +10244,20 @@ fill_org_gbp (const char *graphemebreakproperty_filename)
       exit (1);
     }
 
+  int lineno = 0;
   for (;;)
     {
-      char buf[200+1];
-      unsigned int i1, i2;
-      char padding[200+1];
-      char propname[200+1];
-      int propvalue;
-
       lineno++;
+      char buf[200+1];
       if (fscanf (stream, "%200[^\n]\n", buf) < 1)
         break;
 
       if (buf[0] == '\0' || buf[0] == '#')
         continue;
 
+      unsigned int i1, i2;
+      char padding[200+1];
+      char propname[200+1];
       if (sscanf (buf, "%X..%X%[ ;]%[^ ]", &i1, &i2, padding, propname) != 4)
         {
           if (sscanf (buf, "%X%[ ;]%[^ ]", &i1, padding, propname) != 3)
@@ -10456,6 +10268,7 @@ fill_org_gbp (const char *graphemebreakproperty_filename)
             }
           i2 = i1;
         }
+      int propvalue;
 #define PROP(name,value) \
       if (streq (propname, name)) propvalue = value; else
       PROP ("CR", GBP_CR)
@@ -10535,17 +10348,12 @@ get_decomposition (unsigned int ch,
   if (decomposition != NULL && decomposition[0] != '\0')
     {
       int type = UC_DECOMP_CANONICAL;
-      unsigned int length;
-      char *endptr;
 
       if (decomposition[0] == '<')
         {
-          const char *rangle;
-          size_t typelen;
-
-          rangle = strchr (decomposition + 1, '>');
+          const char *rangle = strchr (decomposition + 1, '>');
           assert (rangle != NULL);
-          typelen = rangle + 1 - decomposition;
+          size_t typelen = rangle + 1 - decomposition;
 #define TYPE(t1,t2) \
           if (typelen == (sizeof (t1) - 1) && memeq (decomposition, t1, typelen)) \
             type = t2; \
@@ -10575,8 +10383,10 @@ get_decomposition (unsigned int ch,
           if (decomposition[0] == ' ')
             decomposition++;
         }
+      unsigned int length;
       for (length = 0; length < MAX_DECOMP_LENGTH; length++)
         {
+          char *endptr;
           decomposed[length] = strtoul (decomposition, &endptr, 16);
           if (endptr == decomposition)
             break;
@@ -10607,8 +10417,6 @@ static void
 output_decomposition (FILE *stream1, FILE *stream2)
 {
   struct decomp_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-
   t.p = 5;
   t.q = 5;
   decomp_table_init (&t);
@@ -10656,12 +10464,12 @@ output_decomposition (FILE *stream1, FILE *stream2)
 
   decomp_table_finalize (&t);
 
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -10685,10 +10493,9 @@ output_decomposition (FILE *stream1, FILE *stream2)
     fprintf (stream2, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream2, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream2, " %5d", -1);
       else
@@ -10705,10 +10512,9 @@ output_decomposition (FILE *stream1, FILE *stream2)
     fprintf (stream2, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream2, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       if (offset == 0)
         fprintf (stream2, " %5d", -1);
       else
@@ -10742,11 +10548,10 @@ static void
 output_decomposition_tables (const char *filename1, const char *filename2, const char *version)
 {
   const char *filenames[2];
-  FILE *streams[2];
-
   filenames[0] = filename1;
   filenames[1] = filename2;
 
+  FILE *streams[2];
   for (size_t i = 0; i < 2; i++)
     {
       streams[i] = fopen (filenames[i], "w");
@@ -10791,9 +10596,7 @@ char unicode_composition_exclusions[0x110000];
 static void
 fill_composition_exclusions (const char *compositionexclusions_filename)
 {
-  FILE *stream;
-
-  stream = fopen (compositionexclusions_filename, "r");
+  FILE *stream = fopen (compositionexclusions_filename, "r");
   if (stream == NULL)
     {
       fprintf (stderr, "error during fopen of '%s'\n", compositionexclusions_filename);
@@ -10806,14 +10609,13 @@ fill_composition_exclusions (const char *compositionexclusions_filename)
   for (;;)
     {
       char buf[200+1];
-      unsigned int i;
-
       if (fscanf (stream, "%200[^\n]\n", buf) < 1)
         break;
 
       if (buf[0] == '\0' || buf[0] == '#')
         continue;
 
+      unsigned int i;
       if (sscanf (buf, "%X", &i) != 1)
         {
           fprintf (stderr, "parse error in '%s'\n", compositionexclusions_filename);
@@ -10834,9 +10636,7 @@ fill_composition_exclusions (const char *compositionexclusions_filename)
 static void
 debug_output_composition_tables (const char *filename)
 {
-  FILE *stream;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -10890,134 +10690,135 @@ output_composition_tables (const char *filename, const char *filename2,
 {
   unsigned int max_code1;
   unsigned int max_code2;
-  FILE *stream;
-
-  max_code1 = 0;
-  max_code2 = 0;
-
-  stream = fopen (filename, "w");
-  if (stream == NULL)
-    {
-      fprintf (stderr, "cannot open '%s' for writing\n", filename);
-      exit (1);
-    }
 
-  fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n");
-  fprintf (stream, "/* Canonical composition of Unicode characters.  */\n");
-  fprintf (stream, "/* Generated automatically by gen-uni-tables.c for Unicode %s.  */\n",
-           version);
-  fprintf (stream, "\n");
-
-  fprintf (stream, "/* Copyright (C) 2009-2025 Free Software Foundation, Inc.\n");
-  fprintf (stream, "\n");
-  output_library_license (stream, true);
-  fprintf (stream, "\n");
-
-  /* The composition table is a set of mappings (code1, code2) -> combined,
-     with 928 entries,
-     367 values for code1 (from 0x003C to 0x30FD),
-      54 values for code2 (from 0x0300 to 0x309A).
-     For a fixed code1, there are from 1 to 19 possible values for code2.
-     For a fixed code2, there are from 1 to 117 possible values for code1.
-     This is a very sparse matrix.
-
-     We want an O(1) hash lookup.
-
-     We could implement the hash lookup by mapping (code1, code2) to a linear
-     combination  mul1*code1 + mul2*code2, which is then used as an index into
-     a 3-level table.  But this leads to a table of size 37 KB.
-
-     We use gperf to implement the hash lookup, giving it the 928 sets of
-     4 bytes (code1, code2) as input.  gperf generates a hash table of size
-     1527, which is quite good (60% filled).  It requires an auxiliary table
-     lookup in a table of size 0.5 KB.  The total tables size is 11 KB.  */
-
-  fprintf (stream, "struct composition_rule { char codes[6] _GL_ATTRIBUTE_NONSTRING; unsigned int combined; };\n");
-  fprintf (stream, "%%struct-type\n");
-  fprintf (stream, "%%language=ANSI-C\n");
-  fprintf (stream, "%%define slot-name codes\n");
-  fprintf (stream, "%%define hash-function-name gl_uninorm_compose_hash\n");
-  fprintf (stream, "%%define lookup-function-name gl_uninorm_compose_lookup\n");
-  fprintf (stream, "%%compare-lengths\n");
-  fprintf (stream, "%%compare-strncmp\n");
-  fprintf (stream, "%%readonly-tables\n");
-  fprintf (stream, "%%omit-struct-type\n");
-  fprintf (stream, "%%%%\n");
-
-  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 == UC_DECOMP_CANONICAL
-          /* Consider only binary decompositions.
-             Exclude singleton decompositions.  */
-          && length == 2)
-        {
-          unsigned int code1 = decomposed[0];
-          unsigned int code2 = decomposed[1];
-          unsigned int combined = ch;
+  {
+    FILE *stream = fopen (filename, "w");
+    if (stream == NULL)
+      {
+        fprintf (stderr, "cannot open '%s' for writing\n", filename);
+        exit (1);
+      }
 
-          /* Exclude decompositions where the first part is not a starter,
-             i.e. is not of canonical combining class 0.  */
-          if (streq (unicode_attributes[code1].combining, "0")
-              /* Exclude characters listed in CompositionExclusions.txt.  */
-              && !unicode_composition_exclusions[combined])
-            {
-              /* The combined character must now also be a starter.
-                 Verify this.  */
-              assert (streq (unicode_attributes[combined].combining, "0"));
+    fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n");
+    fprintf (stream, "/* Canonical composition of Unicode characters.  */\n");
+    fprintf (stream, "/* Generated automatically by gen-uni-tables.c for Unicode %s.  */\n",
+             version);
+    fprintf (stream, "\n");
 
-              if (max_code1 < code1)
-                max_code1 = code1;
-              if (max_code2 < code2)
-                max_code2 = code2;
+    fprintf (stream, "/* Copyright (C) 2009-2025 Free Software Foundation, Inc.\n");
+    fprintf (stream, "\n");
+    output_library_license (stream, true);
+    fprintf (stream, "\n");
 
-              fprintf (stream, "\"\\x%02x\\x%02x\\x%02x\\x%02x\\x%02x\\x%02x\", 0x%04x\n",
-                       (code1 >> 16) & 0xff, (code1 >> 8) & 0xff, code1 & 0xff,
-                       (code2 >> 16) & 0xff, (code2 >> 8) & 0xff, code2 & 0xff,
-                       combined);
-            }
-        }
-    }
+    /* The composition table is a set of mappings (code1, code2) -> combined,
+       with 928 entries,
+       367 values for code1 (from 0x003C to 0x30FD),
+        54 values for code2 (from 0x0300 to 0x309A).
+       For a fixed code1, there are from 1 to 19 possible values for code2.
+       For a fixed code2, there are from 1 to 117 possible values for code1.
+       This is a very sparse matrix.
+
+       We want an O(1) hash lookup.
+
+       We could implement the hash lookup by mapping (code1, code2) to a linear
+       combination  mul1*code1 + mul2*code2, which is then used as an index into
+       a 3-level table.  But this leads to a table of size 37 KB.
+
+       We use gperf to implement the hash lookup, giving it the 928 sets of
+       4 bytes (code1, code2) as input.  gperf generates a hash table of size
+       1527, which is quite good (60% filled).  It requires an auxiliary table
+       lookup in a table of size 0.5 KB.  The total tables size is 11 KB.  */
+
+    fprintf (stream, "struct composition_rule { char codes[6] _GL_ATTRIBUTE_NONSTRING; unsigned int combined; };\n");
+    fprintf (stream, "%%struct-type\n");
+    fprintf (stream, "%%language=ANSI-C\n");
+    fprintf (stream, "%%define slot-name codes\n");
+    fprintf (stream, "%%define hash-function-name gl_uninorm_compose_hash\n");
+    fprintf (stream, "%%define lookup-function-name gl_uninorm_compose_lookup\n");
+    fprintf (stream, "%%compare-lengths\n");
+    fprintf (stream, "%%compare-strncmp\n");
+    fprintf (stream, "%%readonly-tables\n");
+    fprintf (stream, "%%omit-struct-type\n");
+    fprintf (stream, "%%%%\n");
+
+    max_code1 = 0;
+    max_code2 = 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 (ferror (stream) || fclose (stream))
-    {
-      fprintf (stderr, "error writing to '%s'\n", filename);
-      exit (1);
-    }
+        if (type == UC_DECOMP_CANONICAL
+            /* Consider only binary decompositions.
+               Exclude singleton decompositions.  */
+            && length == 2)
+          {
+            unsigned int code1 = decomposed[0];
+            unsigned int code2 = decomposed[1];
+            unsigned int combined = ch;
+
+            /* Exclude decompositions where the first part is not a starter,
+               i.e. is not of canonical combining class 0.  */
+            if (streq (unicode_attributes[code1].combining, "0")
+                /* Exclude characters listed in CompositionExclusions.txt.  */
+                && !unicode_composition_exclusions[combined])
+              {
+                /* The combined character must now also be a starter.
+                   Verify this.  */
+                assert (streq (unicode_attributes[combined].combining, "0"));
+
+                if (max_code1 < code1)
+                  max_code1 = code1;
+                if (max_code2 < code2)
+                  max_code2 = code2;
+
+                fprintf (stream, "\"\\x%02x\\x%02x\\x%02x\\x%02x\\x%02x\\x%02x\", 0x%04x\n",
+                         (code1 >> 16) & 0xff, (code1 >> 8) & 0xff, code1 & 0xff,
+                         (code2 >> 16) & 0xff, (code2 >> 8) & 0xff, code2 & 0xff,
+                         combined);
+              }
+          }
+      }
 
-  stream = fopen (filename2, "w");
-  if (stream == NULL)
-    {
-      fprintf (stderr, "cannot open '%s' for writing\n", filename2);
-      exit (1);
-    }
+    if (ferror (stream) || fclose (stream))
+      {
+        fprintf (stderr, "error writing to '%s'\n", filename);
+        exit (1);
+      }
+  }
+  {
+    FILE *stream = fopen (filename2, "w");
+    if (stream == NULL)
+      {
+        fprintf (stderr, "cannot open '%s' for writing\n", filename2);
+        exit (1);
+      }
 
-  fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n");
-  fprintf (stream, "/* Canonical composition of Unicode characters.  */\n");
-  fprintf (stream, "/* Generated automatically by gen-uni-tables.c for Unicode %s.  */\n",
-           version);
-  fprintf (stream, "\n");
+    fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n");
+    fprintf (stream, "/* Canonical composition of Unicode characters.  */\n");
+    fprintf (stream, "/* Generated automatically by gen-uni-tables.c for Unicode %s.  */\n",
+             version);
+    fprintf (stream, "\n");
 
-  fprintf (stream, "/* Copyright (C) 2009-2025 Free Software Foundation, Inc.\n");
-  fprintf (stream, "\n");
-  output_library_license (stream, true);
-  fprintf (stream, "\n");
+    fprintf (stream, "/* Copyright (C) 2009-2025 Free Software Foundation, Inc.\n");
+    fprintf (stream, "\n");
+    output_library_license (stream, true);
+    fprintf (stream, "\n");
 
-  fprintf (stream, "/* Maximum value of the first argument for which gl_uninorm_compose_lookup\n"
-                   "   can return a non-NULL value.  */\n");
-  fprintf (stream, "#define UNINORM_COMPOSE_MAX_ARG1 0x%x\n", max_code1);
-  fprintf (stream, "/* Maximum value of the second argument for which gl_uninorm_compose_lookup\n"
-                   "   can return a non-NULL value.  */\n");
-  fprintf (stream, "#define UNINORM_COMPOSE_MAX_ARG2 0x%x\n", max_code2);
+    fprintf (stream, "/* Maximum value of the first argument for which gl_uninorm_compose_lookup\n"
+                     "   can return a non-NULL value.  */\n");
+    fprintf (stream, "#define UNINORM_COMPOSE_MAX_ARG1 0x%x\n", max_code1);
+    fprintf (stream, "/* Maximum value of the second argument for which gl_uninorm_compose_lookup\n"
+                     "   can return a non-NULL value.  */\n");
+    fprintf (stream, "#define UNINORM_COMPOSE_MAX_ARG2 0x%x\n", max_code2);
 
-  if (ferror (stream) || fclose (stream))
-    {
-      fprintf (stderr, "error writing to '%s'\n", filename2);
-      exit (1);
-    }
+    if (ferror (stream) || fclose (stream))
+      {
+        fprintf (stderr, "error writing to '%s'\n", filename2);
+        exit (1);
+      }
+  }
 }
 
 /* ========================================================================= */
@@ -11030,10 +10831,7 @@ output_simple_mapping_test (const char *filename,
                             unsigned int (*func) (unsigned int),
                             const char *version)
 {
-  FILE *stream;
-  bool need_comma;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -11052,7 +10850,7 @@ output_simple_mapping_test (const char *filename,
   fprintf (stream, "#include \"test-mapping-part1.h\"\n");
   fprintf (stream, "\n");
 
-  need_comma = false;
+  bool need_comma = false;
   for (unsigned int ch = 0; ch < 0x110000; ch++)
     {
       unsigned int value = func (ch);
@@ -11094,11 +10892,7 @@ output_simple_mapping (const char *filename,
                        unsigned int (*func) (unsigned int),
                        const char *version)
 {
-  FILE *stream;
-  struct mapping_table t;
-  unsigned int level1_offset, level2_offset, level3_offset;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -11118,6 +10912,7 @@ output_simple_mapping (const char *filename,
                           || streq (filename, "unicase/toupper.h"));
   fprintf (stream, "\n");
 
+  struct mapping_table t;
   t.p = 7;
   t.q = 9;
   mapping_table_init (&t);
@@ -11132,12 +10927,12 @@ output_simple_mapping (const char *filename,
   mapping_table_finalize (&t);
 
   /* Offsets in t.result, in memory of this process.  */
-  level1_offset =
+  unsigned int level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  unsigned int level2_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t);
-  level3_offset =
+  unsigned int level3_offset =
     5 * sizeof (uint32_t)
     + t.level1_size * sizeof (uint32_t)
     + (t.level2_size << t.q) * sizeof (uint32_t);
@@ -11159,10 +10954,9 @@ output_simple_mapping (const char *filename,
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level1_size; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level1_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level1_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -11179,10 +10973,9 @@ output_simple_mapping (const char *filename,
     fprintf (stream, "\n   ");
   for (unsigned int i = 0; i < t.level2_size << t.q; i++)
     {
-      uint32_t offset;
       if (i > 0 && (i % 8) == 0)
         fprintf (stream, "\n   ");
-      offset = ((uint32_t *) (t.result + level2_offset))[i];
+      uint32_t offset = ((uint32_t *) (t.result + level2_offset))[i];
       if (offset == 0)
         fprintf (stream, " %5d", -1);
       else
@@ -11268,9 +11061,7 @@ add_casing_rule (struct special_casing_rule *new_rule)
 static void
 fill_casing_rules (const char *specialcasing_filename)
 {
-  FILE *stream;
-
-  stream = fopen (specialcasing_filename, "r");
+  FILE *stream = fopen (specialcasing_filename, "r");
   if (stream == NULL)
     {
       fprintf (stderr, "error during fopen of '%s'\n", specialcasing_filename);
@@ -11284,25 +11075,18 @@ fill_casing_rules (const char *specialcasing_filename)
   for (;;)
     {
       char buf[200+1];
-      char *scanptr;
-      char *endptr;
-
-      unsigned int code;
-      unsigned int lower_mapping[3];
-      unsigned int title_mapping[3];
-      unsigned int upper_mapping[3];
-      char *language;
-      int context;
-
       if (fscanf (stream, "%200[^\n]\n", buf) < 1)
         break;
 
       if (buf[0] == '\0' || buf[0] == '#')
         continue;
 
+      char *scanptr;
+      char *endptr;
+
       /* Scan code.  */
       scanptr = buf;
-      code = strtoul (scanptr, &endptr, 16);
+      unsigned int code = strtoul (scanptr, &endptr, 16);
       if (endptr == scanptr)
         {
           fprintf (stderr, "parse error in '%s'\n", specialcasing_filename);
@@ -11317,6 +11101,7 @@ fill_casing_rules (const char *specialcasing_filename)
       scanptr++;
 
       /* Scan lower mapping.  */
+      unsigned int lower_mapping[3];
       for (int i = 0; i < 3; i++)
         lower_mapping[i] = 0;
       for (int i = 0; i < 3; i++)
@@ -11341,6 +11126,7 @@ fill_casing_rules (const char *specialcasing_filename)
       scanptr++;
 
       /* Scan title mapping.  */
+      unsigned int title_mapping[3];
       for (int i = 0; i < 3; i++)
         title_mapping[i] = 0;
       for (int i = 0; i < 3; i++)
@@ -11365,6 +11151,7 @@ fill_casing_rules (const char *specialcasing_filename)
       scanptr++;
 
       /* Scan upper mapping.  */
+      unsigned int upper_mapping[3];
       for (int i = 0; i < 3; i++)
         upper_mapping[i] = 0;
       for (int i = 0; i < 3; i++)
@@ -11389,18 +11176,16 @@ fill_casing_rules (const char *specialcasing_filename)
       scanptr++;
 
       /* Scan language and context.  */
-      language = NULL;
-      context = SCC_ALWAYS;
+      char *language = NULL;
+      int context = SCC_ALWAYS;
       while (*scanptr == ' ')
         scanptr++;
       if (*scanptr != '\0' && *scanptr != '#')
         {
           const char *word_begin = scanptr;
-          const char *word_end;
-
           while (*scanptr != '\0' && *scanptr != '#' && *scanptr != ';' && *scanptr != ' ')
             scanptr++;
-          word_end = scanptr;
+          const char *word_end = scanptr;
 
           while (*scanptr == ' ')
             scanptr++;
@@ -11496,9 +11281,7 @@ unsigned int allocated_casefolding_rules;
 static void
 fill_casefolding_rules (const char *casefolding_filename)
 {
-  FILE *stream;
-
-  stream = fopen (casefolding_filename, "r");
+  FILE *stream = fopen (casefolding_filename, "r");
   if (stream == NULL)
     {
       fprintf (stderr, "error during fopen of '%s'\n", casefolding_filename);
@@ -11512,22 +11295,18 @@ fill_casefolding_rules (const char *casefolding_filename)
   for (;;)
     {
       char buf[200+1];
-      char *scanptr;
-      char *endptr;
-
-      unsigned int code;
-      char type;
-      unsigned int mapping[3];
-
       if (fscanf (stream, "%200[^\n]\n", buf) < 1)
         break;
 
       if (buf[0] == '\0' || buf[0] == '#')
         continue;
 
+      char *scanptr;
+      char *endptr;
+
       /* Scan code.  */
       scanptr = buf;
-      code = strtoul (scanptr, &endptr, 16);
+      unsigned int code = strtoul (scanptr, &endptr, 16);
       if (endptr == scanptr)
         {
           fprintf (stderr, "parse error in '%s'\n", casefolding_filename);
@@ -11545,6 +11324,7 @@ fill_casefolding_rules (const char *casefolding_filename)
       while (*scanptr == ' ')
         scanptr++;
 
+      char type;
       switch (*scanptr)
         {
         case 'C': case 'F': case 'S': case 'T':
@@ -11563,6 +11343,7 @@ fill_casefolding_rules (const char *casefolding_filename)
       scanptr++;
 
       /* Scan casefold mapping.  */
+      unsigned int mapping[3];
       for (int i = 0; i < 3; i++)
         mapping[i] = 0;
       for (int i = 0; i < 3; i++)
@@ -11802,10 +11583,7 @@ sort_casing_rules (void)
 static void
 output_casing_rules (const char *filename, const char *version)
 {
-  FILE *stream;
-  unsigned int minor;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -11835,7 +11613,7 @@ output_casing_rules (const char *filename, const char *version)
   fprintf (stream, "%%omit-struct-type\n");
   fprintf (stream, "%%%%\n");
 
-  minor = 0;
+  unsigned int minor = 0;
   for (unsigned int i = 0; i < num_casing_rules; i++)
     {
       struct special_casing_rule *rule = casing_rules[i];
@@ -12032,11 +11810,7 @@ output_casing_properties (const char *version)
 static void
 output_version (const char *filename, const char *version)
 {
-  FILE *stream;
-  int major;
-  int minor;
-
-  stream = fopen (filename, "w");
+  FILE *stream = fopen (filename, "w");
   if (stream == NULL)
     {
       fprintf (stderr, "cannot open '%s' for writing\n", filename);
@@ -12061,6 +11835,8 @@ output_version (const char *filename, const char *version)
   fprintf (stream, "#include \"unimetadata.h\"\n");
   fprintf (stream, "\n");
 
+  int major;
+  int minor;
   sscanf (version, "%d.%d", &major, &minor);
   fprintf (stream, "const int _libunistring_unicode_version = (%d << 8) | %d;\n",
            major, minor);
index 312351b8b7d709a516cff4db80f675ca06735d16..088617b709704a60d3b24aae54c0aa399bc2cc4a 100644 (file)
@@ -183,7 +183,6 @@ get_rusage_as_via_setrlimit (void)
     for (;;)
       {
         /* Here we know that the address space size is >= low_bound.  */
-        struct rlimit try_limit;
         uintptr_t try_next = 2 * low_bound + pagesize;
 
         if (try_next < low_bound)
@@ -204,6 +203,7 @@ get_rusage_as_via_setrlimit (void)
             goto done1;
           }
 
+        struct rlimit try_limit;
         try_limit.rlim_max = orig_limit.rlim_max;
         try_limit.rlim_cur = try_next;
         if (setrlimit (RLIMIT_AS, &try_limit) == 0)
@@ -246,11 +246,11 @@ get_rusage_as_via_setrlimit (void)
        >= low_bound and < high_bound.  */
     while (high_bound - low_bound > pagesize)
       {
-        struct rlimit try_limit;
         uintptr_t try_next =
           low_bound + (((high_bound - low_bound) / 2) / pagesize) * pagesize;
 
         /* Here low_bound <= try_next < high_bound.  */
+        struct rlimit try_limit;
         try_limit.rlim_max = orig_limit.rlim_max;
         try_limit.rlim_cur = try_next;
         if (setrlimit (RLIMIT_AS, &try_limit) == 0)
@@ -354,9 +354,7 @@ get_rusage_as (void)
 #elif HAVE_SETRLIMIT && defined RLIMIT_AS && HAVE_SYS_MMAN_H && HAVE_MPROTECT && !defined __HAIKU__
   /* Prefer get_rusage_as_via_setrlimit() if it succeeds,
      because the caller may want to use the result with setrlimit().  */
-  uintptr_t result;
-
-  result = get_rusage_as_via_setrlimit ();
+  uintptr_t result = get_rusage_as_via_setrlimit ();
   if (result == 0)
     result = get_rusage_as_via_iterator ();
   return result;
index 593b201246d01eafcea7ec0d10c5b99b2d5d182c..54f626bcced15ef34b28a63e5f5012819a04c2b1 100644 (file)
@@ -190,7 +190,6 @@ get_rusage_data_via_setrlimit (void)
     for (;;)
       {
         /* Here we know that the data segment size is >= low_bound.  */
-        struct rlimit try_limit;
         uintptr_t try_next = 2 * low_bound + pagesize;
 
         if (try_next < low_bound)
@@ -211,6 +210,7 @@ get_rusage_data_via_setrlimit (void)
             goto done;
           }
 
+        struct rlimit try_limit;
         try_limit.rlim_max = orig_limit.rlim_max;
         try_limit.rlim_cur = try_next;
         if (setrlimit (RLIMIT_DATA, &try_limit) == 0)
@@ -250,11 +250,11 @@ get_rusage_data_via_setrlimit (void)
        >= low_bound and < high_bound.  */
     while (high_bound - low_bound > pagesize)
       {
-        struct rlimit try_limit;
         uintptr_t try_next =
           low_bound + (((high_bound - low_bound) / 2) / pagesize) * pagesize;
 
         /* Here low_bound <= try_next < high_bound.  */
+        struct rlimit try_limit;
         try_limit.rlim_max = orig_limit.rlim_max;
         try_limit.rlim_cur = try_next;
         if (setrlimit (RLIMIT_DATA, &try_limit) == 0)
@@ -408,9 +408,7 @@ get_rusage_data (void)
 # else
   /* Prefer get_rusage_data_via_setrlimit() if it succeeds,
      because the caller may want to use the result with setrlimit().  */
-  uintptr_t result;
-
-  result = get_rusage_data_via_setrlimit ();
+  uintptr_t result = get_rusage_data_via_setrlimit ();
   if (result == 0)
     result = get_rusage_data_via_iterator ();
   return result;
index 87e77fc9f8d1fbcc1f61d42d1de708e2fc87dfa3..f7d05efb59db8a111343d8b1e9c6799cbfbaa997 100644 (file)
@@ -77,10 +77,8 @@ get_ppid_of (pid_t pid)
 
   /* Read the contents of /proc/<pid>/status into memory.  */
   char filename[6 + 10 + 7 + 1];
-  int fd;
-
   sprintf (filename, "/proc/%u/status", (unsigned int) pid);
-  fd = open (filename, O_RDONLY | O_CLOEXEC);
+  int fd = open (filename, O_RDONLY | O_CLOEXEC);
   if (fd >= 0)
     {
       char buf[4096 + 1];
@@ -117,10 +115,8 @@ get_ppid_of (pid_t pid)
 
   /* Read the contents of /proc/<pid>/status into memory.  */
   char filename[6 + 10 + 7 + 1];
-  int fd;
-
   sprintf (filename, "/proc/%u/status", (unsigned int) pid);
-  fd = open (filename, O_RDONLY | O_CLOEXEC);
+  int fd = open (filename, O_RDONLY | O_CLOEXEC);
   if (fd >= 0)
     {
       char buf[4096 + 1];
@@ -128,13 +124,11 @@ get_ppid_of (pid_t pid)
       close (fd);
       if (nread >= 0)
         {
-          char *p;
-
           /* NUL-terminate the buffer.  */
           buf[nread] = '\0';
 
           /* Search for the third space-separated field.  */
-          p = strchr (buf, ' ');
+          char *p = strchr (buf, ' ');
           if (p != NULL)
             {
               p = strchr (p + 1, ' ');
@@ -154,10 +148,8 @@ get_ppid_of (pid_t pid)
 
   /* Read the contents of /proc/<pid>/psinfo into memory.  */
   char filename[6 + 10 + 7 + 1];
-  int fd;
-
   sprintf (filename, "/proc/%u/psinfo", (unsigned int) pid);
-  fd = open (filename, O_RDONLY | O_CLOEXEC);
+  int fd = open (filename, O_RDONLY | O_CLOEXEC);
   if (fd >= 0)
     {
       char buf[4096 + 1];
@@ -165,15 +157,12 @@ get_ppid_of (pid_t pid)
       close (fd);
       if (nread >= 0)
         {
-          char *p;
-          int count;
-
           /* NUL-terminate the buffer.  */
           buf[nread] = '\0';
 
           /* Search for the 16th space-separated field.  */
-          p = strchr (buf, ' ');
-          for (count = 1; p != NULL && count < 15; count++)
+          char *p = strchr (buf, ' ');
+          for (int count = 1; p != NULL && count < 15; count++)
             p = strchr (p + 1, ' ');
           if (p != NULL)
             {
@@ -192,10 +181,8 @@ get_ppid_of (pid_t pid)
      Alternatively, we could read the contents of /proc/<pid>/status into
      memory.  But it contains a lot of information that we don't need.  */
   char filename[6 + 10 + 7 + 1];
-  int fd;
-
   sprintf (filename, "/proc/%u/psinfo", (unsigned int) pid);
-  fd = open (filename, O_RDONLY | O_CLOEXEC);
+  int fd = open (filename, O_RDONLY | O_CLOEXEC);
   if (fd >= 0)
     {
       /* The contents is a 'struct psinfo'.  But since 'struct psinfo'
@@ -222,9 +209,7 @@ get_ppid_of (pid_t pid)
   int info_path[] =
     { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid, sizeof (struct kinfo_proc), 1 };
   struct kinfo_proc info;
-  size_t len;
-
-  len = sizeof (info);
+  size_t len = sizeof (info);
   if (sysctl (info_path, 6, &info, &len, NULL, 0) >= 0 && len == sizeof (info))
     return info.p_ppid;
 
index 0cc180e15d1095c215e3435f246d1fdc75dccd28..d65fcbfb85e867110bc2292e827a02cb65abecc2 100644 (file)
@@ -86,19 +86,16 @@ get_progname_of (pid_t pid)
   /* Read the symlink /proc/<pid>/exe.  */
   {
     char filename[6 + 10 + 4 + 1];
-    char linkbuf[1024 + 1];
-    ssize_t linklen;
-
     sprintf (filename, "/proc/%u/exe", (unsigned int) pid);
-    linklen = readlink (filename, linkbuf, sizeof (linkbuf) - 1);
+
+    char linkbuf[1024 + 1];
+    ssize_t linklen = readlink (filename, linkbuf, sizeof (linkbuf) - 1);
     if (linklen > 0)
       {
-        char *slash;
-
         /* NUL-terminate the link.  */
         linkbuf[linklen] = '\0';
         /* Find the portion after the last slash.  */
-        slash = strrchr (linkbuf, '/');
+        char *slash = strrchr (linkbuf, '/');
         return strdup (slash != NULL ? slash + 1 : linkbuf);
       }
   }
@@ -108,10 +105,8 @@ get_progname_of (pid_t pid)
      read the contents of /proc/<pid>/cmdline into memory.  */
   {
     char filename[6 + 10 + 8 + 1];
-    int fd;
-
     sprintf (filename, "/proc/%u/cmdline", (unsigned int) pid);
-    fd = open (filename, O_RDONLY | O_CLOEXEC);
+    int fd = open (filename, O_RDONLY | O_CLOEXEC);
     if (fd >= 0)
       {
         char buf[4096 + 1];
@@ -119,14 +114,12 @@ get_progname_of (pid_t pid)
         close (fd);
         if (nread >= 0)
           {
-            char *slash;
-
             /* NUL-terminate the buffer (just in case it does not have the
                expected format).  */
             buf[nread] = '\0';
             /* The program name and each argument is followed by a NUL byte.  */
             /* Find the portion after the last slash.  */
-            slash = strrchr (buf, '/');
+            char *slash = strrchr (buf, '/');
             return strdup (slash != NULL ? slash + 1 : buf);
           }
       }
@@ -139,19 +132,16 @@ get_progname_of (pid_t pid)
 
   /* Read the symlink /proc/<pid>/file.  */
   char filename[6 + 10 + 5 + 1];
-  char linkbuf[1024 + 1];
-  ssize_t linklen;
-
   sprintf (filename, "/proc/%u/file", (unsigned int) pid);
-  linklen = readlink (filename, linkbuf, sizeof (linkbuf) - 1);
+
+  char linkbuf[1024 + 1];
+  ssize_t linklen = readlink (filename, linkbuf, sizeof (linkbuf) - 1);
   if (linklen > 0)
     {
-      char *slash;
-
       /* NUL-terminate the link.  */
       linkbuf[linklen] = '\0';
       /* Find the portion after the last slash.  */
-      slash = strrchr (linkbuf, '/');
+      char *slash = strrchr (linkbuf, '/');
       return strdup (slash != NULL ? slash + 1 : linkbuf);
     }
 
@@ -161,10 +151,8 @@ get_progname_of (pid_t pid)
 
   /* Read the contents of /proc/<pid>/psinfo into memory.  */
   char filename[6 + 10 + 7 + 1];
-  int fd;
-
   sprintf (filename, "/proc/%u/psinfo", (unsigned int) pid);
-  fd = open (filename, O_RDONLY | O_CLOEXEC);
+  int fd = open (filename, O_RDONLY | O_CLOEXEC);
   if (fd >= 0)
     {
       char buf[4096 + 1];
@@ -172,15 +160,12 @@ get_progname_of (pid_t pid)
       close (fd);
       if (nread >= 0)
         {
-          char *p;
-          int count;
-
           /* NUL-terminate the buffer.  */
           buf[nread] = '\0';
 
           /* Search for the 4th space-separated field.  */
-          p = strchr (buf, ' ');
-          for (count = 1; p != NULL && count < 3; count++)
+          char *p = strchr (buf, ' ');
+          for (int count = 1; p != NULL && count < 3; count++)
             p = strchr (p + 1, ' ');
           if (p != NULL)
             {
@@ -203,19 +188,16 @@ get_progname_of (pid_t pid)
      When it succeeds, it doesn't truncate.  */
   {
     char filename[6 + 10 + 11 + 1];
-    char linkbuf[1024 + 1];
-    ssize_t linklen;
-
     sprintf (filename, "/proc/%u/path/a.out", (unsigned int) pid);
-    linklen = readlink (filename, linkbuf, sizeof (linkbuf) - 1);
+
+    char linkbuf[1024 + 1];
+    ssize_t linklen = readlink (filename, linkbuf, sizeof (linkbuf) - 1);
     if (linklen > 0)
       {
-        char *slash;
-
         /* NUL-terminate the link.  */
         linkbuf[linklen] = '\0';
         /* Find the portion after the last slash.  */
-        slash = strrchr (linkbuf, '/');
+        char *slash = strrchr (linkbuf, '/');
         return strdup (slash != NULL ? slash + 1 : linkbuf);
       }
   }
@@ -226,10 +208,8 @@ get_progname_of (pid_t pid)
      memory.  But it contains a lot of information that we don't need.  */
   {
     char filename[6 + 10 + 7 + 1];
-    int fd;
-
     sprintf (filename, "/proc/%u/psinfo", (unsigned int) pid);
-    fd = open (filename, O_RDONLY | O_CLOEXEC);
+    int fd = open (filename, O_RDONLY | O_CLOEXEC);
     if (fd >= 0)
       {
         /* The contents is a 'struct psinfo'.  But since 'struct psinfo'
@@ -263,9 +243,7 @@ get_progname_of (pid_t pid)
   int info_path[] =
     { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid, sizeof (struct kinfo_proc), 1 };
   struct kinfo_proc info;
-  size_t len;
-
-  len = sizeof (info);
+  size_t len = sizeof (info);
   if (sysctl (info_path, 6, &info, &len, NULL, 0) >= 0 && len == sizeof (info))
     return strdup (info.p_comm);
 
index c022c92f2d7b430eb5fad0165912d89556d313cc..8ddfd69593faf10a0ba1bc1e548d2c1d0b39b78a 100644 (file)
@@ -114,14 +114,13 @@ static int
 use_win32_p (void)
 {
   static int done = 0;
-  HMODULE h;
 
   if (done)
     return getaddrinfo_ptr ? 1 : 0;
 
   done = 1;
 
-  h = GetModuleHandle ("ws2_32.dll");
+  HMODULE h = GetModuleHandle ("ws2_32.dll");
 
   if (h)
     {
@@ -221,11 +220,6 @@ getaddrinfo (const char *restrict nodename,
              struct addrinfo **restrict res)
 #undef getaddrinfo
 {
-  struct addrinfo *tmp;
-  int port = 0;
-  struct hostent *he;
-  void *storage;
-  size_t size;
 # if HAVE_IPV6
   struct v6_pair {
     struct addrinfo addrinfo;
@@ -281,6 +275,7 @@ getaddrinfo (const char *restrict nodename,
 # endif
     }
 
+  int port = 0;
   if (servname)
     {
       struct servent *se = NULL;
@@ -306,10 +301,11 @@ getaddrinfo (const char *restrict nodename,
     }
 
   /* FIXME: Use gethostbyname_r if available. */
-  he = gethostbyname (nodename);
+  struct hostent *he = gethostbyname (nodename);
   if (!he || he->h_addr_list[0] == NULL)
     return EAI_NONAME;
 
+  size_t size;
   switch (he->h_addrtype)
     {
 # if HAVE_IPV6
@@ -328,10 +324,11 @@ getaddrinfo (const char *restrict nodename,
       return EAI_NODATA;
     }
 
-  storage = calloc (1, size);
+  void *storage = calloc (1, size);
   if (!storage)
     return EAI_MEMORY;
 
+  struct addrinfo *tmp;
   switch (he->h_addrtype)
     {
 # if HAVE_IPV6
@@ -446,9 +443,7 @@ freeaddrinfo (struct addrinfo *ai)
 
   while (ai)
     {
-      struct addrinfo *cur;
-
-      cur = ai;
+      struct addrinfo *cur = ai;
       ai = ai->ai_next;
 
       free (cur->ai_canonname);
index 155cf33f4abd9ba551968ee9533a7fab40f34748..6d1c3469a642a69120b6327e007d7d8319fab755 100644 (file)
@@ -45,8 +45,6 @@ typedef int dummy;
 char *
 rpl_getcwd (char *buf, size_t size)
 {
-  char *result;
-
   /* Handle single size operations.  */
   if (buf)
     {
@@ -67,7 +65,7 @@ rpl_getcwd (char *buf, size_t size)
           errno = ENOMEM;
           return NULL;
         }
-      result = getcwd (buf, size);
+      char *result = getcwd (buf, size);
       if (!result)
         free (buf);
       return result;
@@ -82,7 +80,7 @@ rpl_getcwd (char *buf, size_t size)
     char *ptr = getcwd (tmp, size);
     if (ptr)
       {
-        result = strdup (ptr);
+        char *result = strdup (ptr);
         if (!result)
           errno = ENOMEM;
         return result;
@@ -92,6 +90,7 @@ rpl_getcwd (char *buf, size_t size)
   }
 
   /* My what a large directory name we have.  */
+  char *result;
   do
     {
       size <<= 1;
index 05b5e56a3757cdce04979cbabee94d19dde5fea0..5e2d7501b4546ce289b3fb39a756f1eab7d93eee 100644 (file)
@@ -190,14 +190,6 @@ __getcwd_generic (char *buf, size_t size)
   size_t dotsize = sizeof dots;
   size_t dotlen = 0;
 #endif
-  DIR *dirstream = NULL;
-  dev_t rootdev, thisdev;
-  ino_t rootino, thisino;
-  char *dir;
-  register char *dirp;
-  struct stat64 st;
-  size_t allocated = size;
-  size_t used;
 
 #if HAVE_MINIMALLY_WORKING_GETCWD
   /* If AT_FDCWD is not defined, the algorithm below is O(N**2) and
@@ -215,9 +207,11 @@ __getcwd_generic (char *buf, size_t size)
      this wrong result with errno = 0.  */
 
 # undef getcwd
-  dir = getcwd_system (buf, size);
-  if (dir || (size && errno == ERANGE))
-    return dir;
+  {
+    char *dir = getcwd_system (buf, size);
+    if (dir || (size && errno == ERANGE))
+      return dir;
+  }
 
   /* Solaris getcwd (NULL, 0) fails with errno == EINVAL, but it has
      internal magic that lets it work even if an ancestor directory is
@@ -226,7 +220,7 @@ __getcwd_generic (char *buf, size_t size)
   if (errno == EINVAL && buf == NULL && size == 0)
     {
       char big_buffer[BIG_FILE_NAME_LENGTH + 1];
-      dir = getcwd_system (big_buffer, sizeof big_buffer);
+      char *dir = getcwd_system (big_buffer, sizeof big_buffer);
       if (dir)
         return strdup (dir);
     }
@@ -238,6 +232,8 @@ __getcwd_generic (char *buf, size_t size)
     return NULL;
 # endif
 #endif
+
+  size_t allocated = size;
   if (size == 0)
     {
       if (buf != NULL)
@@ -249,6 +245,7 @@ __getcwd_generic (char *buf, size_t size)
       allocated = BIG_FILE_NAME_LENGTH + 1;
     }
 
+  char *dir;
   if (buf == NULL)
     {
       dir = malloc (allocated);
@@ -258,56 +255,65 @@ __getcwd_generic (char *buf, size_t size)
   else
     dir = buf;
 
-  dirp = dir + allocated;
+  register char *dirp = dir + allocated;
   *--dirp = '\0';
 
-  if (__lstat64 (".", &st) < 0)
-    goto lose;
-  thisdev = st.st_dev;
-  thisino = st.st_ino;
+  DIR *dirstream = NULL;
+
+  dev_t thisdev;
+  ino_t thisino;
+  {
+    struct stat64 st;
+    if (__lstat64 (".", &st) < 0)
+      goto lose;
+    thisdev = st.st_dev;
+    thisino = st.st_ino;
+  }
 
-  if (__lstat64 ("/", &st) < 0)
-    goto lose;
-  rootdev = st.st_dev;
-  rootino = st.st_ino;
+  dev_t rootdev;
+  ino_t rootino;
+  {
+    struct stat64 st;
+    if (__lstat64 ("/", &st) < 0)
+      goto lose;
+    rootdev = st.st_dev;
+    rootino = st.st_ino;
+  }
 
   while (!(thisdev == rootdev && thisino == rootino))
     {
-      struct dirent64 *d;
+      /* Look at the parent directory.  */
       dev_t dotdev;
       ino_t dotino;
-      bool mount_point;
-      int parent_status;
-      size_t dirroom;
-      size_t namlen;
-      bool use_d_ino = true;
-
-      /* Look at the parent directory.  */
+      {
+        struct stat64 st;
+        int parent_status;
 #if HAVE_OPENAT_SUPPORT
-      fd = __openat64 (fd, "..", O_RDONLY);
-      if (fd < 0)
-        goto lose;
-      fd_needs_closing = true;
-      parent_status = __fstat64 (fd, &st);
+        fd = __openat64 (fd, "..", O_RDONLY);
+        if (fd < 0)
+          goto lose;
+        fd_needs_closing = true;
+        parent_status = __fstat64 (fd, &st);
 #else
-      dotlist[dotlen++] = '.';
-      dotlist[dotlen++] = '.';
-      dotlist[dotlen] = '\0';
-      parent_status = __lstat64 (dotlist, &st);
+        dotlist[dotlen++] = '.';
+        dotlist[dotlen++] = '.';
+        dotlist[dotlen] = '\0';
+        parent_status = __lstat64 (dotlist, &st);
 #endif
-      if (parent_status != 0)
-        goto lose;
-
-      if (dirstream && __closedir (dirstream) != 0)
-        {
-          dirstream = NULL;
+        if (parent_status != 0)
           goto lose;
-        }
 
+        if (dirstream && __closedir (dirstream) != 0)
+          {
+            dirstream = NULL;
+            goto lose;
+          }
+
+        dotdev = st.st_dev;
+        dotino = st.st_ino;
+      }
       /* Figure out if this directory is a mount point.  */
-      dotdev = st.st_dev;
-      dotino = st.st_ino;
-      mount_point = dotdev != thisdev;
+      bool mount_point = dotdev != thisdev;
 
       /* Search for the last directory.  */
 #if HAVE_OPENAT_SUPPORT
@@ -321,6 +327,8 @@ __getcwd_generic (char *buf, size_t size)
         goto lose;
       dotlist[dotlen++] = '/';
 #endif
+      struct dirent64 *d;
+      bool use_d_ino = true;
       for (;;)
         {
           /* Clear errno to distinguish EOF from error if readdir returns
@@ -363,6 +371,7 @@ __getcwd_generic (char *buf, size_t size)
             }
 
           {
+            struct stat64 st;
             int entry_status;
 #if HAVE_OPENAT_SUPPORT
             entry_status = __fstatat64 (fd, d->d_name, &st, AT_SYMLINK_NOFOLLOW);
@@ -415,8 +424,8 @@ __getcwd_generic (char *buf, size_t size)
           }
         }
 
-      dirroom = dirp - dir;
-      namlen = _D_EXACT_NAMLEN (d);
+      size_t dirroom = dirp - dir;
+      size_t namlen = _D_EXACT_NAMLEN (d);
 
       if (dirroom <= namlen)
         {
@@ -532,7 +541,7 @@ __getcwd_generic (char *buf, size_t size)
     free (dotlist);
 #endif
 
-  used = dir + allocated - dirp;
+  size_t used = dir + allocated - dirp;
   memmove (dir, dirp, used);
 
   if (size == 0)
index 4cd5eca1895950ce70531cc5eb1d94c4ed45b33e..4b4a0c9b1a64809149d917f31e2ce5cff9a5b664 100644 (file)
@@ -62,9 +62,6 @@ alloc_failed (void)
 ssize_t
 getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
 {
-  ssize_t result;
-  size_t cur_len = 0;
-
   if (lineptr == NULL || n == NULL
       /* glibc already declares this function as __nonnull ((4)).
          Avoid a gcc warning "‘nonnull’ argument â€˜fp’ compared to NULL".  */
@@ -79,6 +76,8 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
 
   flockfile (fp);
 
+  ssize_t result;
+
   if (*lineptr == NULL || *n == 0)
     {
       char *new_lineptr;
@@ -93,6 +92,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
       *lineptr = new_lineptr;
     }
 
+  size_t cur_len = 0;
   for (;;)
     {
       int i;
@@ -110,7 +110,6 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
           size_t needed_max =
             SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
           size_t needed = 2 * *n + 1;   /* Be generous. */
-          char *new_lineptr;
 
           if (needed_max < needed)
             needed = needed_max;
@@ -121,7 +120,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
               goto unlock_return;
             }
 
-          new_lineptr = (char *) realloc (*lineptr, needed);
+          char *new_lineptr = (char *) realloc (*lineptr, needed);
           if (new_lineptr == NULL)
             {
               alloc_failed ();
index 7178bd2e96039a3ee017b6d173d7e0372ff290a4..75697e4e4b003b49f7486d68c11b5211865bc783 100644 (file)
@@ -52,11 +52,9 @@ getdomainname (char *name, size_t len)
   return getdomainname (name, (int) len);
 #elif HAVE_SYSINFO && HAVE_SYS_SYSTEMINFO_H && defined SI_SRPC_DOMAIN
                                        /* Solaris */
-  int ret;
-
   /* The third argument is a 'long', but the return value must fit in an
      'int', therefore it's better to avoid arguments > INT_MAX.  */
-  ret = sysinfo (SI_SRPC_DOMAIN, name, len > INT_MAX ? INT_MAX : len);
+  int ret = sysinfo (SI_SRPC_DOMAIN, name, len > INT_MAX ? INT_MAX : len);
   if (ret < 0)
     /* errno is set here.  */
     return -1;
index c53322a7159279b4a8609f8cdef322887ee0fcef..f3947807dd7ad1c79cdf3d25659aabb1f317ac32 100644 (file)
 int
 getentropy (void *buffer, size_t length)
 {
-  char *buf = buffer;
 
   if (length <= 256)
-    for (;;)
-      {
-        ssize_t bytes;
-        if (length == 0)
-          return 0;
-        while ((bytes = getrandom (buf, length, 0)) < 0)
-          if (errno != EINTR)
-            return -1;
-        if (bytes == 0)
-          break;
-        buf += bytes;
-        length -= bytes;
-      }
+    {
+      char *buf = buffer;
+      for (;;)
+        {
+          if (length == 0)
+            return 0;
+          ssize_t bytes;
+          while ((bytes = getrandom (buf, length, 0)) < 0)
+            if (errno != EINTR)
+              return -1;
+          if (bytes == 0)
+            break;
+          buf += bytes;
+          length -= bytes;
+        }
+    }
 
   errno = EIO;
   return -1;
index 402206bf8860efa32336403b66ab26914b1cdee2..d788601db75afcb0d06efdc77eeea169446975fd 100644 (file)
@@ -68,9 +68,6 @@ int posix_getgroups (int, gid_t []) __asm ("_getgroups");
 int
 rpl_getgroups (int n, gid_t *group)
 {
-  int n_groups;
-  GETGROUPS_T *gbuf;
-
   if (n < 0)
     {
       errno = EINVAL;
@@ -79,19 +76,18 @@ rpl_getgroups (int n, gid_t *group)
 
   if (n != 0 || !GETGROUPS_ZERO_BUG)
     {
-      int result;
-      if (sizeof *group == sizeof *gbuf)
+      if (sizeof *group == sizeof (GETGROUPS_T))
         return getgroups (n, (GETGROUPS_T *) group);
 
-      if (SIZE_MAX / sizeof *gbuf <= n)
+      if (SIZE_MAX / sizeof (GETGROUPS_T) <= n)
         {
           errno = ENOMEM;
           return -1;
         }
-      gbuf = malloc (n * sizeof *gbuf);
+      GETGROUPS_T *gbuf = malloc (n * sizeof *gbuf);
       if (!gbuf)
         return -1;
-      result = getgroups (n, gbuf);
+      int result = getgroups (n, gbuf);
       if (0 <= result)
         {
           n = result;
@@ -108,18 +104,18 @@ rpl_getgroups (int n, gid_t *group)
       /* No need to worry about address arithmetic overflow here,
          since the ancient systems that we're running on have low
          limits on the number of secondary groups.  */
-      gbuf = malloc (n * sizeof *gbuf);
+      GETGROUPS_T *gbuf = malloc (n * sizeof *gbuf);
       if (!gbuf)
         return -1;
-      n_groups = getgroups (n, gbuf);
+      int n_groups = getgroups (n, gbuf);
       if (n_groups == -1 ? errno != EINVAL : n_groups < n)
-        break;
+        {
+          free (gbuf);
+          return n_groups;
+        }
       free (gbuf);
       n *= 2;
     }
-
-  free (gbuf);
-  return n_groups;
 }
 
 #endif /* HAVE_GETGROUPS */
index 8f0ceafcdaaf5c32eb251a9cbff89af172d95f70..57f93dc8671829b8c87dddfb14bf33e7971746e8 100644 (file)
@@ -89,12 +89,10 @@ gethostname (char *name, size_t len)
 int
 rpl_gethostname (char *name, size_t len)
 {
-  int r;
-
   if (len > INT_MAX)
     len = INT_MAX;
   gl_sockets_startup (SOCKETS_1_1);
-  r = gethostname (name, (int) len);
+  int r = gethostname (name, (int) len);
   if (r < 0)
     set_winsock_errno ();
 
index ec7305f5d48ea8cdbd0889f6be839740cd6d46ec..cf7e0154da560933017c20085cf5fbec087487ce 100644 (file)
@@ -384,51 +384,47 @@ getloadavg (double loadavg[], int nelem)
 # if !defined (LDAV_DONE) && defined (HAVE_LIBKSTAT)       /* Solaris <= 2.6 */
 /* Use libkstat because we don't have to be root.  */
 #  define LDAV_DONE
-  kstat_ctl_t *kc;
-  kstat_t *ksp;
-  kstat_named_t *kn;
-  int saved_errno;
-
-  kc = kstat_open ();
-  if (kc == NULL)
-    return -1;
-  ksp = kstat_lookup (kc, "unix", 0, "system_misc");
-  if (ksp == NULL)
-    return -1;
-  if (kstat_read (kc, ksp, 0) == -1)
-    return -1;
-
-
-  kn = kstat_data_lookup (ksp, "avenrun_1min");
-  if (kn == NULL)
-    {
-      /* Return -1 if no load average information is available.  */
-      nelem = 0;
-      elem = -1;
-    }
-
-  if (nelem >= 1)
-    loadavg[elem++] = (double) kn->value.ul / FSCALE;
-
-  if (nelem >= 2)
-    {
-      kn = kstat_data_lookup (ksp, "avenrun_5min");
-      if (kn != NULL)
-        {
-          loadavg[elem++] = (double) kn->value.ul / FSCALE;
+  {
+    kstat_ctl_t *kc = kstat_open ();
+    if (kc == NULL)
+      return -1;
+    kstat_t *ksp = kstat_lookup (kc, "unix", 0, "system_misc");
+    if (ksp == NULL)
+      return -1;
+    if (kstat_read (kc, ksp, 0) == -1)
+      return -1;
 
-          if (nelem >= 3)
-            {
-              kn = kstat_data_lookup (ksp, "avenrun_15min");
-              if (kn != NULL)
-                loadavg[elem++] = (double) kn->value.ul / FSCALE;
-            }
-        }
-    }
+    kstat_named_t *kn = kstat_data_lookup (ksp, "avenrun_1min");
+    if (kn == NULL)
+      {
+        /* Return -1 if no load average information is available.  */
+        nelem = 0;
+        elem = -1;
+      }
+
+    if (nelem >= 1)
+      loadavg[elem++] = (double) kn->value.ul / FSCALE;
+
+    if (nelem >= 2)
+      {
+        kn = kstat_data_lookup (ksp, "avenrun_5min");
+        if (kn != NULL)
+          {
+            loadavg[elem++] = (double) kn->value.ul / FSCALE;
+
+            if (nelem >= 3)
+              {
+                kn = kstat_data_lookup (ksp, "avenrun_15min");
+                if (kn != NULL)
+                  loadavg[elem++] = (double) kn->value.ul / FSCALE;
+              }
+          }
+      }
 
-  saved_errno = errno;
-  kstat_close (kc);
-  errno = saved_errno;
+    int saved_errno = errno;
+    kstat_close (kc);
+    errno = saved_errno;
+  }
 # endif /* HAVE_LIBKSTAT */
 
 # if !defined (LDAV_DONE) && defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC)
@@ -489,13 +485,12 @@ getloadavg (double loadavg[], int nelem)
 
   char ldavgbuf[3 * (INT_STRLEN_BOUND (int) + sizeof ".00 ")];
   char const *ptr = ldavgbuf;
-  int fd, count, saved_errno;
 
-  fd = open ("/proc/loadavg", O_RDONLY | O_CLOEXEC);
+  int fd = open ("/proc/loadavg", O_RDONLY | O_CLOEXEC);
   if (fd == -1)
     return -1;
-  count = read (fd, ldavgbuf, sizeof ldavgbuf - 1);
-  saved_errno = errno;
+  int count = read (fd, ldavgbuf, sizeof ldavgbuf - 1);
+  int saved_errno = errno;
   (void) close (fd);
   errno = saved_errno;
   if (count <= 0)
@@ -504,9 +499,6 @@ getloadavg (double loadavg[], int nelem)
 
   for (elem = 0; elem < nelem; elem++)
     {
-      double numerator = 0;
-      double denominator = 1;
-
       while (*ptr == ' ')
         ptr++;
 
@@ -522,6 +514,9 @@ getloadavg (double loadavg[], int nelem)
           break;
         }
 
+      double numerator = 0;
+      double denominator = 1;
+
       while ('0' <= *ptr && *ptr <= '9')
         numerator = 10 * numerator + (*ptr++ - '0');
 
@@ -544,12 +539,11 @@ getloadavg (double loadavg[], int nelem)
 #   define NETBSD_LDAV_FILE "/kern/loadavg"
 #  endif
 
-  unsigned long int load_ave[3], scale;
-  int count;
-  char readbuf[4 * INT_BUFSIZE_BOUND (unsigned long int) + 1];
   int fd = open (NETBSD_LDAV_FILE, O_RDONLY | O_CLOEXEC);
   if (fd < 0)
     return fd;
+
+  char readbuf[4 * INT_BUFSIZE_BOUND (unsigned long int) + 1];
   int nread = read (fd, readbuf, sizeof readbuf - 1);
   int saved_errno = errno;
   close (fd);
@@ -559,9 +553,11 @@ getloadavg (double loadavg[], int nelem)
       return -1;
     }
   readbuf[nread] = '\0';
-  count = sscanf (readbuf, "%lu %lu %lu %lu\n",
-                  &load_ave[0], &load_ave[1], &load_ave[2],
-                  &scale);
+
+  unsigned long int load_ave[3], scale;
+  int count = sscanf (readbuf, "%lu %lu %lu %lu\n",
+                      &load_ave[0], &load_ave[1], &load_ave[2],
+                      &scale);
   if (count != 4)
     {
       errno = ENOTSUP;
@@ -579,10 +575,6 @@ getloadavg (double loadavg[], int nelem)
 #  define LDAV_DONE
   /* The NeXT code was adapted from iscreen 3.2.  */
 
-  host_t host;
-  struct processor_set_basic_info info;
-  unsigned int info_count;
-
   /* We only know how to get the 1-minute average for this system,
      so even if the caller asks for more than 1, we only return 1.  */
 
@@ -594,7 +586,9 @@ getloadavg (double loadavg[], int nelem)
 
   if (getloadavg_initialized)
     {
-      info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
+      host_t host;
+      struct processor_set_basic_info info;
+      unsigned int info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
       if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host,
                               (processor_set_info_t) &info, &info_count)
           != KERN_SUCCESS)
@@ -620,11 +614,6 @@ getloadavg (double loadavg[], int nelem)
    can be gathered with inq_stats system calls.
    We only know how to get the 1-minute average for this system.  */
 
-  struct proc_summary proc_sum_data;
-  struct stat_descr proc_info;
-  double load;
-  register unsigned int j;
-
   if (cpus == 0)
     {
       register unsigned int c;
@@ -660,6 +649,9 @@ getloadavg (double loadavg[], int nelem)
       samples = cpus < 2 ? 3 : (2 * cpus / 3);
     }
 
+  struct proc_summary proc_sum_data;
+
+  struct stat_descr proc_info;
   proc_info.sd_next = 0;
   proc_info.sd_subsys = SUBSYS_PROC;
   proc_info.sd_type = PROCTYPE_SUMMARY;
@@ -670,8 +662,8 @@ getloadavg (double loadavg[], int nelem)
   if (inq_stats (1, &proc_info) != 0)
     return -1;
 
-  load = proc_sum_data.ps_nrunnable;
-  j = 0;
+  double load = proc_sum_data.ps_nrunnable;
+  register unsigned int j = 0;
   for (unsigned int i = samples - 1; i > 0; --i)
     {
       load += proc_sum_data.ps_nrun[j];
@@ -797,8 +789,6 @@ getloadavg (double loadavg[], int nelem)
 
 #  define LDAV_PRIVILEGED               /* This code requires special installation.  */
 
-  LOAD_AVE_TYPE load_ave[3];
-
   /* Get the address of LDAV_SYMBOL.  */
   if (offset == 0)
     {
@@ -857,6 +847,8 @@ getloadavg (double loadavg[], int nelem)
 #  endif /* SUNOS_5 */
     }
 
+  LOAD_AVE_TYPE load_ave[3];
+
   /* If we can, get the load average values.  */
   if (offset && getloadavg_initialized)
     {
index 27cc5f38e66a805fffcfc7c1a1bf8c0c2bfbd776..08900939d0e5cb18fc274293b36492f9522b9118 100644 (file)
@@ -130,10 +130,6 @@ locale_t
 newlocale (int category_mask, const char *name, locale_t base)
 #undef newlocale
 {
-  struct locale_categories_names names;
-  struct locale_hash_node *node;
-  locale_t result;
-
   /* Make sure name has indefinite extent.  */
   if (((LC_CTYPE_MASK | LC_NUMERIC_MASK | LC_TIME_MASK | LC_COLLATE_MASK
         | LC_MONETARY_MASK | LC_MESSAGES_MASK)
@@ -141,6 +137,7 @@ newlocale (int category_mask, const char *name, locale_t base)
     name = struniq (name);
 
   /* Determine the category names of the result.  */
+  struct locale_categories_names names;
   if (((LC_CTYPE_MASK | LC_NUMERIC_MASK | LC_TIME_MASK | LC_COLLATE_MASK
         | LC_MONETARY_MASK | LC_MESSAGES_MASK)
        & ~category_mask) == 0)
@@ -158,8 +155,8 @@ newlocale (int category_mask, const char *name, locale_t base)
           for (int i = 0; i < 6; i++)
             {
               int category = i + LCMIN;
-              int mask;
 
+              int mask;
               switch (category)
                 {
                 case LC_CTYPE:
@@ -192,8 +189,8 @@ newlocale (int category_mask, const char *name, locale_t base)
           for (int i = 0; i < 6; i++)
             {
               int category = i + LCMIN;
-              int mask;
 
+              int mask;
               switch (category)
                 {
                 case LC_CTYPE:
@@ -227,10 +224,10 @@ newlocale (int category_mask, const char *name, locale_t base)
         {
           /* Look up the names of base in the hash table.  Like multiple calls
              of get_locale_t_name, but locking only once.  */
-          struct locale_hash_node *p;
 
           /* Lock while looking up the hash node.  */
           gl_rwlock_rdlock (locale_lock);
+          struct locale_hash_node *p;
           for (p = locale_hash_table[locale_hash_function (base) % LOCALE_HASH_TABLE_SIZE];
                p != NULL;
                p = p->next)
@@ -240,8 +237,8 @@ newlocale (int category_mask, const char *name, locale_t base)
           for (int i = 0; i < 6; i++)
             {
               int category = i + LCMIN;
-              int mask;
 
+              int mask;
               switch (category)
                 {
                 case LC_CTYPE:
@@ -275,12 +272,13 @@ newlocale (int category_mask, const char *name, locale_t base)
         }
     }
 
-  node = (struct locale_hash_node *) malloc (sizeof (struct locale_hash_node));
+  struct locale_hash_node *node =
+    (struct locale_hash_node *) malloc (sizeof (struct locale_hash_node));
   if (node == NULL)
     /* errno is set to ENOMEM.  */
     return NULL;
 
-  result = newlocale (category_mask, name, base);
+  locale_t result = newlocale (category_mask, name, base);
   if (result == NULL)
     {
       free (node);
@@ -295,10 +293,10 @@ newlocale (int category_mask, const char *name, locale_t base)
   {
     size_t hashcode = locale_hash_function (result);
     size_t slot = hashcode % LOCALE_HASH_TABLE_SIZE;
-    struct locale_hash_node *p;
 
     /* Lock while inserting the new node.  */
     gl_rwlock_wrlock (locale_lock);
+    struct locale_hash_node *p;
     for (p = locale_hash_table[slot]; p != NULL; p = p->next)
       if (p->locale == result)
         {
@@ -327,19 +325,17 @@ locale_t
 duplocale (locale_t locale)
 #undef duplocale
 {
-  struct locale_hash_node *node;
-  locale_t result;
-
   if (locale == NULL)
     /* Invalid argument.  */
     abort ();
 
-  node = (struct locale_hash_node *) malloc (sizeof (struct locale_hash_node));
+  struct locale_hash_node *node =
+    (struct locale_hash_node *) malloc (sizeof (struct locale_hash_node));
   if (node == NULL)
     /* errno is set to ENOMEM.  */
     return NULL;
 
-  result = duplocale (locale);
+  locale_t result = duplocale (locale);
   if (result == NULL)
     {
       free (node);
@@ -362,11 +358,10 @@ duplocale (locale_t locale)
     }
   else
     {
-      struct locale_hash_node *p;
-
       /* Lock once, for the lookup and the insertion.  */
       gl_rwlock_wrlock (locale_lock);
 
+      struct locale_hash_node *p;
       for (p = locale_hash_table[locale_hash_function (locale) % LOCALE_HASH_TABLE_SIZE];
            p != NULL;
            p = p->next)
@@ -388,8 +383,8 @@ duplocale (locale_t locale)
   {
     size_t hashcode = locale_hash_function (result);
     size_t slot = hashcode % LOCALE_HASH_TABLE_SIZE;
-    struct locale_hash_node *p;
 
+    struct locale_hash_node *p;
     for (p = locale_hash_table[slot]; p != NULL; p = p->next)
       if (p->locale == result)
         {
@@ -425,9 +420,8 @@ freelocale (locale_t locale)
   {
     size_t hashcode = locale_hash_function (locale);
     size_t slot = hashcode % LOCALE_HASH_TABLE_SIZE;
-    struct locale_hash_node *found;
 
-    found = NULL;
+    struct locale_hash_node *found = NULL;
     /* Lock while removing the hash node.  */
     gl_rwlock_wrlock (locale_lock);
     for (struct locale_hash_node **p = &locale_hash_table[slot]; *p != NULL; p = &(*p)->next)
@@ -478,7 +472,6 @@ getlocalename_l_unsafe (int category, locale_t locale)
 #elif (defined __FreeBSD__ || defined __DragonFly__) || (defined __APPLE__ && defined __MACH__)
       /* FreeBSD >= 9.1, Mac OS X */
       int mask;
-
       switch (category)
         {
         case LC_CTYPE:
index eb31008ea12cb1524a2423f4ba76c483885acbe5..b5f937e5571ca195234105608f3c58796e950507 100644 (file)
@@ -54,14 +54,13 @@ getlogin_r (char *name, size_t size)
 #undef getlogin_r
 #if defined _WIN32 && ! defined __CYGWIN__
   /* Native Windows platform.  */
-  DWORD sz;
 
   /* When size > 0x7fff, the doc says that GetUserName will fail.
      Actually, on Windows XP SP3, it succeeds.  But let's be safe,
      for the sake of older Windows versions.  */
   if (size > 0x7fff)
     size = 0x7fff;
-  sz = size;
+  DWORD sz = size;
   if (!GetUserName (name, &sz))
     {
       if (GetLastError () == ERROR_INSUFFICIENT_BUFFER)
@@ -166,16 +165,13 @@ getlogin_r (char *name, size_t size)
   return ret;
 #else
   /* Platform with a getlogin() function.  */
-  char *n;
-  size_t nlen;
-
   errno = 0;
-  n = getlogin ();
+  char *n = getlogin ();
   if (!n)
     /* ENOENT is a reasonable errno value if getlogin returns NULL.  */
     return (errno != 0 ? errno : ENOENT);
 
-  nlen = strlen (n);
+  size_t nlen = strlen (n);
   if (size <= nlen)
     return ERANGE;
   memcpy (name, n, nlen + 1);
index c4f1cbd90dcde21668abee40b5729b26de109ff6..8735caeb1453e6ddc797564796791c9fee7ffd4b 100644 (file)
@@ -66,13 +66,8 @@ ssize_t
 getndelim2 (char **lineptr, size_t *linesize, size_t offset, size_t nmax,
             int delim1, int delim2, FILE *stream)
 {
-  size_t nbytes_avail;          /* Allocated but unused bytes in *LINEPTR.  */
-  char *read_pos;               /* Where we're reading into *LINEPTR. */
-  ssize_t bytes_stored = -1;
   char *ptr = *lineptr;
   size_t size = *linesize;
-  bool found_delimiter;
-
   if (!ptr)
     {
       size = nmax < MIN_CHUNK ? nmax : MIN_CHUNK;
@@ -81,11 +76,14 @@ getndelim2 (char **lineptr, size_t *linesize, size_t offset, size_t nmax,
         return -1;
     }
 
+  ssize_t bytes_stored = -1;
+
   if (size < offset)
     goto done;
 
-  nbytes_avail = size - offset;
-  read_pos = ptr + offset;
+  size_t nbytes_avail =          /* Allocated but unused bytes in *LINEPTR.  */
+    size - offset;
+  char *read_pos = ptr + offset; /* Where we're reading into *LINEPTR. */
 
   if (nbytes_avail == 0 && nmax <= size)
     goto done;
@@ -98,7 +96,7 @@ getndelim2 (char **lineptr, size_t *linesize, size_t offset, size_t nmax,
 
   flockfile (stream);
 
-  found_delimiter = false;
+  bool found_delimiter = false;
   do
     {
       /* Here always ptr + size == read_pos + nbytes_avail.
index d61bf8619c0df946eea37cdb6d1e23ae12580aeb..4f2c32f41ec222cda727a1b7165e4cdd28b4ba02 100644 (file)
@@ -133,7 +133,6 @@ exchange (char **argv, struct _getopt_data *d)
   int bottom = d->__first_nonopt;
   int middle = d->__last_nonopt;
   int top = d->optind;
-  char *tem;
 
   /* Exchange the shorter segment with the far end of the longer segment.
      That puts the shorter segment into the right place.
@@ -151,7 +150,7 @@ exchange (char **argv, struct _getopt_data *d)
          /* Swap it with the top part of the top segment.  */
          for (i = 0; i < len; i++)
            {
-             tem = argv[bottom + i];
+             char *tem = argv[bottom + i];
              argv[bottom + i] = argv[top - (middle - bottom) + i];
              argv[top - (middle - bottom) + i] = tem;
            }
@@ -167,7 +166,7 @@ exchange (char **argv, struct _getopt_data *d)
          /* Swap it with the bottom part of the bottom segment.  */
          for (i = 0; i < len; i++)
            {
-             tem = argv[bottom + i];
+             char *tem = argv[bottom + i];
              argv[bottom + i] = argv[middle + i];
              argv[middle + i] = tem;
            }
@@ -196,28 +195,29 @@ process_long_option (int argc, char **argv, const char *optstring,
                     int long_only, struct _getopt_data *d,
                     int print_errors, const char *prefix)
 {
-  char *nameend;
-  size_t namelen;
-  const struct option *p;
-  const struct option *pfound = NULL;
-  int n_options;
-  int option_index;
 
+  char *nameend;
   for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++)
     /* Do nothing.  */ ;
-  namelen = nameend - d->__nextchar;
+  size_t namelen = nameend - d->__nextchar;
 
   /* First look for an exact match, counting the options as a side
      effect.  */
-  for (p = longopts, n_options = 0; p->name; p++, n_options++)
-    if (!strncmp (p->name, d->__nextchar, namelen)
-       && namelen == strlen (p->name))
-      {
-       /* Exact match found.  */
-       pfound = p;
-       option_index = n_options;
-       break;
-      }
+  const struct option *pfound = NULL;
+  int n_options;
+  int option_index;
+  {
+    const struct option *p;
+    for (p = longopts, n_options = 0; p->name; p++, n_options++)
+      if (!strncmp (p->name, d->__nextchar, namelen)
+         && namelen == strlen (p->name))
+       {
+         /* Exact match found.  */
+         pfound = p;
+         option_index = n_options;
+         break;
+       }
+  }
 
   if (pfound == NULL)
     {
@@ -227,6 +227,7 @@ process_long_option (int argc, char **argv, const char *optstring,
       unsigned char ambig_fallback;
       void *ambig_malloced = NULL;
       int indfound = -1;
+      const struct option *p;
 
       for (p = longopts, option_index = 0; p->name; p++, option_index++)
        if (!strncmp (p->name, d->__nextchar, namelen))
@@ -475,11 +476,11 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
                    const struct option *longopts, int *longind,
                    int long_only, struct _getopt_data *d, int posixly_correct)
 {
-  int print_errors = d->opterr;
-
   if (argc < 1)
     return -1;
 
+  int print_errors = d->opterr;
+
   d->optarg = NULL;
 
   if (d->optind == 0 || !d->__initialized)
@@ -594,11 +595,10 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
          if (long_only && (argv[d->optind][2]
                            || !strchr (optstring, argv[d->optind][1])))
            {
-             int code;
              d->__nextchar = argv[d->optind] + 1;
-             code = process_long_option (argc, argv, optstring, longopts,
-                                         longind, long_only, d,
-                                         print_errors, "-");
+             int code = process_long_option (argc, argv, optstring, longopts,
+                                             longind, long_only, d,
+                                             print_errors, "-");
              if (code != -1)
                return code;
            }
@@ -707,14 +707,12 @@ _getopt_internal (int argc, char **argv, const char *optstring,
                  const struct option *longopts, int *longind, int long_only,
                  int posixly_correct)
 {
-  int result;
-
   getopt_data.optind = optind;
   getopt_data.opterr = opterr;
 
-  result = _getopt_internal_r (argc, argv, optstring, longopts,
-                              longind, long_only, &getopt_data,
-                              posixly_correct);
+  int result = _getopt_internal_r (argc, argv, optstring, longopts,
+                                  longind, long_only, &getopt_data,
+                                  posixly_correct);
 
   optind = getopt_data.optind;
   optarg = getopt_data.optarg;
@@ -751,14 +749,13 @@ GETOPT_ENTRY(getopt, 1)
 int
 main (int argc, char **argv)
 {
-  int c;
   int digit_optind = 0;
 
   while (1)
     {
       int this_option_optind = optind ? optind : 1;
 
-      c = getopt (argc, argv, "abc:d:0123456789");
+      int c = getopt (argc, argv, "abc:d:0123456789");
       if (c == -1)
        break;
 
index c8566845b7d5a8f4bb3961d33024ac5283593aea..e6781753b86caf5e41f6b2d3d2c65ed501e5d111 100644 (file)
@@ -73,7 +73,6 @@ _getopt_long_only_r (int argc, char **argv, const char *options,
 int
 main (int argc, char **argv)
 {
-  int c;
   int digit_optind = 0;
 
   while (1)
@@ -91,8 +90,8 @@ main (int argc, char **argv)
        {0, 0, 0, 0}
       };
 
-      c = getopt_long (argc, argv, "abc:d:0123456789",
-                      long_options, &option_index);
+      int c = getopt_long (argc, argv, "abc:d:0123456789",
+                          long_options, &option_index);
       if (c == -1)
        break;
 
index 36852d7f916b2fe3d8be37ace730645b741d949f..687d60f08f5e492af99de1bf171583e9efb2fbaa 100644 (file)
@@ -84,20 +84,11 @@ call_fclose (void *arg)
 char *
 getpass (const char *prompt)
 {
-  FILE *tty;
-  FILE *in, *out;
-# if HAVE_TCGETATTR
-  struct termios s, t;
-# endif
-  bool tty_changed = false;
-  static char *buf;
-  static size_t bufsize;
-  ssize_t nread;
-
   /* Try to write to and read from the terminal if we can.
      If we can't open the terminal, use stderr and stdin.  */
 
-  tty = fopen ("/dev/tty", "w+e");
+  FILE *tty = fopen ("/dev/tty", "w+e");
+  FILE *in, *out;
   if (tty == NULL)
     {
       in = stdin;
@@ -113,8 +104,11 @@ getpass (const char *prompt)
 
   flockfile (out);
 
+  bool tty_changed = false;
+
   /* Turn echoing off if it is on now.  */
 # if HAVE_TCGETATTR
+  struct termios s, t;
   if (tcgetattr (fileno (in), &t) == 0)
     {
       /* Save the old one. */
@@ -133,7 +127,9 @@ getpass (const char *prompt)
     }
 
   /* Read the password.  */
-  nread = getline (&buf, &bufsize, in);
+  static char *buf;
+  static size_t bufsize;
+  ssize_t nread = getline (&buf, &bufsize, in);
 
   /* According to the C standard, input may not be followed by output
      on the same stream without an intervening call to a file
@@ -194,35 +190,35 @@ getpass (const char *prompt)
 char *
 getpass (const char *prompt)
 {
-  char getpassbuf[PASS_MAX + 1];
-  size_t i = 0;
-  int c;
-
   if (prompt)
     {
       fputs (prompt, stderr);
       fflush (stderr);
     }
 
-  for (;;)
-    {
-      c = _getch ();
-      if (c == '\r')
-        {
-          getpassbuf[i] = '\0';
-          break;
-        }
-      else if (i < PASS_MAX)
-        {
-          getpassbuf[i++] = c;
-        }
-
-      if (i >= PASS_MAX)
-        {
-          getpassbuf[i] = '\0';
-          break;
-        }
-    }
+  char getpassbuf[PASS_MAX + 1];
+  {
+    size_t i = 0;
+    for (;;)
+      {
+        int c = _getch ();
+        if (c == '\r')
+          {
+            getpassbuf[i] = '\0';
+            break;
+          }
+        else if (i < PASS_MAX)
+          {
+            getpassbuf[i++] = c;
+          }
+
+        if (i >= PASS_MAX)
+          {
+            getpassbuf[i] = '\0';
+            break;
+          }
+      }
+  }
 
   if (prompt)
     {
index 4e424bc2362b61f744ba8ad727ca2be5c629b3a3..67abe494028af9490eb72247361f2c84d77e13f6 100644 (file)
@@ -228,27 +228,20 @@ getprogname (void)
   return p;
 # elif defined __SCO_VERSION__ || defined __sysv5__                /* SCO OpenServer6/UnixWare */
   char buf[80];
-  int fd;
   sprintf (buf, "/proc/%d/cmdline", getpid());
-  fd = open (buf, O_RDONLY);
+  int fd = open (buf, O_RDONLY);
   if (0 <= fd)
     {
       size_t n = read (fd, buf, 79);
       if (n > 0)
         {
           buf[n] = '\0'; /* Guarantee null-termination */
-          char *progname;
-          progname = strrchr (buf, '/');
+          char *progname = strrchr (buf, '/');
           if (progname)
-            {
-              progname = progname + 1; /* Skip the '/' */
-            }
+            progname = progname + 1; /* Skip the '/' */
           else
-            {
-              progname = buf;
-            }
-          char *ret;
-          ret = malloc (strlen (progname) + 1);
+            progname = buf;
+          char *ret = malloc (strlen (progname) + 1);
           if (ret)
             {
               strcpy (ret, progname);
index 46c738be0721d500676a8232841517c77af72d0d..81aff078f4a9b7626b9cf39613b215ee1aaba7dd 100644 (file)
@@ -91,9 +91,6 @@ getrusage (int who, struct rusage *usage_p)
                 clock_t user_ticks;
                 clock_t system_ticks;
 
-                uint64_t user_usec;
-                uint64_t system_usec;
-
                 if (who == RUSAGE_CHILDREN)
                   {
                     user_ticks   = time.tms_cutime;
@@ -105,10 +102,10 @@ getrusage (int who, struct rusage *usage_p)
                     system_ticks = time.tms_stime;
                   }
 
-                user_usec =
+                uint64_t user_usec =
                   (((uint64_t) user_ticks * (uint64_t) 1000000U)
                    + clocks_per_second / 2) / clocks_per_second;
-                system_usec =
+                uint64_t system_usec =
                   (((uint64_t) system_ticks * (uint64_t) 1000000U)
                    + clocks_per_second / 2) / clocks_per_second;
 
index 55176b0ae14dbf5db4d73fc8ec1dc82e5a41ed9c..9afdafbf5b050e015e524d976277b6ff75af833b 100644 (file)
@@ -53,7 +53,6 @@ rpl_getsockopt (int fd, int level, int optname, void *optval, socklen_t *optlen)
         {
           int milliseconds;
           int milliseconds_len = sizeof (int);
-          size_t n;
 
           r = getsockopt (sock, level, optname, (char *) &milliseconds,
                           &milliseconds_len);
@@ -61,7 +60,7 @@ rpl_getsockopt (int fd, int level, int optname, void *optval, socklen_t *optlen)
             .tv_sec = milliseconds / 1000,
             .tv_usec = (milliseconds % 1000) * 1000
           };
-          n = sizeof (struct timeval);
+          size_t n = sizeof (struct timeval);
           if (n > *optlen)
             n = *optlen;
           memcpy (optval, &tv, n);
index 35079d897825e6dad9cc01bb452fa227efa1455d..5510b29ce5765f3bcd78956ae90d945a4474bf38 100644 (file)
 int
 getsubopt (char **optionp, char *const *tokens, char **valuep)
 {
-  char *endp, *vstart;
-  int cnt;
-
   if (**optionp == '\0')
     return -1;
 
   /* Find end of next token.  */
-  endp = __strchrnul (*optionp, ',');
+  char *endp = __strchrnul (*optionp, ',');
 
   /* Find start of value.  */
-  vstart = memchr (*optionp, '=', endp - *optionp);
+  char *vstart = memchr (*optionp, '=', endp - *optionp);
   if (vstart == NULL)
     vstart = endp;
 
   /* Try to match the characters between *OPTIONP and VSTART against
      one of the TOKENS.  */
-  for (cnt = 0; tokens[cnt] != NULL; ++cnt)
+  for (int cnt = 0; tokens[cnt] != NULL; ++cnt)
     if (strncmp (*optionp, tokens[cnt], vstart - *optionp) == 0
         && tokens[cnt][vstart - *optionp] == '\0')
       {
index 0650abc9a3d7ec74703448f04cb9b5c31e294a5c..68f56f91962f87e49264ccca44f81b05660860ed 100644 (file)
@@ -298,12 +298,11 @@ dcpgettext_expr (const char *domain,
   if (msg_ctxt_id != NULL)
 #endif
     {
-      int found_translation;
       memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
       msg_ctxt_id[msgctxt_len - 1] = '\004';
       memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
       translation = dcgettext (domain, msg_ctxt_id, category);
-      found_translation = (translation != msg_ctxt_id);
+      int found_translation = (translation != msg_ctxt_id);
 #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
       if (msg_ctxt_id != buf)
         free (msg_ctxt_id);
@@ -346,12 +345,11 @@ dcnpgettext_expr (const char *domain,
   if (msg_ctxt_id != NULL)
 #endif
     {
-      int found_translation;
       memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
       msg_ctxt_id[msgctxt_len - 1] = '\004';
       memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
       translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
-      found_translation = !(translation == msg_ctxt_id || translation == msgid_plural);
+      int found_translation = !(translation == msg_ctxt_id || translation == msgid_plural);
 #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
       if (msg_ctxt_id != buf)
         free (msg_ctxt_id);
index 304e23b23c79d9aa3a4e5f6809ee703a21f78e7d..7e239a57232cd53eff2163c511877815bbf043b4 100644 (file)
@@ -92,12 +92,12 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz)
      microseconds.
      More discussion on this topic:
      <http://www.windowstimestamp.com/description>.  */
-  FILETIME current_time;
-
 # if !(_WIN32_WINNT >= _WIN32_WINNT_WIN8)
   if (!initialized)
     initialize ();
 # endif
+
+  FILETIME current_time;
   if (GetSystemTimePreciseAsFileTimeFunc != NULL)
     GetSystemTimePreciseAsFileTimeFunc (&current_time);
   else
index 6d17e43b6c4e1e7bf1278bbe085a5093e6e9a94b..a6353ef6f906eb6402b859fe8d42f32bcb397101 100644 (file)
@@ -71,20 +71,17 @@ getugroups (int maxcount, gid_t *grouplist, char const *username,
   setgrent ();
   while (1)
     {
-      struct group *grp;
-
       errno = 0;
-      grp = getgrent ();
+      struct group *grp = getgrent ();
       if (grp == NULL)
         break;
 
       for (char **cp = grp->gr_mem; *cp; ++cp)
         {
-          int n;
-
           if (streq (username, *cp))
             {
               /* See if this group number is already on the list.  */
+              int n;
               for (n = 0; n < count; ++n)
                 if (grouplist && grouplist[n] == grp->gr_gid)
                   break;
index f5daffb3aee53ae74563f1a84b5fda55197b350d..b9afb626ac68d041b07cbe66d1af19675620e479 100644 (file)
@@ -67,10 +67,10 @@ getumask (void)
   {
     /* In Linux >= 4.7, the umask can be retrieved from an "Umask:" line in the
        /proc/self/status file.  */
-    char buf[4096];
     int fd = open ("/proc/self/status", O_RDONLY);
     if (fd >= 0)
       {
+        char buf[4096];
         ssize_t n = read (fd, buf, sizeof (buf));
         if (n > 0)
           {
index e283828afe0a54060d7dde9717f716021a260ea9..09584909ae9e971138befda190ab47a64729ebe4 100644 (file)
@@ -148,21 +148,16 @@ rebalance (gl_list_t list,
 {
   for (;;)
     {
-      gl_list_node_t child;
-      int previous_balance;
-      int balance_diff;
-      gl_list_node_t nodeleft;
-      gl_list_node_t noderight;
-
-      child = node;
+      gl_list_node_t child = node;
       node = parent;
 
-      previous_balance = node->balance;
+      int previous_balance = node->balance;
 
       /* The balance of NODE is incremented by BALANCE_DIFF: +1 if the right
          branch's height has increased by 1 or the left branch's height has
          decreased by 1, -1 if the right branch's height has decreased by 1 or
          the left branch's height has increased by 1, 0 if no height change.  */
+      int balance_diff;
       if (node->left != NULL || node->right != NULL)
         balance_diff = (child == node->right ? height_diff : -height_diff);
       else
@@ -187,8 +182,8 @@ rebalance (gl_list_t list,
           else
             abort ();
 
-          nodeleft = node->left;
-          noderight = node->right;
+          gl_list_node_t nodeleft = node->left;
+          gl_list_node_t noderight = node->right;
 
           if (balance_diff < 0)
             {
@@ -462,16 +457,14 @@ gl_tree_remove_node_from_tree (gl_list_t list, gl_list_node_t node)
   else
     {
       /* Replace node with the rightmost element of the node->left subtree.  */
-      gl_list_node_t subst;
-      gl_list_node_t subst_parent;
-      gl_list_node_t child;
 
+      gl_list_node_t subst;
       for (subst = node->left; subst->right != NULL; )
         subst = subst->right;
 
-      subst_parent = subst->parent;
+      gl_list_node_t subst_parent = subst->parent;
 
-      child = subst->left;
+      gl_list_node_t child = subst->left;
 
       /* The case subst_parent == node is special:  If we do nothing special,
          we get confusion about node->left, subst->left and child->parent.
@@ -553,7 +546,6 @@ gl_tree_nx_add_first (gl_list_t list, const void *elt)
   else
     {
       gl_list_node_t node;
-
       for (node = list->root; node->left != NULL; )
         node = node->left;
 
@@ -617,7 +609,6 @@ gl_tree_nx_add_last (gl_list_t list, const void *elt)
   else
     {
       gl_list_node_t node;
-
       for (node = list->root; node->right != NULL; )
         node = node->right;
 
@@ -655,7 +646,6 @@ gl_tree_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
 {
   /* Create new node.  */
   gl_list_node_t new_node;
-  bool height_inc;
 
   new_node =
     (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl));
@@ -675,6 +665,7 @@ gl_tree_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
 #endif
 
   /* Add it to the tree.  */
+  bool height_inc;
   if (node->left == NULL)
     {
       node->left = new_node;
@@ -720,7 +711,6 @@ gl_tree_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
 {
   /* Create new node.  */
   gl_list_node_t new_node;
-  bool height_inc;
 
   new_node =
     (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl));
@@ -740,6 +730,7 @@ gl_tree_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
 #endif
 
   /* Add it to the tree.  */
+  bool height_inc;
   if (node->right == NULL)
     {
       node->right = new_node;
index 6dcb57f125335416c46c6d89a8d41d4e113ea739..0029907b8be83c5822ddbe5372a02221ff37553a 100644 (file)
@@ -31,12 +31,11 @@ hash_resize (CONTAINER_T container, size_t estimate)
   if (new_size > container->table_size)
     {
       gl_hash_entry_t *old_table = container->table;
-      /* Allocate the new table.  */
-      gl_hash_entry_t *new_table;
 
+      /* Allocate the new table.  */
       if (size_overflow_p (xtimes (new_size, sizeof (gl_hash_entry_t))))
         goto fail;
-      new_table =
+      gl_hash_entry_t *new_table =
         (gl_hash_entry_t *) calloc (new_size, sizeof (gl_hash_entry_t));
       if (new_table == NULL)
         goto fail;
index 4b7a42f64c3079894efc7435576f81bc1d712707..248910dc2af7620e53b4b83973345a75c8e2e2ed 100644 (file)
@@ -247,12 +247,12 @@ static const void * _GL_ATTRIBUTE_PURE
 gl_linked_get_at (gl_list_t list, size_t position)
 {
   size_t count = list->count;
-  gl_list_node_t node;
 
   if (!(position < count))
     /* Invalid argument.  */
     abort ();
   /* Here we know count > 0.  */
+  gl_list_node_t node;
   if (position <= ((count - 1) / 2))
     {
       node = list->root.next;
@@ -273,12 +273,12 @@ static gl_list_node_t
 gl_linked_nx_set_at (gl_list_t list, size_t position, const void *elt)
 {
   size_t count = list->count;
-  gl_list_node_t node;
 
   if (!(position < count))
     /* Invalid argument.  */
     abort ();
   /* Here we know count > 0.  */
+  gl_list_node_t node;
   if (position <= ((count - 1) / 2))
     {
       node = list->root.next;
@@ -455,13 +455,13 @@ gl_linked_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
           }
       }
 #else
-    gl_listelement_equals_fn equals = list->base.equals_fn;
-    gl_list_node_t node = list->root.next;
-
     end_index -= start_index;
+
+    gl_list_node_t node = list->root.next;
     for (; start_index > 0; start_index--)
       node = node->next;
 
+    gl_listelement_equals_fn equals = list->base.equals_fn;
     if (equals != NULL)
       {
         for (; end_index > 0; node = node->next, end_index--)
@@ -499,9 +499,9 @@ gl_linked_indexof_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_list_node_t node;
 
     /* First step: Look up the node.  */
+    gl_list_node_t node;
     if (!list->base.allow_duplicates)
       {
         /* Look for the first match in the hash bucket.  */
@@ -540,9 +540,7 @@ gl_linked_indexof_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.  */
-            size_t index;
-
-            index = start_index;
+            size_t index = start_index;
             node = list->root.next;
             for (; start_index > 0; start_index--)
               node = node->next;
@@ -568,7 +566,6 @@ gl_linked_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index,
     else
       {
         size_t index = 0;
-
         for (; node->prev != &list->root; node = node->prev)
           index++;
 
@@ -578,13 +575,13 @@ gl_linked_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index,
           return (size_t)(-1);
       }
 #else
-    gl_listelement_equals_fn equals = list->base.equals_fn;
     size_t index = start_index;
-    gl_list_node_t node = list->root.next;
 
+    gl_list_node_t node = list->root.next;
     for (; start_index > 0; start_index--)
       node = node->next;
 
+    gl_listelement_equals_fn equals = list->base.equals_fn;
     if (equals != NULL)
       {
         for (;
@@ -790,11 +787,10 @@ gl_linked_nx_add_at (gl_list_t list, size_t position, const void *elt)
   /* Add new_node to the list.  */
   if (position <= (count / 2))
     {
-      gl_list_node_t node;
-
-      node = &list->root;
+      gl_list_node_t node = &list->root;
       for (; position > 0; position--)
         node = node->next;
+
       new_node->prev = node;
       ASYNCSAFE(gl_list_node_t) new_node->next = node->next;
       new_node->next->prev = new_node;
@@ -802,12 +798,12 @@ gl_linked_nx_add_at (gl_list_t list, size_t position, const void *elt)
     }
   else
     {
-      gl_list_node_t node;
-
       position = count - position;
-      node = &list->root;
+
+      gl_list_node_t node = &list->root;
       for (; position > 0; position--)
         node = node->prev;
+
       ASYNCSAFE(gl_list_node_t) new_node->next = node;
       new_node->prev = node->prev;
       ASYNCSAFE(gl_list_node_t) new_node->prev->next = new_node;
@@ -825,17 +821,14 @@ gl_linked_nx_add_at (gl_list_t list, size_t position, const void *elt)
 static bool
 gl_linked_remove_node (gl_list_t list, gl_list_node_t node)
 {
-  gl_list_node_t prev;
-  gl_list_node_t next;
-
 #if WITH_HASHTABLE
   /* Remove node from the hash table.  */
   remove_from_bucket (list, node);
 #endif
 
   /* Remove node from the list.  */
-  prev = node->prev;
-  next = node->next;
+  gl_list_node_t prev = node->prev;
+  gl_list_node_t next = node->next;
 
   ASYNCSAFE(gl_list_node_t) prev->next = next;
   next->prev = prev;
@@ -851,36 +844,33 @@ static bool
 gl_linked_remove_at (gl_list_t list, size_t position)
 {
   size_t count = list->count;
-  gl_list_node_t removed_node;
 
   if (!(position < count))
     /* Invalid argument.  */
     abort ();
   /* Here we know count > 0.  */
+  gl_list_node_t removed_node;
   if (position <= ((count - 1) / 2))
     {
-      gl_list_node_t node;
-      gl_list_node_t after_removed;
-
-      node = &list->root;
+      gl_list_node_t node = &list->root;
       for (; position > 0; position--)
         node = node->next;
+
       removed_node = node->next;
-      after_removed = node->next->next;
+      gl_list_node_t after_removed = node->next->next;
       ASYNCSAFE(gl_list_node_t) node->next = after_removed;
       after_removed->prev = node;
     }
   else
     {
-      gl_list_node_t node;
-      gl_list_node_t before_removed;
-
       position = count - 1 - position;
-      node = &list->root;
+
+      gl_list_node_t node = &list->root;
       for (; position > 0; position--)
         node = node->prev;
+
       removed_node = node->prev;
-      before_removed = node->prev->prev;
+      gl_list_node_t before_removed = node->prev->prev;
       node->prev = before_removed;
       ASYNCSAFE(gl_list_node_t) before_removed->next = node;
     }
@@ -965,12 +955,11 @@ gl_linked_iterator_from_to (gl_list_t list,
   if (n1 > n2 && n1 > n3)
     {
       /* n1 is the maximum, use n2 and n3.  */
-      gl_list_node_t node;
-
-      node = &list->root;
+      gl_list_node_t node = &list->root;
       for (size_t i = n3; i > 0; i--)
         node = node->prev;
       result.q = node;
+
       for (size_t i = n2; i > 0; i--)
         node = node->prev;
       result.p = node;
@@ -978,9 +967,7 @@ gl_linked_iterator_from_to (gl_list_t list,
   else if (n2 > n3)
     {
       /* n2 is the maximum, use n1 and n3.  */
-      gl_list_node_t node;
-
-      node = list->root.next;
+      gl_list_node_t node = list->root.next;
       for (size_t i = n1; i > 0; i--)
         node = node->next;
       result.p = node;
@@ -993,12 +980,11 @@ gl_linked_iterator_from_to (gl_list_t list,
   else
     {
       /* n3 is the maximum, use n1 and n2.  */
-      gl_list_node_t node;
-
-      node = list->root.next;
+      gl_list_node_t node = list->root.next;
       for (size_t i = n1; i > 0; i--)
         node = node->next;
       result.p = node;
+
       for (size_t i = n2; i > 0; i--)
         node = node->next;
       result.q = node;
@@ -1070,8 +1056,8 @@ gl_linked_sortedlist_search_from_to (gl_list_t list,
     {
       /* Here we know low < count.  */
       size_t position = low;
-      gl_list_node_t node;
 
+      gl_list_node_t node;
       if (position <= ((count - 1) / 2))
         {
           node = list->root.next;
@@ -1140,8 +1126,8 @@ gl_linked_sortedlist_indexof_from_to (gl_list_t list,
       /* Here we know low < count.  */
       size_t index = low;
       size_t position = low;
-      gl_list_node_t node;
 
+      gl_list_node_t node;
       if (position <= ((count - 1) / 2))
         {
           node = list->root.next;
index 4272606a5de94cf6b9e34254b33fca46525fcd19..1ff55568ec524afd22a4e1afa988732df106eb00 100644 (file)
@@ -232,8 +232,6 @@ rebalance_after_add (gl_list_t list, gl_list_node_t node, gl_list_node_t parent)
       /* At this point, parent = node->parent != NULL.
          Think of node->color being RED (although node->color is not yet
          assigned.)  */
-      gl_list_node_t grandparent;
-      gl_list_node_t uncle;
 
       if (parent->color == BLACK)
         {
@@ -242,10 +240,11 @@ rebalance_after_add (gl_list_t list, gl_list_node_t node, gl_list_node_t parent)
           return;
         }
 
-      grandparent = parent->parent;
+      gl_list_node_t grandparent = parent->parent;
       /* Since parent is RED, we know that
          grandparent is != NULL and colored BLACK.  */
 
+      gl_list_node_t uncle;
       if (grandparent->left == parent)
         uncle = grandparent->right;
       else if (grandparent->right == parent)
@@ -694,19 +693,16 @@ gl_tree_remove_node_from_tree (gl_list_t list, gl_list_node_t node)
   else
     {
       /* Replace node with the rightmost element of the node->left subtree.  */
-      gl_list_node_t subst;
-      gl_list_node_t subst_parent;
-      gl_list_node_t child;
-      color_t removed_color;
 
+      gl_list_node_t subst;
       for (subst = node->left; subst->right != NULL; )
         subst = subst->right;
 
-      subst_parent = subst->parent;
+      gl_list_node_t subst_parent = subst->parent;
 
-      child = subst->left;
+      gl_list_node_t child = subst->left;
 
-      removed_color = subst->color;
+      color_t removed_color = subst->color;
 
       /* The case subst_parent == node is special:  If we do nothing special,
          we get confusion about node->left, subst->left and child->parent.
@@ -796,7 +792,6 @@ gl_tree_nx_add_first (gl_list_t list, const void *elt)
   else
     {
       gl_list_node_t node;
-
       for (node = list->root; node->left != NULL; )
         node = node->left;
 
@@ -858,7 +853,6 @@ gl_tree_nx_add_last (gl_list_t list, const void *elt)
   else
     {
       gl_list_node_t node;
-
       for (node = list->root; node->right != NULL; )
         node = node->right;
 
index 6f2d157f812523e63048e7145514404ec94d912d..ad9ef8e247905c9ff15d553d9c6c9eff54410756 100644 (file)
@@ -582,16 +582,17 @@ static gl_list_iterator_t _GL_ATTRIBUTE_PURE
 gl_tree_iterator (gl_list_t list)
 {
   gl_list_iterator_t result;
-  gl_list_node_t node;
 
   result.vtable = list->base.vtable;
   result.list = list;
-  /* Start node is the leftmost node.  */
-  node = list->root;
-  if (node != NULL)
-    while (node->left != NULL)
-      node = node->left;
-  result.p = node;
+  {
+    /* Start node is the leftmost node.  */
+    gl_list_node_t node = list->root;
+    if (node != NULL)
+      while (node->left != NULL)
+        node = node->left;
+    result.p = node;
+  }
   /* End point is past the rightmost node.  */
   result.q = NULL;
 #if defined GCC_LINT || defined lint
@@ -844,14 +845,14 @@ gl_tree_sortedlist_indexof_from_to (gl_list_t list,
                                     size_t low, size_t high,
                                     const void *elt)
 {
-  gl_list_node_t node;
-  size_t position;
-
   if (!(low <= high
         && high <= (list->root != NULL ? list->root->branch_size : 0)))
     /* Invalid arguments.  */
     abort ();
 
+  gl_list_node_t node;
+  size_t position;
+
   for (node = list->root, position = 0; node != NULL; )
     {
       size_t left_branch_size =
index 9660d87b176b9bb177ead2a10602888bcab16b7e..757eb83c176e213c12e94eda476cd0e17801bbd7 100644 (file)
@@ -119,7 +119,6 @@ static int
 gl_tree_nx_getput (gl_omap_t map, const void *key, const void *value,
                    const void **oldvaluep)
 {
-  gl_mapkey_compar_fn compar;
   gl_omap_node_t node = map->root;
 
   if (node == NULL)
@@ -129,7 +128,7 @@ gl_tree_nx_getput (gl_omap_t map, const void *key, const void *value,
       return 1;
     }
 
-  compar = map->base.compar_fn;
+  gl_mapkey_compar_fn compar = map->base.compar_fn;
 
   for (;;)
     {
@@ -245,16 +244,17 @@ static gl_omap_iterator_t _GL_ATTRIBUTE_PURE
 gl_tree_iterator (gl_omap_t map)
 {
   gl_omap_iterator_t result;
-  gl_omap_node_t node;
 
   result.vtable = map->base.vtable;
   result.map = map;
-  /* Start node is the leftmost node.  */
-  node = map->root;
-  if (node != NULL)
-    while (node->left != NULL)
-      node = node->left;
-  result.p = node;
+  {
+    /* Start node is the leftmost node.  */
+    gl_omap_node_t node = map->root;
+    if (node != NULL)
+      while (node->left != NULL)
+        node = node->left;
+    result.p = node;
+  }
   /* End point is past the rightmost node.  */
   result.q = NULL;
 #if defined GCC_LINT || defined lint
index d0717913d03a829dd4c69ddd71db2e2e8aa11c9c..4083b9b545817fa784fd04de44d0451005006f3a 100644 (file)
@@ -173,7 +173,6 @@ gl_tree_search_node (gl_oset_t set, const void *elt)
 static int
 gl_tree_nx_add (gl_oset_t set, const void *elt)
 {
-  gl_setelement_compar_fn compar;
   gl_oset_node_t node = set->root;
 
   if (node == NULL)
@@ -183,7 +182,7 @@ gl_tree_nx_add (gl_oset_t set, const void *elt)
       return true;
     }
 
-  compar = set->base.compar_fn;
+  gl_setelement_compar_fn compar = set->base.compar_fn;
 
   for (;;)
     {
@@ -255,12 +254,11 @@ gl_tree_update (gl_oset_t set, const void *elt,
                   && (next_node == NULL || next_node->value > elt)))
             {
               /* old_node needs to move in the tree.  */
-              gl_oset_node_t node;
 
               /* Remove the node from the tree.  Don't free it.  */
               gl_tree_remove_node_no_free (set, old_node);
 
-              node = set->root;
+              gl_oset_node_t node = set->root;
 
               for (;;)
                 {
@@ -350,16 +348,17 @@ static gl_oset_iterator_t _GL_ATTRIBUTE_PURE
 gl_tree_iterator (gl_oset_t set)
 {
   gl_oset_iterator_t result;
-  gl_oset_node_t node;
 
   result.vtable = set->base.vtable;
   result.set = set;
-  /* Start node is the leftmost node.  */
-  node = set->root;
-  if (node != NULL)
-    while (node->left != NULL)
-      node = node->left;
-  result.p = node;
+  {
+    /* Start node is the leftmost node.  */
+    gl_oset_node_t node = set->root;
+    if (node != NULL)
+      while (node->left != NULL)
+        node = node->left;
+    result.p = node;
+  }
   /* End point is past the rightmost node.  */
   result.q = NULL;
 #if defined GCC_LINT || defined lint
index 9ec21093991ef0aa14d1fe9db006dcef9e2b019e..99e9e4c3b99fd44e00ea5c6f66b76d086ec26ce6 100644 (file)
@@ -137,10 +137,7 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node)
                     {
                       /* Found already a node with the same value.  Turn it
                          into an ordered set, and add new_node to it.  */
-                      gl_oset_t nodes;
-                      struct gl_multiple_nodes *multi_entry;
-
-                      nodes =
+                      gl_oset_t nodes =
                         gl_oset_nx_create_empty (OSET_TREE_FLAVOR,
                                                  compare_by_position, NULL);
                       if (nodes == NULL)
@@ -151,7 +148,7 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node)
                       if (gl_oset_nx_add (nodes, new_node) < 0)
                         goto fail;
 
-                      multi_entry =
+                      struct gl_multiple_nodes *multi_entry =
                        (struct gl_multiple_nodes *) malloc (sizeof (struct gl_multiple_nodes));
                       if (multi_entry == NULL)
                         goto fail;
index 592f0862af8a321e87339cfee94d109c4f145b76..385cece876944117c91d3319ae8781d0a1bd9c0c 100644 (file)
@@ -259,17 +259,13 @@ gl_array_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
 static int
 grow (gl_list_t list)
 {
-  size_t new_allocated;
-  size_t memory_size;
-  const void **memory;
-
-  new_allocated = xtimes (list->allocated, 2);
+  size_t new_allocated = xtimes (list->allocated, 2);
   new_allocated = xsum (new_allocated, 1);
-  memory_size = xtimes (new_allocated, sizeof (const void *));
+  size_t memory_size = xtimes (new_allocated, sizeof (const void *));
   if (size_overflow_p (memory_size))
     /* Overflow, would lead to out of memory.  */
     return -1;
-  memory = (const void **) realloc (list->elements, memory_size);
+  const void **memory = (const void **) realloc (list->elements, memory_size);
   if (memory == NULL)
     /* Out of memory.  */
     return -1;
@@ -282,12 +278,11 @@ static gl_list_node_t
 gl_array_nx_add_first (gl_list_t list, const void *elt)
 {
   size_t count = list->count;
-  const void **elements;
 
   if (count == list->allocated)
     if (grow (list) < 0)
       return NULL;
-  elements = list->elements;
+  const void **elements = list->elements;
   for (size_t i = count; i > 0; i--)
     elements[i] = elements[i - 1];
   elements[0] = elt;
@@ -313,17 +308,15 @@ gl_array_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
 {
   size_t count = list->count;
   uintptr_t index = NODE_TO_INDEX (node);
-  size_t position;
-  const void **elements;
 
   if (!(index < count))
     /* Invalid argument.  */
     abort ();
-  position = index;
+  size_t position = index;
   if (count == list->allocated)
     if (grow (list) < 0)
       return NULL;
-  elements = list->elements;
+  const void **elements = list->elements;
   for (size_t i = count; i > position; i--)
     elements[i] = elements[i - 1];
   elements[position] = elt;
@@ -336,17 +329,15 @@ gl_array_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
 {
   size_t count = list->count;
   uintptr_t index = NODE_TO_INDEX (node);
-  size_t position;
-  const void **elements;
 
   if (!(index < count))
     /* Invalid argument.  */
     abort ();
-  position = index + 1;
+  size_t position = index + 1;
   if (count == list->allocated)
     if (grow (list) < 0)
       return NULL;
-  elements = list->elements;
+  const void **elements = list->elements;
   for (size_t i = count; i > position; i--)
     elements[i] = elements[i - 1];
   elements[position] = elt;
@@ -358,7 +349,6 @@ static gl_list_node_t
 gl_array_nx_add_at (gl_list_t list, size_t position, const void *elt)
 {
   size_t count = list->count;
-  const void **elements;
 
   if (!(position <= count))
     /* Invalid argument.  */
@@ -366,7 +356,7 @@ gl_array_nx_add_at (gl_list_t list, size_t position, const void *elt)
   if (count == list->allocated)
     if (grow (list) < 0)
       return NULL;
-  elements = list->elements;
+  const void **elements = list->elements;
   for (size_t i = count; i > position; i--)
     elements[i] = elements[i - 1];
   elements[position] = elt;
@@ -379,14 +369,12 @@ gl_array_remove_node (gl_list_t list, gl_list_node_t node)
 {
   size_t count = list->count;
   uintptr_t index = NODE_TO_INDEX (node);
-  size_t position;
-  const void **elements;
 
   if (!(index < count))
     /* Invalid argument.  */
     abort ();
-  position = index;
-  elements = list->elements;
+  size_t position = index;
+  const void **elements = list->elements;
   if (list->base.dispose_fn != NULL)
     list->base.dispose_fn (elements[position]);
   for (size_t i = position + 1; i < count; i++)
@@ -399,12 +387,11 @@ static bool
 gl_array_remove_at (gl_list_t list, size_t position)
 {
   size_t count = list->count;
-  const void **elements;
 
   if (!(position < count))
     /* Invalid argument.  */
     abort ();
-  elements = list->elements;
+  const void **elements = list->elements;
   if (list->base.dispose_fn != NULL)
     list->base.dispose_fn (elements[position]);
   for (size_t i = position + 1; i < count; i++)
index 35ac174b61ad252b9ded5c71fb810bd900d17f93..a185a567a23c888acb5c652f2791bb23419cc074 100644 (file)
@@ -117,17 +117,13 @@ gl_array_search (gl_map_t map, const void *key, const void **valuep)
 static int
 grow (gl_map_t map)
 {
-  size_t new_allocated;
-  size_t memory_size;
-  struct pair *memory;
-
-  new_allocated = xtimes (map->allocated, 2);
+  size_t new_allocated = xtimes (map->allocated, 2);
   new_allocated = xsum (new_allocated, 1);
-  memory_size = xtimes (new_allocated, sizeof (struct pair));
+  size_t memory_size = xtimes (new_allocated, sizeof (struct pair));
   if (size_overflow_p (memory_size))
     /* Overflow, would lead to out of memory.  */
     return -1;
-  memory = (struct pair *) realloc (map->pairs, memory_size);
+  struct pair *memory = (struct pair *) realloc (map->pairs, memory_size);
   if (memory == NULL)
     /* Out of memory.  */
     return -1;
@@ -150,12 +146,10 @@ gl_array_nx_getput (gl_map_t map, const void *key, const void *value,
   else
     {
       size_t count = map->count;
-      struct pair *pairs;
-
       if (count == map->allocated)
         if (grow (map) < 0)
           return -1;
-      pairs = map->pairs;
+      struct pair *pairs = map->pairs;
       pairs[count].key = key;
       pairs[count].value = value;
       map->count = count + 1;
@@ -169,9 +163,7 @@ static void
 gl_array_remove_at (gl_map_t map, size_t position)
 {
   size_t count = map->count;
-  struct pair *pairs;
-
-  pairs = map->pairs;
+  struct pair *pairs = map->pairs;
   if (map->base.kdispose_fn != NULL)
     map->base.kdispose_fn (pairs[position].key);
   for (size_t i = position + 1; i < count; i++)
index 83cd00785078204e0062bd3a91840d2f9e2cec07..4c9eb7ea9a8f326b037b4933b96584051adbf1c7 100644 (file)
@@ -178,17 +178,13 @@ gl_array_search_atleast (gl_omap_t map,
 static int
 grow (gl_omap_t map)
 {
-  size_t new_allocated;
-  size_t memory_size;
-  struct pair *memory;
-
-  new_allocated = xtimes (map->allocated, 2);
+  size_t new_allocated = xtimes (map->allocated, 2);
   new_allocated = xsum (new_allocated, 1);
-  memory_size = xtimes (new_allocated, sizeof (struct pair));
+  size_t memory_size = xtimes (new_allocated, sizeof (struct pair));
   if (size_overflow_p (memory_size))
     /* Overflow, would lead to out of memory.  */
     return -1;
-  memory = (struct pair *) realloc (map->pairs, memory_size);
+  struct pair *memory = (struct pair *) realloc (map->pairs, memory_size);
   if (memory == NULL)
     /* Out of memory.  */
     return -1;
@@ -205,12 +201,10 @@ gl_array_nx_add_at (gl_omap_t map, size_t position,
                     const void *key, const void *value)
 {
   size_t count = map->count;
-  struct pair *pairs;
-
   if (count == map->allocated)
     if (grow (map) < 0)
       return -1;
-  pairs = map->pairs;
+  struct pair *pairs = map->pairs;
   for (size_t i = count; i > position; i--)
     pairs[i] = pairs[i - 1];
   pairs[position].key = key;
@@ -265,9 +259,7 @@ static void
 gl_array_remove_at (gl_omap_t map, size_t position)
 {
   size_t count = map->count;
-  struct pair *pairs;
-
-  pairs = map->pairs;
+  struct pair *pairs = map->pairs;
   if (map->base.kdispose_fn != NULL)
     map->base.kdispose_fn (pairs[position].key);
   for (size_t i = position + 1; i < count; i++)
index eeb8aede83b58d3e7bed9cf4238d348691aa59b9..ed1aea666e21610a276d1887395b1976e6ef8887 100644 (file)
@@ -182,17 +182,13 @@ gl_array_search_atleast (gl_oset_t set,
 static int
 grow (gl_oset_t set)
 {
-  size_t new_allocated;
-  size_t memory_size;
-  const void **memory;
-
-  new_allocated = xtimes (set->allocated, 2);
+  size_t new_allocated = xtimes (set->allocated, 2);
   new_allocated = xsum (new_allocated, 1);
-  memory_size = xtimes (new_allocated, sizeof (const void *));
+  size_t memory_size = xtimes (new_allocated, sizeof (const void *));
   if (size_overflow_p (memory_size))
     /* Overflow, would lead to out of memory.  */
     return -1;
-  memory = (const void **) realloc (set->elements, memory_size);
+  const void **memory = (const void **) realloc (set->elements, memory_size);
   if (memory == NULL)
     /* Out of memory.  */
     return -1;
@@ -208,12 +204,10 @@ static int
 gl_array_nx_add_at (gl_oset_t set, size_t position, const void *elt)
 {
   size_t count = set->count;
-  const void **elements;
-
   if (count == set->allocated)
     if (grow (set) < 0)
       return -1;
-  elements = set->elements;
+  const void **elements = set->elements;
   for (size_t i = count; i > position; i--)
     elements[i] = elements[i - 1];
   elements[position] = elt;
@@ -227,9 +221,7 @@ static void
 gl_array_remove_at (gl_oset_t set, size_t position)
 {
   size_t count = set->count;
-  const void **elements;
-
-  elements = set->elements;
+  const void **elements = set->elements;
   if (set->base.dispose_fn != NULL)
     set->base.dispose_fn (elements[position]);
   for (size_t i = position + 1; i < count; i++)
index d1626236029fa5c464167ada4b51962c9a62556d..9a738167415eb3195facb60e9bc6c87e5a7730dd 100644 (file)
@@ -97,17 +97,13 @@ gl_array_search (gl_set_t set, const void *elt)
 static int
 grow (gl_set_t set)
 {
-  size_t new_allocated;
-  size_t memory_size;
-  const void **memory;
-
-  new_allocated = xtimes (set->allocated, 2);
+  size_t new_allocated = xtimes (set->allocated, 2);
   new_allocated = xsum (new_allocated, 1);
-  memory_size = xtimes (new_allocated, sizeof (const void *));
+  size_t memory_size = xtimes (new_allocated, sizeof (const void *));
   if (size_overflow_p (memory_size))
     /* Overflow, would lead to out of memory.  */
     return -1;
-  memory = (const void **) realloc (set->elements, memory_size);
+  const void **memory = (const void **) realloc (set->elements, memory_size);
   if (memory == NULL)
     /* Out of memory.  */
     return -1;
index e25ce5eb9139a5049a0d7815bc95d0b46cb9c876..4704c31f3ed45cb23b3b8ecbbed105fc9f326c0c 100644 (file)
@@ -67,21 +67,16 @@ rebalance (CONTAINER_T container,
 {
   for (;;)
     {
-      NODE_T child;
-      int previous_balance;
-      int balance_diff;
-      NODE_T nodeleft;
-      NODE_T noderight;
-
-      child = node;
+      NODE_T child = node;
       node = parent;
 
-      previous_balance = node->balance;
+      int previous_balance = node->balance;
 
       /* The balance of NODE is incremented by BALANCE_DIFF: +1 if the right
          branch's height has increased by 1 or the left branch's height has
          decreased by 1, -1 if the right branch's height has decreased by 1 or
          the left branch's height has increased by 1, 0 if no height change.  */
+      int balance_diff;
       if (node->left != NULL || node->right != NULL)
         balance_diff = (child == node->right ? height_diff : -height_diff);
       else
@@ -106,8 +101,8 @@ rebalance (CONTAINER_T container,
           else
             abort ();
 
-          nodeleft = node->left;
-          noderight = node->right;
+          NODE_T nodeleft = node->left;
+          NODE_T noderight = node->right;
 
           if (balance_diff < 0)
             {
@@ -318,7 +313,6 @@ gl_tree_nx_add_first (CONTAINER_T container, NODE_PAYLOAD_PARAMS)
   else
     {
       NODE_T node;
-
       for (node = container->root; node->left != NULL; )
         node = node->left;
 
@@ -339,13 +333,12 @@ gl_tree_nx_add_first (CONTAINER_T container, NODE_PAYLOAD_PARAMS)
 static void
 gl_tree_add_node_before (CONTAINER_T container, NODE_T node, NODE_T new_node)
 {
-  bool height_inc;
-
   new_node->left = NULL;
   new_node->right = NULL;
   new_node->balance = 0;
 
   /* Add it to the tree.  */
+  bool height_inc;
   if (node->left == NULL)
     {
       node->left = new_node;
@@ -389,13 +382,12 @@ gl_tree_nx_add_before (CONTAINER_T container, NODE_T node, NODE_PAYLOAD_PARAMS)
 static void
 gl_tree_add_node_after (CONTAINER_T container, NODE_T node, NODE_T new_node)
 {
-  bool height_inc;
-
   new_node->left = NULL;
   new_node->right = NULL;
   new_node->balance = 0;
 
   /* Add it to the tree.  */
+  bool height_inc;
   if (node->right == NULL)
     {
       node->right = new_node;
@@ -483,15 +475,12 @@ gl_tree_remove_node_no_free (CONTAINER_T container, NODE_T node)
     {
       /* Replace node with the rightmost element of the node->left subtree.  */
       NODE_T subst;
-      NODE_T subst_parent;
-      NODE_T child;
-
       for (subst = node->left; subst->right != NULL; )
         subst = subst->right;
 
-      subst_parent = subst->parent;
+      NODE_T subst_parent = subst->parent;
 
-      child = subst->left;
+      NODE_T child = subst->left;
 
       /* The case subst_parent == node is special:  If we do nothing special,
          we get confusion about node->left, subst->left and child->parent.
index ffcf0efcddf143bfbbfdc2200ec562f566cf2324..5a020fa6e041ec34efabf4cfb15acb96c585e594 100644 (file)
@@ -126,12 +126,11 @@ static const void * _GL_ATTRIBUTE_PURE
 gl_carray_node_value (gl_list_t list, gl_list_node_t node)
 {
   uintptr_t index = NODE_TO_INDEX (node);
-  size_t i;
 
   if (!(index < list->count))
     /* Invalid argument.  */
     abort ();
-  i = list->offset + index;
+  size_t i = list->offset + index;
   if (i >= list->allocated)
     i -= list->allocated;
   return list->elements[i];
@@ -142,12 +141,11 @@ gl_carray_node_nx_set_value (gl_list_t list, gl_list_node_t node,
                              const void *elt)
 {
   uintptr_t index = NODE_TO_INDEX (node);
-  size_t i;
 
   if (!(index < list->count))
     /* Invalid argument.  */
     abort ();
-  i = list->offset + index;
+  size_t i = list->offset + index;
   if (i >= list->allocated)
     i -= list->allocated;
   list->elements[i] = elt;
@@ -203,12 +201,11 @@ static const void * _GL_ATTRIBUTE_PURE
 gl_carray_get_at (gl_list_t list, size_t position)
 {
   size_t count = list->count;
-  size_t i;
 
   if (!(position < count))
     /* Invalid argument.  */
     abort ();
-  i = list->offset + position;
+  size_t i = list->offset + position;
   if (i >= list->allocated)
     i -= list->allocated;
   return list->elements[i];
@@ -218,12 +215,11 @@ static gl_list_node_t
 gl_carray_nx_set_at (gl_list_t list, size_t position, const void *elt)
 {
   size_t count = list->count;
-  size_t i;
 
   if (!(position < count))
     /* Invalid argument.  */
     abort ();
-  i = list->offset + position;
+  size_t i = list->offset + position;
   if (i >= list->allocated)
     i -= list->allocated;
   list->elements[i] = elt;
@@ -244,9 +240,8 @@ gl_carray_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index,
     {
       gl_listelement_equals_fn equals = list->base.equals_fn;
       size_t allocated = list->allocated;
-      size_t i_end;
 
-      i_end = list->offset + end_index;
+      size_t i_end = list->offset + end_index;
       if (i_end >= allocated)
         i_end -= allocated;
 
@@ -305,16 +300,13 @@ gl_carray_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
 static int
 grow (gl_list_t list)
 {
-  size_t new_allocated;
-  size_t memory_size;
-  const void **memory;
-
-  new_allocated = xtimes (list->allocated, 2);
+  size_t new_allocated = xtimes (list->allocated, 2);
   new_allocated = xsum (new_allocated, 1);
-  memory_size = xtimes (new_allocated, sizeof (const void *));
+  size_t memory_size = xtimes (new_allocated, sizeof (const void *));
   if (size_overflow_p (memory_size))
     /* Overflow, would lead to out of memory.  */
     return -1;
+  const void **memory;
   if (list->offset > 0 && list->count > 0)
     {
       memory = (const void **) malloc (memory_size);
@@ -367,12 +359,11 @@ static gl_list_node_t
 gl_carray_nx_add_last (gl_list_t list, const void *elt)
 {
   size_t count = list->count;
-  size_t i;
 
   if (count == list->allocated)
     if (grow (list) < 0)
       return NULL;
-  i = list->offset + count;
+  size_t i = list->offset + count;
   if (i >= list->allocated)
     i -= list->allocated;
   list->elements[i] = elt;
@@ -384,7 +375,6 @@ static gl_list_node_t
 gl_carray_nx_add_at (gl_list_t list, size_t position, const void *elt)
 {
   size_t count = list->count;
-  const void **elements;
 
   if (!(position <= count))
     /* Invalid argument.  */
@@ -392,15 +382,13 @@ gl_carray_nx_add_at (gl_list_t list, size_t position, const void *elt)
   if (count == list->allocated)
     if (grow (list) < 0)
       return NULL;
-  elements = list->elements;
+  const void **elements = list->elements;
   if (position <= (count / 2))
     {
       /* Shift at most count/2 elements to the left.  */
-      size_t i2;
-
       list->offset = (list->offset == 0 ? list->allocated : list->offset) - 1;
 
-      i2 = list->offset + position;
+      size_t i2 = list->offset + position;
       if (i2 >= list->allocated)
         {
           /* Here we must have list->offset > 0, hence list->allocated > 0.  */
@@ -422,10 +410,8 @@ 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;
-
-      i1 = list->offset + position;
-      i3 = list->offset + count;
+      size_t i1 = list->offset + position;
+      size_t i3 = list->offset + count;
       if (i1 >= list->allocated)
         {
           i1 -= list->allocated;
@@ -483,20 +469,17 @@ static bool
 gl_carray_remove_at (gl_list_t list, size_t position)
 {
   size_t count = list->count;
-  const void **elements;
 
   if (!(position < count))
     /* Invalid argument.  */
     abort ();
   /* Here we know count > 0.  */
-  elements = list->elements;
+  const void **elements = list->elements;
   if (position <= ((count - 1) / 2))
     {
       /* Shift at most (count-1)/2 elements to the right.  */
-      size_t i0, i2;
-
-      i0 = list->offset;
-      i2 = list->offset + position;
+      size_t i0 = list->offset;
+      size_t i2 = list->offset + position;
       if (i2 >= list->allocated)
         {
           /* Here we must have list->offset > 0, hence list->allocated > 0.  */
@@ -524,10 +507,8 @@ 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;
-
-      i1 = list->offset + position;
-      i3 = list->offset + count - 1;
+      size_t i1 = list->offset + position;
+      size_t i3 = list->offset + count - 1;
       if (i1 >= list->allocated)
         {
           i1 -= list->allocated;
@@ -647,11 +628,11 @@ gl_carray_iterator (gl_list_t list)
 static gl_list_iterator_t _GL_ATTRIBUTE_PURE
 gl_carray_iterator_from_to (gl_list_t list, size_t start_index, size_t end_index)
 {
-  gl_list_iterator_t result;
-
   if (!(start_index <= end_index && end_index <= list->count))
     /* Invalid arguments.  */
     abort ();
+
+  gl_list_iterator_t result;
   result.vtable = list->base.vtable;
   result.list = list;
   result.count = list->count;
@@ -720,14 +701,12 @@ gl_carray_sortedlist_indexof_from_to (gl_list_t list,
       do
         {
           size_t mid = low + (high - low) / 2; /* low <= mid < high */
-          size_t i_mid;
-          int cmp;
 
-          i_mid = list->offset + mid;
+          size_t i_mid = list->offset + mid;
           if (i_mid >= list->allocated)
             i_mid -= list->allocated;
 
-          cmp = compar (list->elements[i_mid], elt);
+          int cmp = compar (list->elements[i_mid], elt);
 
           if (cmp < 0)
             low = mid + 1;
@@ -745,14 +724,12 @@ gl_carray_sortedlist_indexof_from_to (gl_list_t list,
               while (low < high)
                 {
                   size_t mid2 = low + (high - low) / 2; /* low <= mid2 < high */
-                  size_t i_mid2;
-                  int cmp2;
 
-                  i_mid2 = list->offset + mid2;
+                  size_t i_mid2 = list->offset + mid2;
                   if (i_mid2 >= list->allocated)
                     i_mid2 -= list->allocated;
 
-                  cmp2 = compar (list->elements[i_mid2], elt);
+                  int cmp2 = compar (list->elements[i_mid2], elt);
 
                   if (cmp2 < 0)
                     low = mid2 + 1;
@@ -816,14 +793,12 @@ gl_carray_sortedlist_nx_add (gl_list_t list, gl_listelement_compar_fn compar,
   while (low < high)
     {
       size_t mid = low + (high - low) / 2; /* low <= mid < high */
-      size_t i_mid;
-      int cmp;
 
-      i_mid = list->offset + mid;
+      size_t i_mid = list->offset + mid;
       if (i_mid >= list->allocated)
         i_mid -= list->allocated;
 
-      cmp = compar (list->elements[i_mid], elt);
+      int cmp = compar (list->elements[i_mid], elt);
 
       if (cmp < 0)
         low = mid + 1;
index f8a55a18304155e703c7dea13cfd3d6cac0e68f2..83f546ed07f0e157a30a612226386fa25fa52175 100644 (file)
@@ -126,8 +126,6 @@ rebalance_after_add (CONTAINER_T container, NODE_T node, NODE_T parent)
       /* At this point, parent = node->parent != NULL.
          Think of node->color being RED (although node->color is not yet
          assigned.)  */
-      NODE_T grandparent;
-      NODE_T uncle;
 
       if (parent->color == BLACK)
         {
@@ -136,10 +134,11 @@ rebalance_after_add (CONTAINER_T container, NODE_T node, NODE_T parent)
           return;
         }
 
-      grandparent = parent->parent;
+      NODE_T grandparent = parent->parent;
       /* Since parent is RED, we know that
          grandparent is != NULL and colored BLACK.  */
 
+      NODE_T uncle;
       if (grandparent->left == parent)
         uncle = grandparent->right;
       else if (grandparent->right == parent)
@@ -699,19 +698,16 @@ gl_tree_remove_node_no_free (CONTAINER_T container, NODE_T node)
   else
     {
       /* Replace node with the rightmost element of the node->left subtree.  */
-      NODE_T subst;
-      NODE_T subst_parent;
-      NODE_T child;
-      color_t removed_color;
 
+      NODE_T subst;
       for (subst = node->left; subst->right != NULL; )
         subst = subst->right;
 
-      subst_parent = subst->parent;
+      NODE_T subst_parent = subst->parent;
 
-      child = subst->left;
+      NODE_T child = subst->left;
 
-      removed_color = subst->color;
+      color_t removed_color = subst->color;
 
       /* The case subst_parent == node is special:  If we do nothing special,
          we get confusion about node->left, subst->left and child->parent.
index 5f79398af8a3e6a15d81c0df8ba77e4009bc6b54..88415448b51464518b05134e044ddbea998e96b2 100644 (file)
@@ -351,13 +351,11 @@ gl_sublist_sortedlist_search_from_to (gl_list_t list,
                                       size_t low, size_t high,
                                       const void *elt)
 {
-  size_t index;
-
   if (!(low <= high && high <= list->end - list->start))
     /* Invalid arguments.  */
     abort ();
 
-  index =
+  size_t index =
     gl_sortedlist_indexof_from_to (list->whole, compar,
                                    list->start + low, list->start + high, elt);
   if (index != (size_t)(-1))
@@ -385,15 +383,13 @@ gl_sublist_sortedlist_indexof_from_to (gl_list_t list,
                                        size_t low, size_t high,
                                        const void *elt)
 {
-  size_t index;
-
   if (!(low <= high && high <= list->end - list->start))
     /* Invalid arguments.  */
     abort ();
 
-  index = gl_sortedlist_indexof_from_to (list->whole, compar,
-                                         list->start + low, list->start + high,
-                                         elt);
+  size_t index =
+    gl_sortedlist_indexof_from_to (list->whole, compar,
+                                   list->start + low, list->start + high, elt);
   if (index != (size_t)(-1))
     index -= list->start;
   return index;
index dc21014afffba428d5d5dc466f729a1caa7aa621..ad9da5a35246f6927ffa544ce2a94bb21e10f00e 100644 (file)
@@ -288,18 +288,6 @@ GLOB_ATTRIBUTE
 __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
         glob_t *pglob)
 {
-  const char *filename;
-  char *dirname = NULL;
-  size_t dirlen;
-  int status;
-  size_t oldcount;
-  int meta;
-  int dirname_modified;
-  int malloc_dirname = 0;
-  glob_t dirs;
-  int retval = 0;
-  size_t alloca_used = 0;
-
   if (pattern == NULL || pglob == NULL || (flags & ~__GLOB_FLAGS) != 0)
     {
       __set_errno (EINVAL);
@@ -323,8 +311,6 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
         pglob->gl_pathv = NULL;
       else
         {
-          size_t i;
-
           if (pglob->gl_offs >= ~((size_t) 0) / sizeof (char *))
             return GLOB_NOSPACE;
 
@@ -333,11 +319,13 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
           if (pglob->gl_pathv == NULL)
             return GLOB_NOSPACE;
 
-          for (i = 0; i <= pglob->gl_offs; ++i)
+          for (size_t i = 0; i <= pglob->gl_offs; ++i)
             pglob->gl_pathv[i] = NULL;
         }
     }
 
+  size_t alloca_used = 0;
+
   if (flags & GLOB_BRACE)
     {
       const char *begin;
@@ -368,15 +356,9 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
         {
           /* Allocate working buffer large enough for our work.  Note that
              we have at least an opening and closing brace.  */
-          size_t firstc;
-          char *alt_start;
-          const char *p;
-          const char *next;
-          const char *rest;
-          size_t rest_len;
-          char *onealt;
           size_t pattern_len = strlen (pattern) - 1;
           int alloca_onealt = glob_use_alloca (alloca_used, pattern_len);
+          char *onealt;
           if (alloca_onealt)
             onealt = alloca_account (pattern_len, alloca_used);
           else
@@ -387,11 +369,11 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
             }
 
           /* We know the prefix for all sub-patterns.  */
-          alt_start = mempcpy (onealt, pattern, begin - pattern);
+          char *alt_start = mempcpy (onealt, pattern, begin - pattern);
 
           /* Find the first sub-pattern and at the same time find the
              rest after the closing brace.  */
-          next = next_brace_sub (begin + 1, flags);
+          const char *next = next_brace_sub (begin + 1, flags);
           if (next == NULL)
             {
               /* It is an invalid expression.  */
@@ -403,7 +385,7 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
             }
 
           /* Now find the end of the whole brace expression.  */
-          rest = next;
+          const char *rest = next;
           while (*rest != '}')
             {
               rest = next_brace_sub (rest + 1, flags);
@@ -413,27 +395,25 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
             }
           /* Please note that we now can be sure the brace expression
              is well-formed.  */
-          rest_len = strlen (++rest) + 1;
+          size_t rest_len = strlen (++rest) + 1;
 
           /* We have a brace expression.  BEGIN points to the opening {,
              NEXT points past the terminator of the first element, and END
              points past the final }.  We will accumulate result names from
              recursive runs for each brace alternative in the buffer using
              GLOB_APPEND.  */
-          firstc = pglob->gl_pathc;
+          size_t firstc = pglob->gl_pathc;
 
-          p = begin + 1;
+          const char *p = begin + 1;
           while (1)
             {
-              int result;
-
               /* Construct the new glob expression.  */
               mempcpy (mempcpy (alt_start, p, next - p), rest, rest_len);
 
-              result = __glob (onealt,
-                               ((flags & ~(GLOB_NOCHECK | GLOB_NOMAGIC))
-                                | GLOB_APPEND),
-                               errfunc, pglob);
+              int result = __glob (onealt,
+                                   ((flags & ~(GLOB_NOCHECK | GLOB_NOMAGIC))
+                                    | GLOB_APPEND),
+                                   errfunc, pglob);
 
               /* If we got an error, return it.  */
               if (result && result != GLOB_NOMATCH)
@@ -468,11 +448,11 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
         }
     }
 
- no_brace:
-  oldcount = pglob->gl_pathc + pglob->gl_offs;
+ no_brace: ;
+  size_t oldcount = pglob->gl_pathc + pglob->gl_offs;
 
   /* Find the filename.  */
-  filename = strrchr (pattern, '/');
+  const char *filename = strrchr (pattern, '/');
 
 #if defined __MSDOS__ || defined WINDOWS32
   /* The case of "d:pattern".  Since ':' is not allowed in
@@ -483,7 +463,12 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
     filename = strchr (pattern, ':');
 #endif /* __MSDOS__ || WINDOWS32 */
 
-  dirname_modified = 0;
+  char *dirname = NULL;
+  size_t dirlen;
+  int malloc_dirname = 0;
+  int dirname_modified = 0;
+  glob_t dirs;
+  int retval = 0;
   if (filename == NULL)
     {
       /* This can mean two things: a simple name or "~name".  The latter
@@ -522,7 +507,6 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
     }
   else
     {
-      char *newp;
       dirlen = filename - pattern;
 #if defined __MSDOS__ || defined WINDOWS32
       if (*filename == ':'
@@ -543,6 +527,7 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
         }
 #endif
 
+      char *newp;
       if (glob_use_alloca (alloca_used, dirlen + 1))
         newp = alloca_account (dirlen + 1, alloca_used);
       else
@@ -703,9 +688,9 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
             }
           else
             {
-              char *newp;
               size_t home_len = strlen (home_dir);
               int use_alloca = glob_use_alloca (alloca_used, home_len + dirlen);
+              char *newp;
               if (use_alloca)
                 newp = alloca_account (home_len + dirlen, alloca_used);
               else
@@ -837,7 +822,6 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
                 /* dirname contains end_name; we can't free it now.  */
                 char *prev_dirname =
                   (__glibc_unlikely (malloc_dirname) ? dirname : NULL);
-                char *d;
 
                 malloc_dirname = 0;
 
@@ -856,7 +840,7 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
                       }
                     malloc_dirname = 1;
                   }
-                d = mempcpy (dirname, p->pw_dir, home_len);
+                char *d = mempcpy (dirname, p->pw_dir, home_len);
                 if (end_name != NULL)
                   d = mempcpy (d, end_name, rest_len);
                 *d = '\0';
@@ -903,7 +887,6 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
   if (filename == NULL)
     {
       size_t newcount = pglob->gl_pathc + pglob->gl_offs;
-      char **new_gl_pathv;
 
       if (newcount > SIZE_MAX / sizeof (char *) - 2)
         {
@@ -915,19 +898,18 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
           goto out;
         }
 
-      new_gl_pathv = realloc (pglob->gl_pathv,
-                              (newcount + 2) * sizeof (char *));
+      char **new_gl_pathv = realloc (pglob->gl_pathv,
+                                     (newcount + 2) * sizeof (char *));
       if (new_gl_pathv == NULL)
         goto nospace;
       pglob->gl_pathv = new_gl_pathv;
 
       if (flags & GLOB_MARK && is_dir (dirname, flags, pglob))
         {
-          char *p;
           pglob->gl_pathv[newcount] = malloc (dirlen + 2);
           if (pglob->gl_pathv[newcount] == NULL)
             goto nospace;
-          p = mempcpy (pglob->gl_pathv[newcount], dirname, dirlen);
+          char *p = mempcpy (pglob->gl_pathv[newcount], dirname, dirlen);
           p[0] = '/';
           p[1] = '\0';
           if (__glibc_unlikely (malloc_dirname))
@@ -951,7 +933,7 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
       return 0;
     }
 
-  meta = __glob_pattern_type (dirname, !(flags & GLOB_NOESCAPE));
+  int meta = __glob_pattern_type (dirname, !(flags & GLOB_NOESCAPE));
   /* meta is 1 if correct glob pattern containing metacharacters.
      If meta has bit (1 << 2) set, it means there was an unterminated
      [ which we handle the same, using fnmatch.  Broken unterminated
@@ -962,8 +944,6 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
       /* The directory name contains metacharacters, so we
          have to glob for the directory, and then glob for
          the pattern in each directory found.  */
-      size_t i;
-
       if (!(flags & GLOB_NOESCAPE) && dirlen > 0 && dirname[dirlen - 1] == '\\')
         {
           /* "foo\\/bar".  Remove the final backslash from dirname
@@ -986,10 +966,11 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
           dirs.gl_lstat = pglob->gl_lstat;
         }
 
-      status = __glob (dirname,
-                       ((flags & (GLOB_ERR | GLOB_NOESCAPE | GLOB_ALTDIRFUNC))
-                        | GLOB_NOSORT | GLOB_ONLYDIR),
-                       errfunc, &dirs);
+      int status =
+        __glob (dirname,
+                ((flags & (GLOB_ERR | GLOB_NOESCAPE | GLOB_ALTDIRFUNC))
+                 | GLOB_NOSORT | GLOB_ONLYDIR),
+                errfunc, &dirs);
       if (status != 0)
         {
           if ((flags & GLOB_NOCHECK) == 0 || status != GLOB_NOMATCH)
@@ -1003,11 +984,9 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
       /* We have successfully globbed the preceding directory name.
          For each name we found, call glob_in_dir on it and FILENAME,
          appending the results to PGLOB.  */
-      for (i = 0; i < dirs.gl_pathc; ++i)
+      for (size_t i = 0; i < dirs.gl_pathc; ++i)
         {
-          size_t old_pathc;
-
-          old_pathc = pglob->gl_pathc;
+          size_t old_pathc = pglob->gl_pathc;
           status = glob_in_dir (filename, dirs.gl_pathv[i],
                                 ((flags | GLOB_APPEND)
                                  & ~(GLOB_NOCHECK | GLOB_NOMAGIC)),
@@ -1050,8 +1029,6 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
           if (flags & GLOB_NOCHECK)
             {
               size_t newcount = pglob->gl_pathc + pglob->gl_offs;
-              char **new_gl_pathv;
-
               if (newcount > SIZE_MAX / sizeof (char *) - 2)
                 {
                 nospace2:
@@ -1060,8 +1037,8 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
                   goto out;
                 }
 
-              new_gl_pathv = realloc (pglob->gl_pathv,
-                                      (newcount + 2) * sizeof (char *));
+              char **new_gl_pathv = realloc (pglob->gl_pathv,
+                                             (newcount + 2) * sizeof (char *));
               if (new_gl_pathv == NULL)
                 goto nospace2;
               pglob->gl_pathv = new_gl_pathv;
@@ -1120,8 +1097,8 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
         }
       if (dirname_modified)
         flags &= ~(GLOB_NOCHECK | GLOB_NOMAGIC);
-      status = glob_in_dir (filename, dirname, flags, errfunc, pglob,
-                            alloca_used);
+      int status = glob_in_dir (filename, dirname, flags, errfunc, pglob,
+                                alloca_used);
       if (status != 0)
         {
           if (status == GLOB_NOMATCH && flags != orig_flags
@@ -1154,9 +1131,7 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
   if (flags & GLOB_MARK)
     {
       /* Append slashes to directory names.  */
-      size_t i;
-
-      for (i = oldcount; i < pglob->gl_pathc + pglob->gl_offs; ++i)
+      for (size_t i = oldcount; i < pglob->gl_pathc + pglob->gl_offs; ++i)
         if (is_dir (pglob->gl_pathv[i], flags, pglob))
           {
             size_t len = strlen (pglob->gl_pathv[i]) + 2;
index 1902d216dece916f34b22f8c055e3dd2da990cdd..7c52c40ff00801ab6c565f58677beeaeb07cae7c 100644 (file)
@@ -29,8 +29,7 @@ globfree (glob_t *pglob)
 {
   if (pglob->gl_pathv != NULL)
     {
-      size_t i;
-      for (i = 0; i < pglob->gl_pathc; ++i)
+      for (size_t i = 0; i < pglob->gl_pathc; ++i)
         free (pglob->gl_pathv[pglob->gl_offs + i]);
       free (pglob->gl_pathv);
       pglob->gl_pathv = NULL;
index a2c53dc7d6f0e205579a3e92884751ebdabd93bd..c3e90d6e4903f6ff9652e7ae89f73a6ae76f9c42 100644 (file)
@@ -261,9 +261,7 @@ int
 glthread_rwlock_init_for_glibc (pthread_rwlock_t *lock)
 {
   pthread_rwlockattr_t attributes;
-  int err;
-
-  err = pthread_rwlockattr_init (&attributes);
+  int err = pthread_rwlockattr_init (&attributes);
   if (err != 0)
     return err;
   /* Note: PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP is the only value that
@@ -286,9 +284,7 @@ glthread_rwlock_init_for_glibc (pthread_rwlock_t *lock)
 int
 glthread_rwlock_init_multithreaded (gl_rwlock_t *lock)
 {
-  int err;
-
-  err = pthread_rwlock_init (&lock->rwlock, NULL);
+  int err = pthread_rwlock_init (&lock->rwlock, NULL);
   if (err != 0)
     return err;
   lock->initialized = 1;
@@ -300,9 +296,7 @@ glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock)
 {
   if (!lock->initialized)
     {
-      int err;
-
-      err = pthread_mutex_lock (&lock->guard);
+      int err = pthread_mutex_lock (&lock->guard);
       if (err != 0)
         return err;
       if (!lock->initialized)
@@ -326,9 +320,7 @@ glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock)
 {
   if (!lock->initialized)
     {
-      int err;
-
-      err = pthread_mutex_lock (&lock->guard);
+      int err = pthread_mutex_lock (&lock->guard);
       if (err != 0)
         return err;
       if (!lock->initialized)
@@ -358,11 +350,9 @@ glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock)
 int
 glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock)
 {
-  int err;
-
   if (!lock->initialized)
     return EINVAL;
-  err = pthread_rwlock_destroy (&lock->rwlock);
+  int err = pthread_rwlock_destroy (&lock->rwlock);
   if (err != 0)
     return err;
   lock->initialized = 0;
@@ -376,9 +366,7 @@ glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock)
 int
 glthread_rwlock_init_multithreaded (gl_rwlock_t *lock)
 {
-  int err;
-
-  err = pthread_mutex_init (&lock->lock, NULL);
+  int err = pthread_mutex_init (&lock->lock, NULL);
   if (err != 0)
     return err;
   err = pthread_cond_init (&lock->waiting_readers, NULL);
@@ -395,9 +383,7 @@ glthread_rwlock_init_multithreaded (gl_rwlock_t *lock)
 int
 glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock)
 {
-  int err;
-
-  err = pthread_mutex_lock (&lock->lock);
+  int err = pthread_mutex_lock (&lock->lock);
   if (err != 0)
     return err;
   /* Test whether only readers are currently running, and whether the runcount
@@ -422,9 +408,7 @@ glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock)
 int
 glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock)
 {
-  int err;
-
-  err = pthread_mutex_lock (&lock->lock);
+  int err = pthread_mutex_lock (&lock->lock);
   if (err != 0)
     return err;
   /* Test whether no readers or writers are currently running.  */
@@ -449,9 +433,7 @@ glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock)
 int
 glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock)
 {
-  int err;
-
-  err = pthread_mutex_lock (&lock->lock);
+  int err = pthread_mutex_lock (&lock->lock);
   if (err != 0)
     return err;
   if (lock->runcount < 0)
@@ -505,9 +487,7 @@ glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock)
 int
 glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock)
 {
-  int err;
-
-  err = pthread_mutex_destroy (&lock->lock);
+  int err = pthread_mutex_destroy (&lock->lock);
   if (err != 0)
     return err;
   err = pthread_cond_destroy (&lock->waiting_readers);
@@ -531,9 +511,7 @@ int
 glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
 {
   pthread_mutexattr_t attributes;
-  int err;
-
-  err = pthread_mutexattr_init (&attributes);
+  int err = pthread_mutexattr_init (&attributes);
   if (err != 0)
     return err;
   err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE);
@@ -560,9 +538,7 @@ int
 glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
 {
   pthread_mutexattr_t attributes;
-  int err;
-
-  err = pthread_mutexattr_init (&attributes);
+  int err = pthread_mutexattr_init (&attributes);
   if (err != 0)
     return err;
   err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE);
@@ -589,9 +565,7 @@ glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
 {
   if (!lock->initialized)
     {
-      int err;
-
-      err = pthread_mutex_lock (&lock->guard);
+      int err = pthread_mutex_lock (&lock->guard);
       if (err != 0)
         return err;
       if (!lock->initialized)
@@ -621,11 +595,9 @@ glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock)
 int
 glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
 {
-  int err;
-
   if (!lock->initialized)
     return EINVAL;
-  err = pthread_mutex_destroy (&lock->recmutex);
+  int err = pthread_mutex_destroy (&lock->recmutex);
   if (err != 0)
     return err;
   lock->initialized = 0;
@@ -639,9 +611,7 @@ glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
 int
 glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
 {
-  int err;
-
-  err = pthread_mutex_init (&lock->mutex, NULL);
+  int err = pthread_mutex_init (&lock->mutex, NULL);
   if (err != 0)
     return err;
   lock->owner = (pthread_t) 0;
@@ -655,9 +625,7 @@ glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
   pthread_t self = pthread_self ();
   if (lock->owner != self)
     {
-      int err;
-
-      err = pthread_mutex_lock (&lock->mutex);
+      int err = pthread_mutex_lock (&lock->mutex);
       if (err != 0)
         return err;
       lock->owner = self;
index 2d015b6b0b70035599270b0591f6053602492e30..fb06b45e1faef7405846fb455045cf0dc970f7a9 100644 (file)
@@ -208,9 +208,7 @@ gl_thread_t
 gl_thread_create (void *(*func) (void *arg), void *arg)
 {
   gl_thread_t thread;
-  int ret;
-
-  ret = glthread_create (&thread, func, arg);
+  int ret = glthread_create (&thread, func, arg);
   if (ret != 0)
     abort ();
   return thread;
index 34938a1b05e4edac266c1037909585eb166cac9e..1369263646487ab20919d47d104af7a7377a3a06 100644 (file)
@@ -73,12 +73,11 @@ get_group_info (struct group_info *gi)
 int
 group_member (gid_t gid)
 {
-  int found;
   struct group_info gi;
   int n_groups = get_group_info (&gi);
 
   /* Search through the list looking for GID. */
-  found = 0;
+  int found = 0;
   for (int i = 0; i < n_groups; i++)
     {
       if (gid == gi.group[i])
@@ -100,9 +99,7 @@ main (int argc, char **argv)
 {
   for (int i = 1; i < argc; i++)
     {
-      gid_t gid;
-
-      gid = atoi (argv[i]);
+      gid_t gid = atoi (argv[i]);
       printf ("%d: %s\n", gid, group_member (gid) ? "yes" : "no");
     }
   exit (0);
index a0085de3cb7bb8db34f2d256df18984ccd7d4bd0..f28f60e180170d9fa6da4c6e69d9e8856c44dfb3 100644 (file)
@@ -277,17 +277,18 @@ void *
 hash_get_next (const Hash_table *table, const void *entry)
 {
   struct hash_entry const *bucket = safe_hasher (table, entry);
-  struct hash_entry const *cursor;
 
   /* Find next entry in the same bucket.  */
-  cursor = bucket;
-  do
-    {
-      if (cursor->data == entry && cursor->next)
-        return cursor->next->data;
-      cursor = cursor->next;
-    }
-  while (cursor != NULL);
+  {
+    struct hash_entry const *cursor = bucket;
+    do
+      {
+        if (cursor->data == entry && cursor->next)
+          return cursor->next->data;
+        cursor = cursor->next;
+      }
+    while (cursor != NULL);
+  }
 
   /* Find first entry in any subsequent bucket.  */
   while (++bucket < table->bucket_limit)
@@ -386,7 +387,6 @@ static bool
 check_tuning (Hash_table *table)
 {
   const Hash_tuning *tuning = table->tuning;
-  float epsilon;
   if (tuning == &default_tuning)
     return true;
 
@@ -395,7 +395,7 @@ check_tuning (Hash_table *table)
      fail to grow or shrink as they should.  The smallest allocation
      is 11 (due to next_prime's algorithm), so an epsilon of 0.1
      should be good enough.  */
-  epsilon = 0.1f;
+  float epsilon = 0.1f;
 
   if (epsilon < tuning->growth_threshold
       && tuning->growth_threshold < 1 - epsilon
@@ -439,14 +439,12 @@ hash_initialize (size_t candidate, const Hash_tuning *tuning,
                  Hash_hasher hasher, Hash_comparator comparator,
                  Hash_data_freer data_freer)
 {
-  Hash_table *table;
-
   if (hasher == NULL)
     hasher = raw_hasher;
   if (comparator == NULL)
     comparator = raw_comparator;
 
-  table = malloc (sizeof *table);
+  Hash_table *table = malloc (sizeof *table);
   if (table == NULL)
     return NULL;
 
@@ -499,20 +497,20 @@ hash_clear (Hash_table *table)
     {
       if (bucket->data)
         {
-          struct hash_entry *next;
-
           /* Free the bucket overflow.  */
-          for (struct hash_entry *cursor = bucket->next; cursor; cursor = next)
+          for (struct hash_entry *cursor = bucket->next; cursor; )
             {
               if (table->data_freer)
                 table->data_freer (cursor->data);
               cursor->data = NULL;
 
-              next = cursor->next;
+              struct hash_entry *next = cursor->next;
               /* Relinking is done one entry at a time, as it is to be expected
                  that overflows are either rare or short.  */
               cursor->next = table->free_entry_list;
               table->free_entry_list = cursor;
+
+              cursor = next;
             }
 
           /* Free the bucket head.  */
@@ -530,7 +528,6 @@ hash_clear (Hash_table *table)
 void
 hash_free (Hash_table *table)
 {
-  struct hash_entry *next;
   int saved_errno = errno;
 
   /* Call the user data_freer function.  */
@@ -559,18 +556,20 @@ hash_free (Hash_table *table)
        bucket < table->bucket_limit;
        bucket++)
     {
-      for (struct hash_entry *cursor = bucket->next; cursor; cursor = next)
+      for (struct hash_entry *cursor = bucket->next; cursor; )
         {
-          next = cursor->next;
+          struct hash_entry *next = cursor->next;
           free (cursor);
+          cursor = next;
         }
     }
 
   /* Also reclaim the internal list of previously freed entries.  */
-  for (struct hash_entry *cursor = table->free_entry_list; cursor; cursor = next)
+  for (struct hash_entry *cursor = table->free_entry_list; cursor; )
     {
-      next = cursor->next;
+      struct hash_entry *next = cursor->next;
       free (cursor);
+      cursor = next;
     }
 
 #endif
@@ -698,8 +697,6 @@ find_entry (Hash_table *table, const void *entry,
 static bool
 transfer_entries (Hash_table *dst, Hash_table *src, bool safe)
 {
-  struct hash_entry *next;
-
   for (struct hash_entry *bucket = src->bucket; bucket < src->bucket_limit; bucket++)
     if (bucket->data)
       {
@@ -712,12 +709,12 @@ 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 (struct hash_entry *cursor = bucket->next; cursor; cursor = next)
+        for (struct hash_entry *cursor = bucket->next; cursor; )
           {
             data = cursor->data;
             new_bucket = safe_hasher (dst, data);
 
-            next = cursor->next;
+            struct hash_entry *next = cursor->next;
 
             if (new_bucket->data)
               {
@@ -734,6 +731,8 @@ transfer_entries (Hash_table *dst, Hash_table *src, bool safe)
                 dst->n_buckets_used++;
                 free_entry (dst, cursor);
               }
+
+            cursor = next;
           }
         /* Now move the bucket head.  Be sure that if we fail due to
            allocation failure that the src table is in a consistent
@@ -773,15 +772,15 @@ transfer_entries (Hash_table *dst, Hash_table *src, bool safe)
 bool
 hash_rehash (Hash_table *table, size_t candidate)
 {
-  Hash_table storage;
-  Hash_table *new_table;
   size_t new_size = compute_bucket_size (candidate, table->tuning);
 
   if (!new_size)
     return false;
   if (new_size == table->n_buckets)
     return true;
-  new_table = &storage;
+
+  Hash_table storage;
+  Hash_table *new_table = &storage;
   new_table->bucket = calloc (new_size, sizeof *new_table->bucket);
   if (new_table->bucket == NULL)
     return false;
@@ -855,8 +854,6 @@ int
 hash_insert_if_absent (Hash_table *table, void const *entry,
                        void const **matched_ent)
 {
-  void *data;
-  struct hash_entry *bucket;
 
   /* The caller cannot insert a NULL entry, since hash_lookup returns NULL
      to indicate "not found", and find_entry uses "bucket->data == NULL"
@@ -865,7 +862,9 @@ hash_insert_if_absent (Hash_table *table, void const *entry,
     abort ();
 
   /* If there's a matching entry already in the table, return that.  */
-  if ((data = find_entry (table, entry, &bucket, false)) != NULL)
+  struct hash_entry *bucket;
+  void *data = find_entry (table, entry, &bucket, false);
+  if (data != NULL)
     {
       if (matched_ent)
         *matched_ent = data;
@@ -949,10 +948,8 @@ hash_insert (Hash_table *table, void const *entry)
 void *
 hash_remove (Hash_table *table, const void *entry)
 {
-  void *data;
   struct hash_entry *bucket;
-
-  data = find_entry (table, entry, &bucket, true);
+  void *data = find_entry (table, entry, &bucket, true);
   if (!data)
     return NULL;
 
@@ -1013,9 +1010,9 @@ hash_remove (Hash_table *table, const void *entry)
 void
 hash_print (const Hash_table *table)
 {
-  struct hash_entry *bucket = (struct hash_entry *) table->bucket;
-
-  for ( ; bucket < table->bucket_limit; bucket++)
+  for (struct hash_entry *bucket = (struct hash_entry *) table->bucket;
+       bucket < table->bucket_limit;
+       bucket++)
     {
       if (bucket)
         printf ("%lu:\n", (unsigned long int) (bucket - table->bucket));
index d538a5406f6e2151688abbe0158ec2e044cd30bd..d801e20f5d3477a920537e0ae072d134f1b6061a 100644 (file)
@@ -26,9 +26,9 @@ char *
 hasmntopt (const struct mntent *mnt, const char *opt)
 {
   const size_t optlen = strlen (opt);
-  char *rest = mnt->mnt_opts, *p;
+  char *p;
 
-  while ((p = strstr (rest, opt)) != NULL)
+  for (char *rest = mnt->mnt_opts; (p = strstr (rest, opt)) != NULL; )
     {
       if ((p == rest || p[-1] == ',')
           && (p[optlen] == '\0' || p[optlen] == '=' || p[optlen] == ','))
index 6dbf1185a7787e5aec0b821e333864306bceab24..0d5df5ad51ad92531fc14dca264898f3853de728 100644 (file)
@@ -43,12 +43,12 @@ hmac_hash (const void *key, size_t keylen,
            const void *in, size_t inlen,
            int pad, void *resbuf)
 {
-  struct GL_HMAC_CTX hmac_ctx;
   char block[GL_HMAC_BLOCKSIZE];
 
   memset (block, pad, sizeof block);
   memxor (block, key, keylen);
 
+  struct GL_HMAC_CTX hmac_ctx;
   GL_HMAC_FN_INIT (&hmac_ctx);
   GL_HMAC_FN_BLOC (block, sizeof block, &hmac_ctx);
   GL_HMAC_FN_PROC (in, inlen, &hmac_ctx);
@@ -60,7 +60,6 @@ GL_HMAC_FN (const void *key, size_t keylen,
             const void *in, size_t inlen, void *resbuf)
 {
   char optkeybuf[GL_HMAC_HASHSIZE];
-  char innerhash[GL_HMAC_HASHSIZE];
 
   /* Ensure key size is <= block size.  */
   if (keylen > GL_HMAC_BLOCKSIZE)
@@ -78,6 +77,7 @@ GL_HMAC_FN (const void *key, size_t keylen,
     }
 
   /* Compute INNERHASH from KEY and IN.  */
+  char innerhash[GL_HMAC_HASHSIZE];
   hmac_hash (key, keylen, in, inlen, IPAD, innerhash);
 
   /* Compute result from KEY and INNERHASH.  */
index f065547d2f109b1735502090f254e9803cdba48b..9e2cf0958f38444fb386dc0f753917eec7c14b36 100644 (file)
@@ -81,18 +81,17 @@ static char *
 group_number (char *number, size_t numberlen,
               char const *grouping, char const *thousands_sep)
 {
-  register char *d;
-  size_t grouplen = SIZE_MAX;
   size_t thousands_seplen = strlen (thousands_sep);
-  size_t i = numberlen;
 
   /* The maximum possible value for NUMBERLEN is the number of digits
      in the square of the largest uintmax_t, so double the size needed.  */
   char buf[2 * INT_STRLEN_BOUND (uintmax_t) + 1];
 
   memcpy (buf, number, numberlen);
-  d = number + numberlen;
+  register char *d = number + numberlen;
 
+  size_t grouplen = SIZE_MAX;
+  size_t i = numberlen;
   for (;;)
     {
       unsigned char g = *grouping;
@@ -158,19 +157,6 @@ human_readable (uintmax_t n, char *buf, int opts,
   int inexact_style =
     opts & (human_round_to_nearest | human_floor | human_ceiling);
   unsigned int base = opts & human_base_1024 ? 1024 : 1000;
-  uintmax_t amt;
-  int tenths;
-  int exponent = -1;
-  int exponent_max = sizeof power_letter - 1;
-  char *p;
-  char *psuffix;
-  char const *integerlim;
-
-  /* 0 means adjusted N == AMT.TENTHS;
-     1 means AMT.TENTHS < adjusted N < AMT.TENTHS + 0.05;
-     2 means adjusted N == AMT.TENTHS + 0.05;
-     3 means AMT.TENTHS + 0.05 < adjusted N < AMT.TENTHS + 0.1.  */
-  int rounding;
 
   char const *decimal_point = ".";
   size_t decimal_pointlen = 1;
@@ -188,12 +174,20 @@ human_readable (uintmax_t n, char *buf, int opts,
     thousands_sep = l->thousands_sep;
 
   /* Leave room for a trailing space and following suffix.  */
-  psuffix = buf + LONGEST_HUMAN_READABLE - 1 - HUMAN_READABLE_SUFFIX_LENGTH_MAX;
-  p = psuffix;
+  char *psuffix =
+    buf + LONGEST_HUMAN_READABLE - 1 - HUMAN_READABLE_SUFFIX_LENGTH_MAX;
+  char *p = psuffix;
 
   /* Adjust AMT out of FROM_BLOCK_SIZE units and into TO_BLOCK_SIZE
      units.  If this can be done exactly with integer arithmetic, do
      not use floating point operations.  */
+  uintmax_t amt;
+  int tenths;
+  /* 0 means adjusted N == AMT.TENTHS;
+     1 means AMT.TENTHS < adjusted N < AMT.TENTHS + 0.05;
+     2 means adjusted N == AMT.TENTHS + 0.05;
+     3 means AMT.TENTHS + 0.05 < adjusted N < AMT.TENTHS + 0.1.  */
+  int rounding;
   if (to_block_size <= from_block_size)
     {
       if (from_block_size % to_block_size == 0)
@@ -219,6 +213,10 @@ human_readable (uintmax_t n, char *buf, int opts,
       goto use_integer_arithmetic;
     }
 
+  int exponent = -1;
+  int exponent_max = sizeof power_letter - 1;
+  char const *integerlim;
+
   {
     /* Either the result cannot be computed easily using uintmax_t,
        or from_block_size is zero.  Fall back on floating point.
@@ -412,7 +410,6 @@ default_block_size (void)
 static strtol_error
 humblock (char const *spec, uintmax_t *block_size, int *options)
 {
-  int i;
   int opts = 0;
 
   if (! spec
@@ -427,7 +424,8 @@ humblock (char const *spec, uintmax_t *block_size, int *options)
           spec++;
         }
 
-      if (0 <= (i = ARGMATCH (spec, block_size_args, block_size_opts)))
+      int i = ARGMATCH (spec, block_size_args, block_size_opts);
+      if (0 <= i)
         {
           opts |= block_size_opts[i];
           *block_size = 1;
index 27707a574d1f2dd988fd35c62eb791439d324f56..71abfcf98379c7d77a8ffcf3b10055d34ac59916 100644 (file)
@@ -48,20 +48,15 @@ hypot (double x, double y)
         /* Now 0 <= b <= a.  */
 
         {
-          int e;
-          double an;
-          double bn;
-
           /* Write a = an * 2^e, b = bn * 2^e with 0 <= bn <= an < 1.  */
-          an = frexp (a, &e);
-          bn = ldexp (b, - e);
+          int e;
+          double an = frexp (a, &e);
+          double bn = ldexp (b, - e);
 
           {
-            double cn;
-
             /* Through the normalization, no unneeded overflow or underflow
                will occur here.  */
-            cn = sqrt (an * an + bn * bn);
+            double cn = sqrt (an * an + bn * bn);
             return ldexp (cn, e);
           }
         }
index 8dc0fba57a2334df9635fba1f6c34feb0e5ed624..8e89cfb2ac1a194b0c8c696ce290e60f6f9b4a55 100644 (file)
@@ -58,20 +58,15 @@ hypotl (long double x, long double y)
         /* Now 0 <= b <= a.  */
 
         {
-          int e;
-          long double an;
-          long double bn;
-
           /* Write a = an * 2^e, b = bn * 2^e with 0 <= bn <= an < 1.  */
-          an = frexpl (a, &e);
-          bn = ldexpl (b, - e);
+          int e;
+          long double an = frexpl (a, &e);
+          long double bn = ldexpl (b, - e);
 
           {
-            long double cn;
-
             /* Through the normalization, no unneeded overflow or underflow
                will occur here.  */
-            cn = sqrtl (an * an + bn * bn);
+            long double cn = sqrtl (an * an + bn * bn);
             return ldexpl (cn, e);
           }
         }
index afac835bcfb74664ed24553cada60f64d6904c2d..7d7d85ffae845e95017af534662ca0ad52058d2d 100644 (file)
@@ -54,10 +54,9 @@ i_ring_push (I_ring *ir, int val)
 int
 i_ring_pop (I_ring *ir)
 {
-  int top_val;
   if (i_ring_empty (ir))
     abort ();
-  top_val = ir->ir_data[ir->ir_front];
+  int top_val = ir->ir_data[ir->ir_front];
   ir->ir_data[ir->ir_front] = ir->ir_default_val;
   if (ir->ir_front == ir->ir_back)
     ir->ir_empty = true;
index c54b8ee603432ceeda0508e1ef85c4079e6d4a09..00444e00984ba09eb8205d76c84736576cb1d41b 100644 (file)
@@ -44,11 +44,6 @@ iconv_t
 rpl_iconv_open (const char *tocode, const char *fromcode)
 #undef iconv_open
 {
-  char fromcode_upper[32];
-  char tocode_upper[32];
-  char *fromcode_upper_end;
-  char *tocode_upper_end;
-
 #if REPLACE_ICONV_UTF
   /* Special handling of conversion between UTF-8 and UTF-{16,32}{BE,LE}.
      We do not need to handle conversion between arbitrary encodings and
@@ -113,6 +108,8 @@ rpl_iconv_open (const char *tocode, const char *fromcode)
   /* Convert the encodings to upper case, because
        1. in the arguments of iconv_open() on AIX and HP-UX, the case matters,
        2. it makes searching in the table faster.  */
+  char fromcode_upper[32];
+  char *fromcode_upper_end;
   {
     const char *p = fromcode;
     char *q = fromcode_upper;
@@ -129,6 +126,8 @@ rpl_iconv_open (const char *tocode, const char *fromcode)
     fromcode_upper_end = q;
   }
 
+  char tocode_upper[32];
+  char *tocode_upper_end;
   {
     const char *p = tocode;
     char *q = tocode_upper;
index 04bf23d4846987ab8cc1b26275f7136660325aa5..bfff2579106e0d1fa000b131f039def3ffd20960 100644 (file)
@@ -103,8 +103,6 @@ getuser (uid_t uid)
 uid_t *
 getuidbyname (const char *user)
 {
-  struct passwd *pwent;
-
   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))
@@ -115,7 +113,7 @@ getuidbyname (const char *user)
     if (*tail->name == *user && streq (tail->name, user))
       return NULL;
 
-  pwent = getpwnam (user);
+  struct passwd *pwent = getpwnam (user);
 #ifdef __DJGPP__
   /* We need to pretend to be the user USER, to make
      pwd functions know about an arbitrary user name.  */
@@ -184,8 +182,6 @@ getgroup (gid_t gid)
 gid_t *
 getgidbyname (const char *group)
 {
-  struct group *grent;
-
   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))
@@ -196,7 +192,7 @@ getgidbyname (const char *group)
     if (*tail->name == *group && streq (tail->name, group))
       return NULL;
 
-  grent = getgrnam (group);
+  struct group *grent = getgrnam (group);
 #ifdef __DJGPP__
   /* We need to pretend to belong to group GROUP, to make
      grp functions know about an arbitrary group name.  */
index 45300c91eed1fa9d14c0c5f5ce0a0a85d4e27a44..d2052777188d2d75d78345bd6eda5e677216431d 100644 (file)
@@ -125,9 +125,7 @@ static const char *
 inet_ntop4 (const unsigned char *src, char *dst, socklen_t size)
 {
   char tmp[sizeof "255.255.255.255"];
-  int len;
-
-  len = sprintf (tmp, "%u.%u.%u.%u", src[0], src[1], src[2], src[3]);
+  int len = sprintf (tmp, "%u.%u.%u.%u", src[0], src[1], src[2], src[3]);
   if (len < 0)
     return NULL;
 
@@ -151,32 +149,25 @@ inet_ntop4 (const unsigned char *src, char *dst, socklen_t size)
 static const char *
 inet_ntop6 (const unsigned char *src, char *dst, socklen_t size)
 {
-  /*
-   * Note that int32_t and int16_t need only be "at least" large enough
-   * to contain a value of the specified size.  On some systems, like
-   * Crays, there is no such thing as an integer variable with 16 bits.
-   * Keep this in mind if you think this function should have been coded
-   * to use pointer overlays.  All the world's not a VAX.
-   */
-  char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
-  struct
-  {
-    int base, len;
-  } best, cur;
-  unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];
-
   /*
    * Preprocess:
    *      Copy the input (bytewise) array into a wordwise array.
    *      Find the longest run of 0x00's in src[] for :: shorthanding.
    */
+  unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];
   memset (words, '\0', sizeof words);
   for (int i = 0; i < NS_IN6ADDRSZ; i += 2)
     words[i / 2] = (src[i] << 8) | src[i + 1];
+
+  struct
+  {
+    int base, len;
+  } best, cur;
   best.base = -1;
   cur.base = -1;
   IF_LINT(best.len = 0);
   IF_LINT(cur.len = 0);
+
   for (int i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
     {
       if (words[i] == 0)
@@ -207,7 +198,15 @@ inet_ntop6 (const unsigned char *src, char *dst, socklen_t size)
   /*
    * Format the result.
    */
-  tp = tmp;
+  /*
+   * Note that int32_t and int16_t need only be "at least" large enough
+   * to contain a value of the specified size.  On some systems, like
+   * Crays, there is no such thing as an integer variable with 16 bits.
+   * Keep this in mind if you think this function should have been coded
+   * to use pointer overlays.  All the world's not a VAX.
+   */
+  char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
+  char *tp = tmp;
   for (int i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
     {
       /* Are we inside the best run of 0x00's? */
index d891cd0a609af80ff2ea74f0acd468621d7fb8eb..2f4e98d2fbdb5cb6ba8ee417aac309d2c9de0746 100644 (file)
@@ -112,43 +112,44 @@ inet_pton (int af, const char *restrict src, void *restrict dst)
 static int
 inet_pton4 (const char *restrict src, unsigned char *restrict dst)
 {
-  int saw_digit, octets, ch;
-  unsigned char tmp[NS_INADDRSZ], *tp;
+  unsigned char tmp[NS_INADDRSZ];
 
-  saw_digit = 0;
-  octets = 0;
-  *(tp = tmp) = 0;
-  while ((ch = *src++) != '\0')
-    {
-
-      if (ch >= '0' && ch <= '9')
-        {
-          unsigned new = *tp * 10 + (ch - '0');
-
-          if (saw_digit && *tp == 0)
-            return (0);
-          if (new > 255)
-            return (0);
-          *tp = new;
-          if (!saw_digit)
-            {
-              if (++octets > 4)
-                return (0);
-              saw_digit = 1;
-            }
-        }
-      else if (ch == '.' && saw_digit)
-        {
-          if (octets == 4)
-            return (0);
-          *++tp = 0;
-          saw_digit = 0;
-        }
-      else
-        return (0);
-    }
-  if (octets < 4)
-    return (0);
+  {
+    int saw_digit = 0;
+    int octets = 0;
+    unsigned char *tp = tmp;
+    *tp = 0;
+    int ch;
+    while ((ch = *src++) != '\0')
+      {
+        if (ch >= '0' && ch <= '9')
+          {
+            if (saw_digit && *tp == 0)
+              return (0);
+            unsigned new = *tp * 10 + (ch - '0');
+            if (new > 255)
+              return (0);
+            *tp = new;
+            if (!saw_digit)
+              {
+                if (++octets > 4)
+                  return (0);
+                saw_digit = 1;
+              }
+          }
+        else if (ch == '.' && saw_digit)
+          {
+            if (octets == 4)
+              return (0);
+            *++tp = 0;
+            saw_digit = 0;
+          }
+        else
+          return (0);
+      }
+    if (octets < 4)
+      return (0);
+  }
   memcpy (dst, tmp, NS_INADDRSZ);
   return (1);
 }
@@ -172,93 +173,89 @@ static int
 inet_pton6 (const char *restrict src, unsigned char *restrict dst)
 {
   static const char xdigits[] = "0123456789abcdef";
-  unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
-  const char *curtok;
-  int ch, saw_xdigit;
-  unsigned val;
+  unsigned char tmp[NS_IN6ADDRSZ];
 
-  tp = memset (tmp, '\0', NS_IN6ADDRSZ);
-  endp = tp + NS_IN6ADDRSZ;
-  colonp = NULL;
   /* Leading :: requires some special handling. */
   if (*src == ':')
     if (*++src != ':')
       return (0);
-  curtok = src;
-  saw_xdigit = 0;
-  val = 0;
-  while ((ch = c_tolower (*src++)) != '\0')
-    {
-      const char *pch;
 
-      pch = strchr (xdigits, ch);
-      if (pch != NULL)
-        {
-          val <<= 4;
-          val |= (pch - xdigits);
-          if (val > 0xffff)
-            return (0);
-          saw_xdigit = 1;
-        }
-      else if (ch == ':')
-        {
-          curtok = src;
-          if (!saw_xdigit)
-            {
-              if (colonp)
-                return (0);
-              colonp = tp;
-            }
-          else if (*src == '\0')
-            {
+  {
+    unsigned char *tp = memset (tmp, '\0', NS_IN6ADDRSZ);
+    unsigned char *endp = tp + NS_IN6ADDRSZ;
+    unsigned char *colonp = NULL;
+    const char *curtok = src;
+    int saw_xdigit = 0;
+    unsigned int val = 0;
+    int ch;
+    while ((ch = c_tolower (*src++)) != '\0')
+      {
+        const char *pch = strchr (xdigits, ch);
+        if (pch != NULL)
+          {
+            val <<= 4;
+            val |= (pch - xdigits);
+            if (val > 0xffff)
               return (0);
-            }
-          else if (tp + NS_INT16SZ > endp)
-            return (0);
-          else
-            {
-              *tp++ = (unsigned char) (val >> 8) & 0xff;
-              *tp++ = (unsigned char) val & 0xff;
-              saw_xdigit = 0;
-              val = 0;
-            }
-        }
-      else if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
-          inet_pton4 (curtok, tp) > 0)
-        {
-          tp += NS_INADDRSZ;
-          saw_xdigit = 0;
-          break;                /* '\0' was seen by inet_pton4(). */
-        }
-      else
-        return (0);
-    }
-  if (saw_xdigit)
-    {
-      if (tp + NS_INT16SZ > endp)
-        return (0);
-      *tp++ = (unsigned char) (val >> 8) & 0xff;
-      *tp++ = (unsigned char) val & 0xff;
-    }
-  if (colonp != NULL)
-    {
-      /*
-       * Since some memmove()'s erroneously fail to handle
-       * overlapping regions, we'll do the shift by hand.
-       */
-      const int n = tp - colonp;
-
-      if (tp == endp)
-        return (0);
-      for (int i = 1; i <= n; i++)
-        {
-          endp[-i] = colonp[n - i];
-          colonp[n - i] = 0;
-        }
-      tp = endp;
-    }
-  if (tp != endp)
-    return (0);
+            saw_xdigit = 1;
+          }
+        else if (ch == ':')
+          {
+            curtok = src;
+            if (!saw_xdigit)
+              {
+                if (colonp)
+                  return (0);
+                colonp = tp;
+              }
+            else if (*src == '\0')
+              return (0);
+            else if (tp + NS_INT16SZ > endp)
+              return (0);
+            else
+              {
+                *tp++ = (unsigned char) (val >> 8) & 0xff;
+                *tp++ = (unsigned char) val & 0xff;
+                saw_xdigit = 0;
+                val = 0;
+              }
+          }
+        else if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
+            inet_pton4 (curtok, tp) > 0)
+          {
+            tp += NS_INADDRSZ;
+            saw_xdigit = 0;
+            break;                /* '\0' was seen by inet_pton4(). */
+          }
+        else
+          return (0);
+      }
+    if (saw_xdigit)
+      {
+        if (tp + NS_INT16SZ > endp)
+          return (0);
+        *tp++ = (unsigned char) (val >> 8) & 0xff;
+        *tp++ = (unsigned char) val & 0xff;
+      }
+    if (colonp != NULL)
+      {
+        if (tp == endp)
+          return (0);
+        /*
+         * Since some memmove()'s erroneously fail to handle
+         * overlapping regions, we'll do the shift by hand.
+         */
+        const int n = tp - colonp;
+        for (int i = 1; i <= n; i++)
+          {
+            endp[-i] = colonp[n - i];
+            colonp[n - i] = 0;
+          }
+        tp = endp;
+      }
+    if (tp != endp)
+      return (0);
+  }
   memcpy (dst, tmp, NS_IN6ADDRSZ);
   return (1);
 }
index 71c60574970106145b86cf1f777a971c997a780b..6338a083907c9f459f67bcc570626565a6d14a5d 100644 (file)
@@ -116,8 +116,6 @@ ino_map_free (struct ino_map *map)
 size_t
 ino_map_insert (struct ino_map *im, ino_t ino)
 {
-  struct ino_map_ent *ent;
-
   /* Find space for the probe, reusing the cache if available.  */
   struct ino_map_ent *probe = im->probe;
   if (probe)
@@ -134,7 +132,7 @@ ino_map_insert (struct ino_map *im, ino_t ino)
     }
 
   probe->ino = ino;
-  ent = hash_insert (im->map, probe);
+  struct ino_map_ent *ent = hash_insert (im->map, probe);
   if (! ent)
     return INO_MAP_INSERT_FAILURE;
 
index 9d64ab510e9e5153425bd8fe5c0fa80a06cfe8d3..3fc49d66ffacd2c0b5af31e3b405dc487086a94c 100644 (file)
@@ -65,7 +65,6 @@ integer_length (unsigned int x)
       else
         {
           memory_double m;
-          unsigned int exponent;
 
           if (1)
             {
@@ -95,7 +94,7 @@ integer_length (unsigned int x)
               m.value = m.value - TWO_DBL_MANT_DIG;
             }
 
-          exponent =
+          unsigned int exponent =
             (m.word[DBL_EXPBIT0_WORD] >> DBL_EXPBIT0_BIT) & DBL_EXP_MASK;
           return exponent - DBL_EXP_BIAS;
         }
index a92df8b129e8d4fcb3cee395d5b161af6e73fd51..2541f9a6e74aeb622809b225d41217f4a9b8661b 100644 (file)
 int
 rpl_ioctl (int fd, int request, ... /* {void *,char *} arg */)
 {
-  void *buf;
   va_list args;
-
   va_start (args, request);
-  buf = va_arg (args, void *);
+  void *buf = va_arg (args, void *);
   va_end (args);
 
   /* Cast 'request' so that when the system's ioctl function takes a 64-bit
@@ -75,11 +73,9 @@ primary_ioctl (int fd, int request, void *arg)
 int
 ioctl (int fd, int request, ... /* {void *,char *} arg */)
 {
-  void *arg;
   va_list args;
-
   va_start (args, request);
-  arg = va_arg (args, void *);
+  void *arg = va_arg (args, void *);
   va_end (args);
 
 # if WINDOWS_SOCKETS
index 46946e97bd96f2c09cc15ced784194b7ac1a5930..af52b8de7e9973a2b18fdf2e6d6468a3f26ea0cc 100644 (file)
@@ -38,11 +38,10 @@ FUNC (int c, locale_t locale)
 #else
   /* Implementation for the global locale.  */
   {
-    int ret;
 # if HAVE_WORKING_USELOCALE
     locale_t saved_locale = uselocale (LC_GLOBAL_LOCALE);
 # endif
-    ret = GLOBAL_FUNC (c);
+    int ret = GLOBAL_FUNC (c);
 # if HAVE_WORKING_USELOCALE
     uselocale (saved_locale);
 # endif
index 3543c06887808d23170596b55717ff0e54d5153a..b50bfd421ce254585c3b9194f2d4dde381cd80ec 100644 (file)
@@ -73,9 +73,9 @@ isapipe (int fd)
 {
   nlink_t pipe_link_count_max = PIPE_LINK_COUNT_MAX;
   bool check_for_fifo = (HAVE_FIFO_PIPES == 1);
+
   struct stat st;
   int fstat_result = fstat (fd, &st);
-
   if (fstat_result != 0)
     return fstat_result;
 
index 23e3ab8f6df72146adc827573ca144aa895bda2f..a44b5d23cc750efaf3b7fd7a54c72e486b92f207 100644 (file)
@@ -94,46 +94,48 @@ static BOOL IsConsoleHandle (HANDLE h)
 
 static BOOL IsCygwinConsoleHandle (HANDLE h)
 {
-  /* A handle to a Cygwin console is in fact a named pipe whose client process
-     and server process is <CYGWIN_INSTALL_DIR>\bin\mintty.exe.  */
-  BOOL result = FALSE;
-  ULONG processId;
-
 #if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA)
   if (!initialized)
     initialize ();
 #endif
 
+  /* A handle to a Cygwin console is in fact a named pipe whose client process
+     and server process is <CYGWIN_INSTALL_DIR>\bin\mintty.exe.  */
+  BOOL result = FALSE;
+
   /* GetNamedPipeClientProcessId
      <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getnamedpipeclientprocessid>
      It requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher.  */
-  if (GetNamedPipeClientProcessIdFunc && QueryFullProcessImageNameFunc
-      && GetNamedPipeClientProcessIdFunc (h, &processId))
+  if (GetNamedPipeClientProcessIdFunc && QueryFullProcessImageNameFunc)
     {
-      /* OpenProcess
-         <https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openprocess> */
-      HANDLE processHandle =
-        OpenProcess (PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);
-      if (processHandle != NULL)
+      ULONG processId;
+      if (GetNamedPipeClientProcessIdFunc (h, &processId))
         {
-          char buf[1024];
-          DWORD bufsize = sizeof (buf);
-          /* The file name can be determined through
-             GetProcessImageFileName
-             <https://docs.microsoft.com/en-us/windows/desktop/api/psapi/nf-psapi-getprocessimagefilenamea>
-             or
-             QueryFullProcessImageName
-             <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-queryfullprocessimagenamea>
-             The former returns a file name in non-standard notation (it starts
-             with '\Device\') and may require linking with psapi.dll.
-             The latter is better, but requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA
-             or higher.  */
-          if (QueryFullProcessImageNameFunc (processHandle, 0, buf, &bufsize))
+          /* OpenProcess
+             <https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openprocess> */
+          HANDLE processHandle =
+            OpenProcess (PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);
+          if (processHandle != NULL)
             {
-              if (str_endswith (buf, "\\mintty.exe"))
-                result = TRUE;
+              char buf[1024];
+              DWORD bufsize = sizeof (buf);
+              /* The file name can be determined through
+                 GetProcessImageFileName
+                 <https://docs.microsoft.com/en-us/windows/desktop/api/psapi/nf-psapi-getprocessimagefilenamea>
+                 or
+                 QueryFullProcessImageName
+                 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-queryfullprocessimagenamea>
+                 The former returns a file name in non-standard notation (it
+                 starts with '\Device\') and may require linking with psapi.dll.
+                 The latter is better, but requires
+                 -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher.  */
+              if (QueryFullProcessImageNameFunc (processHandle, 0, buf, &bufsize))
+                {
+                  if (str_endswith (buf, "\\mintty.exe"))
+                    result = TRUE;
+                }
+              CloseHandle (processHandle);
             }
-          CloseHandle (processHandle);
         }
     }
   return result;
index 915187bafa91d091b26e80065484ec3930a2050d..1d6134c9e67f1096347b75a009e72cabf3a40f8b 100644 (file)
@@ -105,10 +105,8 @@ FUNC (DOUBLE x)
      The NaN bit pattern is:
        - exponent = 0x7FFF, mantissa >= 0x8000000000000001.  */
   memory_double m;
-  unsigned int exponent;
-
   m.value = x;
-  exponent = (m.word[EXPBIT0_WORD] >> EXPBIT0_BIT) & EXP_MASK;
+  unsigned int exponent = (m.word[EXPBIT0_WORD] >> EXPBIT0_BIT) & EXP_MASK;
 #  ifdef WORDS_BIGENDIAN
   /* Big endian: EXPBIT0_WORD = 0, EXPBIT0_BIT = 16.  */
   if (exponent == 0)
@@ -138,9 +136,9 @@ FUNC (DOUBLE x)
      Visual C/C++ compiler also fails when constant-folding 1.0 / 0.0 even
      when constant-folding is not required.  */
   static DOUBLE zero = L_(0.0);
-  memory_double nan;
   DOUBLE plus_inf = L_(1.0) / zero;
   DOUBLE minus_inf = -L_(1.0) / zero;
+  memory_double nan;
   nan.value = zero / zero;
 #  else
   static memory_double nan = { L_(0.0) / L_(0.0) };
@@ -149,10 +147,10 @@ FUNC (DOUBLE x)
 #  endif
   {
     memory_double m;
+    m.value = x;
 
     /* A NaN can be recognized through its exponent.  But exclude +Infinity and
        -Infinity, which have the same exponent.  */
-    m.value = x;
     if (((m.word[EXPBIT0_WORD] ^ nan.word[EXPBIT0_WORD])
          & (EXP_MASK << EXPBIT0_BIT))
         == 0)
@@ -171,12 +169,13 @@ FUNC (DOUBLE x)
 # if defined USE_LONG_DOUBLE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
       /* Detect any special bit patterns that pass ==; see comment above.  */
       memory_double m1;
-      memory_double m2;
-
       memset (&m1.value, 0, SIZE);
-      memset (&m2.value, 0, SIZE);
       m1.value = x;
+
+      memory_double m2;
+      memset (&m2.value, 0, SIZE);
       m2.value = x + (x ? 0.0L : -0.0L);
+
       if (!memeq (&m1.value, &m2.value, SIZE))
         return 1;
 # endif
index e43aa67dfcd41c08b6fab314700ea8b6e70a6949..bc6abb239d488e344111ebd236bf9d9bdd28fd9b 100644 (file)
@@ -183,14 +183,8 @@ compile_using_envjavac (const char *javac,
      shell.  Because $JAVAC has been set by the user, we leave all
      environment variables in place, including JAVA_HOME, and we don't
      erase the user's CLASSPATH.  */
-  bool err;
-  unsigned int command_length;
-  char *command;
-  const char *argv[4];
-  int exitstatus;
-  char *p;
 
-  command_length = strlen (javac);
+  unsigned int command_length = strlen (javac);
   if (optimize)
     command_length += 3;
   if (debug)
@@ -201,49 +195,52 @@ compile_using_envjavac (const char *javac,
     command_length += 1 + shell_quote_length (java_sources[i]);
   command_length += 1;
 
-  command = (char *) xmalloca (command_length);
-  p = command;
-  /* Don't shell_quote $JAVAC, because it may consist of a command
-     and options.  */
-  memcpy (p, javac, strlen (javac));
-  p += strlen (javac);
-  if (optimize)
-    {
-      memcpy (p, " -O", 3);
-      p += 3;
-    }
-  if (debug)
-    {
-      memcpy (p, " -g", 3);
-      p += 3;
-    }
-  if (directory != NULL)
-    {
-      memcpy (p, " -d ", 4);
-      p += 4;
-      p = shell_quote_copy (p, directory);
-    }
-  for (unsigned int i = 0; i < java_sources_count; i++)
-    {
-      *p++ = ' ';
-      p = shell_quote_copy (p, java_sources[i]);
-    }
-  *p++ = '\0';
-  /* Ensure command_length was correctly calculated.  */
-  if (p - command > command_length)
-    abort ();
+  char *command = (char *) xmalloca (command_length);
+  {
+    char *p = command;
+    /* Don't shell_quote $JAVAC, because it may consist of a command
+       and options.  */
+    memcpy (p, javac, strlen (javac));
+    p += strlen (javac);
+    if (optimize)
+      {
+        memcpy (p, " -O", 3);
+        p += 3;
+      }
+    if (debug)
+      {
+        memcpy (p, " -g", 3);
+        p += 3;
+      }
+    if (directory != NULL)
+      {
+        memcpy (p, " -d ", 4);
+        p += 4;
+        p = shell_quote_copy (p, directory);
+      }
+    for (unsigned int i = 0; i < java_sources_count; i++)
+      {
+        *p++ = ' ';
+        p = shell_quote_copy (p, java_sources[i]);
+      }
+    *p++ = '\0';
+    /* Ensure command_length was correctly calculated.  */
+    if (p - command > command_length)
+      abort ();
+  }
 
   if (verbose)
     printf ("%s\n", command);
 
+  const char *argv[4];
   argv[0] = BOURNE_SHELL;
   argv[1] = "-c";
   argv[2] = command;
   argv[3] = NULL;
-  exitstatus = execute (javac, BOURNE_SHELL, argv, NULL, NULL,
-                        false, false, false, null_stderr,
-                        true, true, NULL);
-  err = (exitstatus != 0);
+  int exitstatus = execute (javac, BOURNE_SHELL, argv, NULL, NULL,
+                            false, false, false, null_stderr,
+                            true, true, NULL);
+  bool err = (exitstatus != 0);
 
   freea (command);
 
@@ -262,47 +259,42 @@ compile_using_javac (const char * const *java_sources,
                      bool optimize, bool debug,
                      bool verbose, bool null_stderr)
 {
-  bool err;
-  unsigned int argc;
-  const char **argv;
-  const char **argp;
-  int exitstatus;
-
-  argc =
+  unsigned int argc =
     1 + (nowarn_option != NULL ? 1 : 0) + (source_option ? 2 : 0)
     + (target_option ? 2 : 0) + (optimize ? 1 : 0) + (debug ? 1 : 0)
     + (directory != NULL ? 2 : 0) + java_sources_count;
-  argv = (const char **) xmalloca ((argc + 1) * sizeof (const char *));
-
-  argp = argv;
-  *argp++ = "javac";
-  if (nowarn_option != NULL)
-    *argp++ = nowarn_option;
-  if (source_option)
-    {
-      *argp++ = "-source";
-      *argp++ = source_version;
-    }
-  if (target_option)
-    {
-      *argp++ = "-target";
-      *argp++ = target_version;
-    }
-  if (optimize)
-    *argp++ = "-O";
-  if (debug)
-    *argp++ = "-g";
-  if (directory != NULL)
-    {
-      *argp++ = "-d";
-      *argp++ = directory;
-    }
-  for (unsigned int i = 0; i < java_sources_count; i++)
-    *argp++ = java_sources[i];
-  *argp = NULL;
-  /* Ensure argv length was correctly calculated.  */
-  if (argp - argv != argc)
-    abort ();
+  const char **argv = (const char **) xmalloca ((argc + 1) * sizeof (const char *));
+  {
+    const char **argp = argv;
+    *argp++ = "javac";
+    if (nowarn_option != NULL)
+      *argp++ = nowarn_option;
+    if (source_option)
+      {
+        *argp++ = "-source";
+        *argp++ = source_version;
+      }
+    if (target_option)
+      {
+        *argp++ = "-target";
+        *argp++ = target_version;
+      }
+    if (optimize)
+      *argp++ = "-O";
+    if (debug)
+      *argp++ = "-g";
+    if (directory != NULL)
+      {
+        *argp++ = "-d";
+        *argp++ = directory;
+      }
+    for (unsigned int i = 0; i < java_sources_count; i++)
+      *argp++ = java_sources[i];
+    *argp = NULL;
+    /* Ensure argv length was correctly calculated.  */
+    if (argp - argv != argc)
+      abort ();
+  }
 
   if (verbose)
     {
@@ -311,10 +303,10 @@ compile_using_javac (const char * const *java_sources,
       free (command);
     }
 
-  exitstatus = execute ("javac", "javac", argv, NULL, NULL,
-                        false, false, false,
-                        null_stderr, true, true, NULL);
-  err = (exitstatus != 0);
+  int exitstatus = execute ("javac", "javac", argv, NULL, NULL,
+                            false, false, false,
+                            null_stderr, true, true, NULL);
+  bool err = (exitstatus != 0);
 
   freea (argv);
 
@@ -330,27 +322,22 @@ static char *
 execute_and_read_line (const char *progname,
                        const char *prog_path, const char * const *prog_argv)
 {
-  pid_t child;
-  int fd[1];
-  FILE *fp;
-  char *line;
-  size_t linesize;
-  size_t linelen;
-
   /* Open a pipe to the program.  */
-  child = create_pipe_in (progname, prog_path, prog_argv, NULL, NULL,
-                          DEV_NULL, false, true, false, fd);
+  int fd[1];
+  pid_t child = create_pipe_in (progname, prog_path, prog_argv, NULL, NULL,
+                                DEV_NULL, false, true, false, fd);
 
   if (child == -1)
     return NULL;
 
   /* Retrieve its result.  */
-  fp = fdopen (fd[0], "r");
+  FILE *fp = fdopen (fd[0], "r");
   if (fp == NULL)
     error (EXIT_FAILURE, errno, _("fdopen() failed"));
 
-  line = NULL; linesize = 0;
-  linelen = getline (&line, &linesize, fp);
+  char *line = NULL;
+  size_t linesize = 0;
+  size_t linelen = getline (&line, &linesize, fp);
   if (linelen == (size_t)(-1))
     {
       error (0, 0, _("%s subprocess I/O error"), progname);
@@ -359,8 +346,6 @@ execute_and_read_line (const char *progname,
     }
   else
     {
-      int exitstatus;
-
       if (linelen > 0 && line[linelen - 1] == '\n')
         line[linelen - 1] = '\0';
 
@@ -371,7 +356,7 @@ execute_and_read_line (const char *progname,
       fclose (fp);
 
       /* Remove zombie process from process list, and retrieve exit status.  */
-      exitstatus =
+      int exitstatus =
         wait_subprocess (child, progname, true, false, true, false, NULL);
       if (exitstatus == 0)
         return line;
@@ -445,10 +430,8 @@ static bool
 write_temp_file (struct temp_dir *tmpdir, const char *file_name,
                  const char *contents)
 {
-  FILE *fp;
-
   register_temp_file (tmpdir, file_name);
-  fp = fopen_temp (file_name, "we", false);
+  FILE *fp = fopen_temp (file_name, "we", false);
   if (fp == NULL)
     {
       error (0, errno, _("failed to create \"%s\""), file_name);
@@ -468,14 +451,13 @@ write_temp_file (struct temp_dir *tmpdir, const char *file_name,
 static int
 get_classfile_version (const char *compiled_file_name)
 {
-  unsigned char header[8];
-  int fd;
 
   /* Open the class file.  */
-  fd = open (compiled_file_name, O_RDONLY | O_BINARY | O_CLOEXEC, 0);
+  int fd = open (compiled_file_name, O_RDONLY | O_BINARY | O_CLOEXEC, 0);
   if (fd >= 0)
     {
       /* Read its first 8 bytes.  */
+      unsigned char header[8];
       if (safe_read (fd, header, 8) == 8)
         {
           /* Verify the class file signature.  */
@@ -527,18 +509,11 @@ is_envjavac_usable (const char *javac,
       if (try_source_version <= try_target_version)
         {
           /* Try $JAVAC.  */
-          struct temp_dir *tmpdir;
-          char *conftest_file_name;
-          char *compiled_file_name;
-          const char *java_sources[1];
-          const char *nowarn_option;
-          struct stat statbuf;
-
-          tmpdir = create_temp_dir ("java", NULL, false);
+          struct temp_dir *tmpdir = create_temp_dir ("java", NULL, false);
           if (tmpdir == NULL)
             return true;
 
-          conftest_file_name =
+          char *conftest_file_name =
             xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL);
           if (write_temp_file (tmpdir, conftest_file_name, "class conftest {}"))
             {
@@ -547,16 +522,18 @@ is_envjavac_usable (const char *javac,
               return true;
             }
 
-          compiled_file_name =
+          char *compiled_file_name =
             xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL);
           register_temp_file (tmpdir, compiled_file_name);
 
           /* See the discussion in javacomp.m4.  */
-          nowarn_option = " -Xlint:-options";
+          const char *nowarn_option = " -Xlint:-options";
           char *javac_nowarn = xasprintf ("%s%s", javac, nowarn_option);
           assume (javac_nowarn != NULL);
 
+          const char *java_sources[1];
           java_sources[0] = conftest_file_name;
+          struct stat statbuf;
           if ((!compile_using_envjavac (javac_nowarn,
                                         java_sources, 1, tmpdir->dir_name,
                                         false, false, false, true)
@@ -756,13 +733,11 @@ is_javac_present (void)
     {
       /* Test for presence of javac: "javac 2> /dev/null ; test $? -le 2"  */
       const char *argv[2];
-      int exitstatus;
-
       argv[0] = "javac";
       argv[1] = NULL;
-      exitstatus = execute ("javac", "javac", argv, NULL, NULL,
-                            false, false, true, true,
-                            true, false, NULL);
+      int exitstatus = execute ("javac", "javac", argv, NULL, NULL,
+                                false, false, true, true,
+                                true, false, NULL);
       javac_present = (exitstatus == 0 || exitstatus == 1 || exitstatus == 2);
       javac_tested = true;
     }
@@ -803,18 +778,11 @@ is_javac_usable (const char *source_version, const char *target_version,
       if (try_source_version <= try_target_version)
         {
           /* Try javac.  */
-          struct temp_dir *tmpdir;
-          char *conftest_file_name;
-          char *compiled_file_name;
-          const char *java_sources[1];
-          const char *nowarn_option;
-          struct stat statbuf;
-
-          tmpdir = create_temp_dir ("java", NULL, false);
+          struct temp_dir *tmpdir = create_temp_dir ("java", NULL, false);
           if (tmpdir == NULL)
             return true;
 
-          conftest_file_name =
+          char *conftest_file_name =
             xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL);
           if (write_temp_file (tmpdir, conftest_file_name, "class conftest {}"))
             {
@@ -823,14 +791,16 @@ is_javac_usable (const char *source_version, const char *target_version,
               return true;
             }
 
-          compiled_file_name =
+          char *compiled_file_name =
             xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL);
           register_temp_file (tmpdir, compiled_file_name);
 
           /* See the discussion in javacomp.m4.  */
-          nowarn_option = "-Xlint:-options";
+          const char *nowarn_option = "-Xlint:-options";
 
+          const char *java_sources[1];
           java_sources[0] = conftest_file_name;
+          struct stat statbuf;
           if ((!compile_using_javac (java_sources, 1,
                                      nowarn_option,
                                      false, source_version,
@@ -903,7 +873,6 @@ is_javac_usable (const char *source_version, const char *target_version,
 
                   {
                     const char *argv[3];
-
                     argv[0] = "javac";
                     argv[1] = "-version";
                     argv[2] = NULL;
@@ -1006,9 +975,6 @@ compile_java_class (const char * const *java_sources,
                     bool use_minimal_classpath,
                     bool verbose)
 {
-  bool err = false;
-  char *old_JAVA_HOME;
-
   /* Map source_version 1.1 ... 1.7 to 1.8.  */
   if (source_version[0] == '1' && source_version[1] == '.'
       && (source_version[2] >= '1' && source_version[2] <= '7')
@@ -1022,6 +988,8 @@ compile_java_class (const char * const *java_sources,
       && target_version[3] == '\0')
     target_version = "1.8";
 
+  bool err = false;
+
   {
     const char *javac = getenv ("JAVAC");
     if (javac != NULL && javac[0] != '\0')
@@ -1074,7 +1042,7 @@ compile_java_class (const char * const *java_sources,
   }
 
   /* Unset the JAVA_HOME environment variable.  */
-  old_JAVA_HOME = getenv ("JAVA_HOME");
+  char *old_JAVA_HOME = getenv ("JAVA_HOME");
   if (old_JAVA_HOME != NULL)
     {
       old_JAVA_HOME = xstrdup (old_JAVA_HOME);
@@ -1102,13 +1070,11 @@ compile_java_class (const char * const *java_sources,
 
       if (usable)
         {
-          char *old_classpath;
-
           /* 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, but we don't know its location.  (In JDK 1.3.0 it
              would work.)  */
-          old_classpath =
+          char *old_classpath =
             set_classpath (classpaths, classpaths_count, use_minimal_classpath,
                            verbose);
 
index fd20d8f9b549f74fadcd9239840c1c6f364216e7..dec937c2e8a7966c253098aecba88588234f5038 100644 (file)
@@ -76,10 +76,9 @@ execute_java_class (const char *class_name,
                     execute_fn *executer, void *private_data)
 {
   bool err = false;
-  unsigned int nargs;
-  char *old_JAVA_HOME;
 
   /* Count args.  */
+  unsigned int nargs;
   {
     const char * const *arg;
 
@@ -91,15 +90,14 @@ execute_java_class (const char *class_name,
   if (exe_dir != NULL)
     {
       char *exe_pathname = xconcatenated_filename (exe_dir, class_name, EXEEXT);
-      char *old_classpath;
-      const char **argv =
-        (const char **) xmalloca ((1 + nargs + 1) * sizeof (const char *));
 
       /* Set CLASSPATH.  */
-      old_classpath =
+      char *old_classpath =
         set_classpath (classpaths, classpaths_count, use_minimal_classpath,
                        verbose);
 
+      const char **argv =
+        (const char **) xmalloca ((1 + nargs + 1) * sizeof (const char *));
       argv[0] = exe_pathname;
       for (unsigned int i = 0; i <= nargs; i++)
         argv[1 + i] = args[i];
@@ -113,11 +111,11 @@ execute_java_class (const char *class_name,
 
       err = executer (class_name, exe_pathname, argv, private_data);
 
+      freea (argv);
+
       /* Reset CLASSPATH.  */
       reset_classpath (old_classpath);
 
-      freea (argv);
-
       goto done1;
     }
 
@@ -129,44 +127,42 @@ execute_java_class (const char *class_name,
            shell.  Because $JAVA has been set by the user, we leave all
            all environment variables in place, including JAVA_HOME, and
            we don't erase the user's CLASSPATH.  */
-        char *old_classpath;
-        unsigned int command_length;
-        char *command;
-        const char *argv[4];
-        char *p;
 
         /* Set CLASSPATH.  */
-        old_classpath =
+        char *old_classpath =
           set_classpath (classpaths, classpaths_count, false,
                          verbose);
 
-        command_length = strlen (java);
+        unsigned int command_length = strlen (java);
         command_length += 1 + shell_quote_length (class_name);
         for (const char * const *arg = args; *arg != NULL; arg++)
           command_length += 1 + shell_quote_length (*arg);
         command_length += 1;
 
-        command = (char *) xmalloca (command_length);
-        p = command;
-        /* Don't shell_quote $JAVA, because it may consist of a command
-           and options.  */
-        memcpy (p, java, strlen (java));
-        p += strlen (java);
-        *p++ = ' ';
-        p = shell_quote_copy (p, class_name);
-        for (const char * const *arg = args; *arg != NULL; arg++)
-          {
-            *p++ = ' ';
-            p = shell_quote_copy (p, *arg);
-          }
-        *p++ = '\0';
-        /* Ensure command_length was correctly calculated.  */
-        if (p - command > command_length)
-          abort ();
+        char *command = (char *) xmalloca (command_length);
+        {
+          char *p = command;
+          /* Don't shell_quote $JAVA, because it may consist of a command
+             and options.  */
+          memcpy (p, java, strlen (java));
+          p += strlen (java);
+          *p++ = ' ';
+          p = shell_quote_copy (p, class_name);
+          for (const char * const *arg = args; *arg != NULL; arg++)
+            {
+              *p++ = ' ';
+              p = shell_quote_copy (p, *arg);
+            }
+          *p++ = '\0';
+          /* Ensure command_length was correctly calculated.  */
+          if (p - command > command_length)
+            abort ();
+        }
 
         if (verbose)
           printf ("%s\n", command);
 
+        const char *argv[4];
         argv[0] = BOURNE_SHELL;
         argv[1] = "-c";
         argv[2] = command;
@@ -183,7 +179,7 @@ execute_java_class (const char *class_name,
   }
 
   /* Unset the JAVA_HOME environment variable.  */
-  old_JAVA_HOME = getenv ("JAVA_HOME");
+  char *old_JAVA_HOME = getenv ("JAVA_HOME");
   if (old_JAVA_HOME != NULL)
     {
       old_JAVA_HOME = xstrdup (old_JAVA_HOME);
@@ -198,31 +194,27 @@ execute_java_class (const char *class_name,
       {
         /* Test for presence of java: "java -version 2> /dev/null"  */
         const char *argv[3];
-        int exitstatus;
-
         argv[0] = "java";
         argv[1] = "-version";
         argv[2] = NULL;
-        exitstatus = execute ("java", "java", argv, NULL, NULL,
-                              false, false, true, true,
-                              true, false, NULL);
+        int exitstatus = execute ("java", "java", argv, NULL, NULL,
+                                  false, false, true, true,
+                                  true, false, NULL);
         java_present = (exitstatus == 0);
         java_tested = true;
       }
 
     if (java_present)
       {
-        char *old_classpath;
-        const char **argv =
-          (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
-
         /* 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,
            but we don't know its location.  (In JDK 1.3.0 it would work.)  */
-        old_classpath =
+        char *old_classpath =
           set_classpath (classpaths, classpaths_count, use_minimal_classpath,
                          verbose);
 
+        const char **argv =
+          (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
         argv[0] = "java";
         argv[1] = class_name;
         for (unsigned int i = 0; i <= nargs; i++)
@@ -237,11 +229,11 @@ execute_java_class (const char *class_name,
 
         err = executer ("java", "java", argv, private_data);
 
+        freea (argv);
+
         /* Reset CLASSPATH.  */
         reset_classpath (old_classpath);
 
-        freea (argv);
-
         goto done2;
       }
   }
@@ -254,30 +246,26 @@ execute_java_class (const char *class_name,
       {
         /* Test for presence of jre: "jre 2> /dev/null ; test $? = 1"  */
         const char *argv[2];
-        int exitstatus;
-
         argv[0] = "jre";
         argv[1] = NULL;
-        exitstatus = execute ("jre", "jre", argv, NULL, NULL,
-                              false, false, true, true,
-                              true, false, NULL);
+        int exitstatus = execute ("jre", "jre", argv, NULL, NULL,
+                                  false, false, true, true,
+                                  true, false, NULL);
         jre_present = (exitstatus == 0 || exitstatus == 1);
         jre_tested = true;
       }
 
     if (jre_present)
       {
-        char *old_classpath;
-        const char **argv =
-          (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
-
         /* 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,
            but we don't know its location.  */
-        old_classpath =
+        char *old_classpath =
           set_classpath (classpaths, classpaths_count, use_minimal_classpath,
                          verbose);
 
+        const char **argv =
+          (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
         argv[0] = "jre";
         argv[1] = class_name;
         for (unsigned int i = 0; i <= nargs; i++)
@@ -292,11 +280,11 @@ execute_java_class (const char *class_name,
 
         err = executer ("jre", "jre", argv, private_data);
 
+        freea (argv);
+
         /* Reset CLASSPATH.  */
         reset_classpath (old_classpath);
 
-        freea (argv);
-
         goto done2;
       }
   }
index ea107f48d54218f24e82ef909edca5b81704fec4..638f0f53ff9fcbdb49571ba39a1aa128b4593ee8 100644 (file)
@@ -55,27 +55,23 @@ execute_and_read_line (const char *progname,
                        void *private_data)
 {
   struct locals *l = (struct locals *) private_data;
-  pid_t child;
-  int fd[1];
-  FILE *fp;
-  char *line;
-  size_t linesize;
-  size_t linelen;
 
   /* Open a pipe to the JVM.  */
-  child = create_pipe_in (progname, prog_path, prog_argv, NULL, NULL,
-                          DEV_NULL, false, true, false, fd);
+  int fd[1];
+  pid_t child = create_pipe_in (progname, prog_path, prog_argv, NULL, NULL,
+                                DEV_NULL, false, true, false, fd);
 
   if (child == -1)
     return false;
 
   /* Retrieve its result.  */
-  fp = fdopen (fd[0], "r");
+  FILE *fp = fdopen (fd[0], "r");
   if (fp == NULL)
     error (EXIT_FAILURE, errno, _("fdopen() failed"));
 
-  line = NULL; linesize = 0;
-  linelen = getline (&line, &linesize, fp);
+  char *line = NULL;
+  size_t linesize = 0;
+  size_t linelen = getline (&line, &linesize, fp);
   if (linelen == (size_t)(-1))
     {
       error (0, 0, _("%s subprocess I/O error"), progname);
@@ -84,15 +80,13 @@ execute_and_read_line (const char *progname,
     }
   else
     {
-      int exitstatus;
-
       if (linelen > 0 && line[linelen - 1] == '\n')
         line[linelen - 1] = '\0';
 
       fclose (fp);
 
       /* Remove zombie process from process list, and retrieve exit status.  */
-      exitstatus =
+      int exitstatus =
         wait_subprocess (child, progname, true, false, true, false, NULL);
       if (exitstatus == 0)
         {
@@ -110,11 +104,13 @@ javaexec_version (void)
   const char *class_name = "javaversion";
   char *malloc_pkgdatadir;
   const char *pkgdatadir = relocate2 (PKGDATADIR, &malloc_pkgdatadir);
-  const char *args[1];
-  struct locals locals;
 
+  const char *args[1];
   args[0] = NULL;
+
+  struct locals locals;
   locals.line = NULL;
+
   execute_java_class (class_name, &pkgdatadir, 1, true, NULL, args,
                       false, false, execute_and_read_line, &locals);
 
index c4be94edf5aaf4db20f7f68aa9d3ecd6ac80d74d..637e59851f13f0ff734fa72c8b9ab9aee3316b42 100644 (file)
@@ -345,8 +345,6 @@ static void
 treefails (struct tree const *tree, struct trie const *fail,
            struct trie *recourse, bool reverse)
 {
-  struct tree *cur;
-
   if (!tree)
     return;
 
@@ -357,7 +355,7 @@ treefails (struct tree const *tree, struct trie const *fail,
      node that has a descendant on the current label.  */
   while (fail)
     {
-      cur = fail->links;
+      struct tree *cur = fail->links;
       while (cur && tree->label != cur->label)
         if (tree->label < cur->label)
           cur = cur->llink;
@@ -425,29 +423,29 @@ kwsprep (kwset_t kwset)
   char const *trans = kwset->trans;
   unsigned char deltabuf[NCHAR];
   unsigned char *delta = trans ? deltabuf : kwset->delta;
-  struct trie *curr, *last;
 
   /* Use Boyer-Moore if just one pattern, Aho-Corasick otherwise.  */
   bool reverse = kwset->words == 1;
 
   if (reverse)
     {
-      kwset_t new_kwset;
-
       /* Enqueue the immediate descendants in the level order queue.  */
-      for (curr = last = kwset->trie; curr; curr = curr->next)
-        enqueue (curr->links, &last);
+      {
+        struct trie *last;
+        for (struct trie *curr = last = kwset->trie; curr; curr = curr->next)
+          enqueue (curr->links, &last);
+      }
 
       /* Looking for just one string.  Extract it from the trie.  */
       kwset->target = obstack_alloc (&kwset->obstack, kwset->mind);
-      curr = kwset->trie;
+      struct trie *curr = kwset->trie;
       for (idx_t i = 0; i < kwset->mind; i++)
         {
           kwset->target[i] = curr->links->label;
           curr = curr->next;
         }
 
-      new_kwset = kwsalloc (kwset->trans);
+      kwset_t new_kwset = kwsalloc (kwset->trans);
       new_kwset->kwsexec = bmexec;
       kwsincr (new_kwset, kwset->target, kwset->mind);
       obstack_free (&kwset->obstack, nullptr);
@@ -462,47 +460,50 @@ kwsprep (kwset_t kwset)
 
   /* Traverse the nodes of the trie in level order, simultaneously
      computing the delta table, failure function, and shift function.  */
-  for (curr = last = kwset->trie; curr; curr = curr->next)
-    {
-      /* Enqueue the immediate descendants in the level order queue.  */
-      enqueue (curr->links, &last);
+  {
+    struct trie *last;
+    for (struct trie *curr = last = kwset->trie; curr; curr = curr->next)
+      {
+        /* Enqueue the immediate descendants in the level order queue.  */
+        enqueue (curr->links, &last);
 
-      /* Update the delta table for the descendants of this node.  */
-      treedelta (curr->links, curr->depth, delta);
+        /* Update the delta table for the descendants of this node.  */
+        treedelta (curr->links, curr->depth, delta);
 
-      /* Compute the failure function for the descendants of this node.  */
-      treefails (curr->links, curr->fail, kwset->trie, reverse);
+        /* Compute the failure function for the descendants of this node.  */
+        treefails (curr->links, curr->fail, kwset->trie, reverse);
 
-      if (reverse)
-        {
-          curr->shift = kwset->mind;
-          curr->maxshift = kwset->mind;
+        if (reverse)
+          {
+            curr->shift = kwset->mind;
+            curr->maxshift = kwset->mind;
 
-          /* Update the shifts at each node in the current node's chain
-             of fails back to the root.  */
-          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
-                 than the difference of their depths.  */
-              if (!hasevery (fail->links, curr->links))
-                if (curr->depth - fail->depth < fail->shift)
-                  fail->shift = curr->depth - fail->depth;
-
-              /* If the current node is accepting then the shift at the
-                 fail and its descendants should be no larger than the
-                 difference of their depths.  */
-              if (curr->accepting && fail->maxshift > curr->depth - fail->depth)
-                fail->maxshift = curr->depth - fail->depth;
-            }
-        }
-    }
+            /* Update the shifts at each node in the current node's chain
+               of fails back to the root.  */
+            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
+                   than the difference of their depths.  */
+                if (!hasevery (fail->links, curr->links))
+                  if (curr->depth - fail->depth < fail->shift)
+                    fail->shift = curr->depth - fail->depth;
+
+                /* If the current node is accepting then the shift at the
+                   fail and its descendants should be no larger than the
+                   difference of their depths.  */
+                if (curr->accepting && fail->maxshift > curr->depth - fail->depth)
+                  fail->maxshift = curr->depth - fail->depth;
+              }
+          }
+      }
+  }
 
   if (reverse)
     {
       /* Traverse the trie in level order again, fixing up all nodes whose
          shift exceeds their inherited maxshift.  */
-      for (curr = kwset->trie->next; curr; curr = curr->next)
+      for (struct trie *curr = kwset->trie->next; curr; curr = curr->next)
         {
           if (curr->maxshift > curr->parent->maxshift)
             curr->maxshift = curr->parent->maxshift;
@@ -513,48 +514,52 @@ kwsprep (kwset_t kwset)
 
   /* Create a vector, indexed by character code, of the outgoing links
      from the root node.  Accumulate GC1 and GC1HELP.  */
-  struct trie *nextbuf[NCHAR];
-  struct trie **next = trans ? nextbuf : kwset->next;
-  memset (next, 0, sizeof nextbuf);
-  treenext (kwset->trie->links, next);
-  int gc1 = -2;
-  int gc1help = -1;
-  for (int i = 0; i < NCHAR; i++)
-    {
-      int ti = i;
-      if (trans)
-        {
-          ti = U(trans[i]);
-          kwset->next[i] = next[ti];
-        }
-      if (kwset->next[i])
-        {
-          if (gc1 < -1)
-            {
-              gc1 = ti;
+  {
+    struct trie *nextbuf[NCHAR];
+    struct trie **next = trans ? nextbuf : kwset->next;
+    memset (next, 0, sizeof nextbuf);
+    treenext (kwset->trie->links, next);
+    int gc1 = -2;
+    int gc1help = -1;
+    for (int i = 0; i < NCHAR; i++)
+      {
+        int ti = i;
+        if (trans)
+          {
+            ti = U(trans[i]);
+            kwset->next[i] = next[ti];
+          }
+        if (kwset->next[i])
+          {
+            if (gc1 < -1)
+              {
+                gc1 = ti;
+                gc1help = i;
+              }
+            else if (gc1 == ti)
+              gc1help = gc1help == ti ? i : -1;
+            else if (i == ti && gc1 == gc1help)
               gc1help = i;
-            }
-          else if (gc1 == ti)
-            gc1help = gc1help == ti ? i : -1;
-          else if (i == ti && gc1 == gc1help)
-            gc1help = i;
-          else
-            gc1 = -1;
-        }
-    }
-  kwset->gc1 = gc1;
-  kwset->gc1help = gc1help;
+            else
+              gc1 = -1;
+          }
+      }
+    kwset->gc1 = gc1;
+    kwset->gc1help = gc1help;
+  }
 
   if (reverse)
     {
       /* Looking for just one string.  Extract it from the trie.  */
       kwset->target = obstack_alloc (&kwset->obstack, kwset->mind);
-      curr = kwset->trie;
-      for (idx_t i = kwset->mind; 0 < i; i--)
-        {
-          kwset->target[i - 1] = curr->links->label;
-          curr = curr->next;
-        }
+      {
+        struct trie *curr = kwset->trie;
+        for (idx_t i = kwset->mind; 0 < i; i--)
+          {
+            kwset->target[i - 1] = curr->links->label;
+            curr = curr->next;
+          }
+      }
 
       if (kwset->mind > 1)
         {
@@ -563,12 +568,14 @@ kwsprep (kwset_t kwset)
           kwset->shift
             = obstack_alloc (&kwset->obstack,
                              sizeof *kwset->shift * (kwset->mind - 1));
-          curr = kwset->trie->next;
-          for (idx_t i = 0; i < kwset->mind - 1; i++)
-            {
-              kwset->shift[i] = curr->shift;
-              curr = curr->next;
-            }
+          {
+            struct trie *curr = kwset->trie->next;
+            for (idx_t i = 0; i < kwset->mind - 1; i++)
+              {
+                kwset->shift[i] = curr->shift;
+                curr = curr->next;
+              }
+          }
 
           /* The penultimate byte.  */
           kwset->gc2 = tr (trans, kwset->target[kwset->mind - 2]);
@@ -669,25 +676,23 @@ static inline ptrdiff_t _GL_ATTRIBUTE_PURE
 bmexec_trans (kwset_t kwset, char const *text, idx_t size)
 {
   assume (0 <= size);
-  unsigned char const *d1;
-  char const *ep, *sp, *tp;
-  int d;
-  idx_t len = kwset->mind;
-  char const *trans = kwset->trans;
 
+  idx_t len = kwset->mind;
   if (len == 0)
     return 0;
   if (len > size)
     return -1;
   if (len == 1)
     {
-      tp = memchr_kwset (text, size, kwset);
+      char const *tp = memchr_kwset (text, size, kwset);
       return tp ? tp - text : -1;
     }
 
-  d1 = kwset->delta;
-  sp = kwset->target + len;
-  tp = text + len;
+  char const *trans = kwset->trans;
+
+  unsigned char const *d1 = kwset->delta;
+  char const *sp = kwset->target + len;
+  char const *tp = text + len;
   char gc1 = kwset->gc1;
   char gc2 = kwset->gc2;
 
@@ -695,9 +700,10 @@ bmexec_trans (kwset_t kwset, char const *text, idx_t size)
   idx_t len12;
   if (!ckd_mul (&len12, len, 12) && len12 < size)
     /* 11 is not a bug, the initial offset happens only once.  */
-    for (ep = text + size - 11 * len; tp <= ep; )
+    for (char const *ep = text + size - 11 * len; tp <= ep; )
       {
         char const *tp0 = tp;
+        int d;
         d = d1[U(tp[-1])], tp += d;
         d = d1[U(tp[-1])], tp += d;
         if (d != 0)
@@ -736,8 +742,8 @@ bmexec_trans (kwset_t kwset, char const *text, idx_t size)
 
   /* Now only a few characters are left to search.  Carefully avoid
      ever producing an out-of-bounds pointer.  */
-  ep = text + size;
-  d = d1[U(tp[-1])];
+  char const *ep = text + size;
+  int d = d1[U(tp[-1])];
   while (d <= ep - tp)
     {
       d = d1[U((tp += d)[-1])];
@@ -773,18 +779,14 @@ static inline ptrdiff_t
 acexec_trans (kwset_t kwset, char const *text, idx_t len,
               struct kwsmatch *kwsmatch, bool longest)
 {
-  struct trie const *trie, *accept;
-  char const *tp, *left, *lim;
-  struct tree const *tree;
-  char const *trans;
-
   /* Initialize register copies and look for easy ways out.  */
   if (len < kwset->mind)
     return -1;
-  trans = kwset->trans;
-  trie = kwset->trie;
-  lim = text + len;
-  tp = text;
+
+  char const *trans = kwset->trans;
+  struct trie const *trie = kwset->trie;
+  char const *lim = text + len;
+  char const *tp = text;
 
   if (!trie->accepting)
     {
@@ -816,6 +818,7 @@ acexec_trans (kwset_t kwset, char const *text, idx_t len,
                 return -1;
               c = tr (trans, *tp++);
 
+              struct tree const *tree;
               for (tree = trie->links; c != tree->label; )
                 {
                   tree = c < tree->label ? tree->llink : tree->rlink;
@@ -846,21 +849,20 @@ acexec_trans (kwset_t kwset, char const *text, idx_t len,
         }
     }
 
- match:
-  accept = trie;
+ match: ;
+  struct trie const *accept = trie;
   while (accept->accepting < 0)
     accept = accept->fail;
-  left = tp - accept->depth;
+  char const *left = tp - accept->depth;
 
   /* Try left-most longest match.  */
   if (longest)
     {
       while (tp < lim)
         {
-          struct trie const *accept1;
-          char const *left1;
           unsigned char c = tr (trans, *tp++);
 
+          struct tree const *tree;
           do
             {
               tree = trie->links;
@@ -874,10 +876,10 @@ acexec_trans (kwset_t kwset, char const *text, idx_t len,
           trie = tree->trie;
           if (trie->accepting)
             {
-              accept1 = trie;
+              struct trie const *accept1 = trie;
               while (accept1->accepting < 0)
                 accept1 = accept1->fail;
-              left1 = tp - accept1->depth;
+              char const *left1 = tp - accept1->depth;
               if (left1 <= left)
                 {
                   left = left1;
index 687922abd46251e2a617367569e2878e0b871694..ad2b2d17dfed97bc7565925230883443e41cc5e2 100644 (file)
@@ -92,12 +92,12 @@ lchown (_GL_UNUSED char const *file, _GL_UNUSED uid_t owner,
 int
 rpl_lchown (const char *file, uid_t owner, gid_t group)
 {
-  struct stat st;
   gid_t no_gid = -1;
   uid_t no_uid = -1;
   bool gid_noop = group == no_gid;
   bool uid_noop = owner == no_uid;
   bool change_time_check = CHOWN_CHANGE_TIME_BUG && !(gid_noop & uid_noop);
+  struct stat st;
 
   if (change_time_check
       || (CHOWN_TRAILING_SLASH_BUG
index 018efa7f29d9ac5043d40248a7ec80fc293e9669..88959aebdc666b0b4b475eb1e6cecea6ff25b4a8 100644 (file)
@@ -59,13 +59,13 @@ struct linebuffer *
 readlinebuffer_delim (struct linebuffer *linebuffer, FILE *stream,
                       char delimiter)
 {
-  int c;
+  if (feof (stream))
+    return NULL;
+
   char *buffer = linebuffer->buffer;
   char *p = linebuffer->buffer;
   char *end = buffer + linebuffer->size; /* Sentinel. */
-
-  if (feof (stream))
-    return NULL;
+  int c;
 
   do
     {
index b2f2132f5e92e37bd430beea8e707f9a68c056b2..0c221dbf0b361ceeef566925081b5396ebe230a4 100644 (file)
@@ -70,10 +70,6 @@ initialize (void)
 int
 link (const char *file1, const char *file2)
 {
-  char *dir;
-  size_t len1 = strlen (file1);
-  size_t len2 = strlen (file2);
-
 #  if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP)
   if (!initialized)
     initialize ();
@@ -85,29 +81,34 @@ link (const char *file1, const char *file2)
       errno = EPERM;
       return -1;
     }
+
   /* Reject trailing slashes on non-directories; native Windows does not
      support hard-linking directories.  */
-  if ((len1 && (file1[len1 - 1] == '/' || file1[len1 - 1] == '\\'))
-      || (len2 && (file2[len2 - 1] == '/' || file2[len2 - 1] == '\\')))
-    {
-      /* If stat() fails, then link() should fail for the same reason.  */
-      struct stat st;
-      if (stat (file1, &st))
-        {
-          if (errno == EOVERFLOW)
-            /* It's surely a file, not a directory (see stat-w32.c).  */
-            errno = ENOTDIR;
-          return -1;
-        }
-      if (!S_ISDIR (st.st_mode))
-        errno = ENOTDIR;
-      else
-        errno = EPERM;
-      return -1;
-    }
+  {
+    size_t len1 = strlen (file1);
+    size_t len2 = strlen (file2);
+    if ((len1 && (file1[len1 - 1] == '/' || file1[len1 - 1] == '\\'))
+        || (len2 && (file2[len2 - 1] == '/' || file2[len2 - 1] == '\\')))
+      {
+        /* If stat() fails, then link() should fail for the same reason.  */
+        struct stat st;
+        if (stat (file1, &st))
+          {
+            if (errno == EOVERFLOW)
+              /* It's surely a file, not a directory (see stat-w32.c).  */
+              errno = ENOTDIR;
+            return -1;
+          }
+        if (!S_ISDIR (st.st_mode))
+          errno = ENOTDIR;
+        else
+          errno = EPERM;
+        return -1;
+      }
+  }
   /* CreateHardLink("b/.","a",NULL) creates file "b", so we must check
      that dirname(file2) exists.  */
-  dir = strdup (file2);
+  char *dir = strdup (file2);
   if (!dir)
     return -1;
   {
@@ -182,8 +183,6 @@ link (const char *file1, const char *file2)
 int
 rpl_link (char const *file1, char const *file2)
 {
-  size_t len1;
-  size_t len2;
   struct stat st;
 
   /* Don't allow IRIX to dereference dangling file2 symlink.  */
@@ -194,8 +193,8 @@ rpl_link (char const *file1, char const *file2)
     }
 
   /* Reject trailing slashes on non-directories.  */
-  len1 = strlen (file1);
-  len2 = strlen (file2);
+  size_t len1 = strlen (file1);
+  size_t len2 = strlen (file2);
   if ((len1 && file1[len1 - 1] == '/')
       || (len2 && file2[len2 - 1] == '/'))
     {
@@ -215,12 +214,11 @@ rpl_link (char const *file1, char const *file2)
     {
       /* Fix Cygwin 1.5.x bug where link("a","b/.") creates file "b".  */
       char *dir = strdup (file2);
-      char *p;
       if (!dir)
         return -1;
       /* We already know file2 does not end in slash.  Strip off the
          basename, then check that the dirname exists.  */
-      p = strrchr (dir, '/');
+      char *p = strrchr (dir, '/');
       if (p)
         {
           *p = '\0';
index d1d789b73e74b74ae6bd0152a9576395f63b296d..c9d806af5929e0d0b9933144d31e95b1a00751c2 100644 (file)
@@ -50,8 +50,6 @@ link_immediate (char const *file1, char const *file2)
          an identical symlink behaves like a hard link to a symlink,
          except for incorrect st_ino and st_nlink.  However, we must
          be careful of EXDEV.  */
-      struct stat st1;
-      struct stat st2;
       char *dir = mdir_name (file2);
       if (!dir)
         {
@@ -59,6 +57,8 @@ link_immediate (char const *file1, char const *file2)
           errno = ENOMEM;
           return -1;
         }
+      struct stat st1;
+      struct stat st2;
       if (lstat (file1, &st1) == 0 && stat (dir, &st2) == 0)
         {
           if (st1.st_dev == st2.st_dev)
@@ -92,7 +92,6 @@ link_follow (char const *file1, char const *file2)
 {
   char *name = (char *) file1;
   char *target;
-  int result;
   int i = __eloop_threshold ();
 
   /* Using realpath or canonicalize_file_name is too heavy-handed: we
@@ -138,7 +137,7 @@ link_follow (char const *file1, char const *file2)
         free (name);
       return -1;
     }
-  result = link (name, file2);
+  int result = link (name, file2);
   if (name != file1)
     free (name);
   return result;
@@ -210,7 +209,6 @@ linkat_follow (int fd1, char const *file1, int fd2, char const *file2)
 {
   char *name = (char *) file1;
   char *target;
-  int result;
   int i = __eloop_threshold ();
 
   /* There is no realpathat.  */
@@ -254,7 +252,7 @@ linkat_follow (int fd1, char const *file1, int fd2, char const *file2)
         free (name);
       return -1;
     }
-  result = linkat (fd1, name, fd2, file2, 0);
+  int result = linkat (fd1, name, fd2, file2, 0);
   if (name != file1)
     free (name);
   return result;
index 79a55c5efda0d64d2a1c6cb14c365eb6d4539a1b..b2b90d5f869134626d2ce87050a5c1dee81933e0 100644 (file)
@@ -813,10 +813,9 @@ locale_charset (void)
      environment variables (if present) or the codepage as a number.  */
   if (codeset != NULL && streq (codeset, "US-ASCII"))
     {
-      const char *locale;
       static char resultbuf[2 + 10 + 1];
 
-      locale = getenv ("LC_ALL");
+      const char *locale = getenv ("LC_ALL");
       if (locale == NULL || locale[0] == '\0')
         {
           locale = getenv ("LC_CTYPE");
@@ -912,16 +911,13 @@ locale_charset (void)
 
 # elif defined OS2
 
-  const char *locale;
   static char resultbuf[2 + 10 + 1];
-  ULONG cp[3];
-  ULONG cplen;
 
   codeset = NULL;
 
   /* Allow user to override the codeset, as set in the operating system,
      with standard language environment variables.  */
-  locale = getenv ("LC_ALL");
+  const char *locale = getenv ("LC_ALL");
   if (locale == NULL || locale[0] == '\0')
     {
       locale = getenv ("LC_CTYPE");
@@ -958,6 +954,9 @@ locale_charset (void)
 
   if (codeset == NULL)
     {
+      ULONG cp[3];
+      ULONG cplen;
+
       /* OS/2 has a function returning the locale's codepage as a number.  */
       if (DosQueryCp (sizeof (cp), cp, &cplen))
         codeset = "";
index 5123168527430dd82ded8f8aed52123c48e194a9..f27899f48f0eb6f1563a2589a8eebd5db6322574 100644 (file)
@@ -46,9 +46,9 @@ static_assert (MB_LEN_MAX <= SCHAR_MAX);
 static bool
 is_using_utf8 (void)
 {
+  mbstate_t state; mbszero (&state);
   char32_t wc;
-  mbstate_t mbs; mbszero (&mbs);
-  return mbrtoc32 (&wc, "\xc4\x80", 2, &mbs) == 2 && wc == 0x100;
+  return mbrtoc32 (&wc, "\xc4\x80", 2, &state) == 2 && wc == 0x100;
 }
 
 /* Return true if the locale is compatible enough with the C locale so
@@ -103,9 +103,9 @@ init_localeinfo (struct localeinfo *localeinfo)
     {
       char c = i;
       unsigned char uc = i;
-      mbstate_t s; mbszero (&s);
+      mbstate_t state; mbszero (&state);
       char32_t wc;
-      size_t len = mbrtoc32 (&wc, &c, 1, &s);
+      size_t len = mbrtoc32 (&wc, &c, 1, &state);
       localeinfo->sbclen[uc] = len <= 1 ? 1 : - (int) - len;
       localeinfo->sbctowc[uc] = len <= 1 ? wc : WEOF;
     }
index 0d35d6bbde0a516ba4a96b68b89b462e1eb65df3..a2048dfb01abd2a6cbc1daacd9fe7cf1d5063e78 100644 (file)
 const char *
 gl_locale_name_environ (_GL_UNUSED int category, const char *categoryname)
 {
-  const char *retval;
-
   /* Setting of LC_ALL overrides all other.  */
-  retval = getenv ("LC_ALL");
-  if (retval != NULL && retval[0] != '\0')
-    return retval;
+  {
+    const char *retval = getenv ("LC_ALL");
+    if (retval != NULL && retval[0] != '\0')
+      return retval;
+  }
   /* Next comes the name of the desired category.  */
-  retval = getenv (categoryname);
-  if (retval != NULL && retval[0] != '\0')
-    return retval;
+  {
+    const char *retval = getenv (categoryname);
+    if (retval != NULL && retval[0] != '\0')
+      return retval;
+  }
   /* Last possibility is the LANG environment variable.  */
-  retval = getenv ("LANG");
-  if (retval != NULL && retval[0] != '\0')
-    {
+  {
+    const char *retval = getenv ("LANG");
+    if (retval != NULL && retval[0] != '\0')
+      {
 #if HAVE_CFPREFERENCESCOPYAPPVALUE
-      /* Mac OS X 10.2 or newer.
-         Ignore invalid LANG value set by the Terminal application.  */
-      if (!streq (retval, "UTF-8"))
+        /* Mac OS X 10.2 or newer.
+           Ignore invalid LANG value set by the Terminal application.  */
+        if (!streq (retval, "UTF-8"))
 #endif
 #if defined __CYGWIN__
-      /* Cygwin.
-         Ignore dummy LANG value set by ~/.profile.  */
-       if (!streq (retval, "C.UTF-8"))
+        /* Cygwin.
+           Ignore dummy LANG value set by ~/.profile.  */
+         if (!streq (retval, "C.UTF-8"))
 #endif
-        return retval;
-    }
+          return retval;
+      }
+  }
 
   return NULL;
 }
index 3163a5c713632fdff14d8589b69e88e61556a0f9..9177b6939dcf8fe2f52cb76ce03f0c9715998e26 100644 (file)
@@ -1387,45 +1387,50 @@ gl_locale_name_canonicalize (char *name)
   /* Step 2: Convert using langtag_table and script_table.  */
   if (strlen (name) == 7 && name[2] == '-')
     {
-      unsigned int i1, i2;
-      i1 = 0;
-      i2 = sizeof (langtag_table) / sizeof (langtag_entry);
-      while (i2 - i1 > 1)
-        {
-          /* At this point we know that if name occurs in langtag_table,
-             its index must be >= i1 and < i2.  */
-          unsigned int i = (i1 + i2) >> 1;
-          const langtag_entry *p = &langtag_table[i];
-          if (strcmp (name, p->langtag) < 0)
-            i2 = i;
-          else
-            i1 = i;
-        }
-      if (streq (name, langtag_table[i1].langtag))
-        {
-          strcpy (name, langtag_table[i1].unixy);
-          return;
-        }
+      {
+        unsigned int i1, i2;
+        i1 = 0;
+        i2 = sizeof (langtag_table) / sizeof (langtag_entry);
+        while (i2 - i1 > 1)
+          {
+            /* At this point we know that if name occurs in langtag_table,
+               its index must be >= i1 and < i2.  */
+            unsigned int i = (i1 + i2) >> 1;
+            const langtag_entry *p = &langtag_table[i];
+            if (strcmp (name, p->langtag) < 0)
+              i2 = i;
+            else
+              i1 = i;
+          }
+        if (streq (name, langtag_table[i1].langtag))
+          {
+            strcpy (name, langtag_table[i1].unixy);
+            return;
+          }
+      }
 
-      i1 = 0;
-      i2 = sizeof (script_table) / sizeof (script_entry);
-      while (i2 - i1 > 1)
-        {
-          /* At this point we know that if (name + 3) occurs in script_table,
-             its index must be >= i1 and < i2.  */
-          unsigned int i = (i1 + i2) >> 1;
-          const script_entry *p = &script_table[i];
-          if (strcmp (name + 3, p->script) < 0)
-            i2 = i;
-          else
-            i1 = i;
-        }
-      if (streq (name + 3, script_table[i1].script))
-        {
-          name[2] = '@';
-          strcpy (name + 3, script_table[i1].unixy);
-          return;
-        }
+      {
+        unsigned int i1, i2;
+        i1 = 0;
+        i2 = sizeof (script_table) / sizeof (script_entry);
+        while (i2 - i1 > 1)
+          {
+            /* At this point we know that if (name + 3) occurs in script_table,
+               its index must be >= i1 and < i2.  */
+            unsigned int i = (i1 + i2) >> 1;
+            const script_entry *p = &script_table[i];
+            if (strcmp (name + 3, p->script) < 0)
+              i2 = i;
+            else
+              i1 = i;
+          }
+        if (streq (name + 3, script_table[i1].script))
+          {
+            name[2] = '@';
+            strcpy (name + 3, script_table[i1].unixy);
+            return;
+          }
+      }
     }
 
   /* Step 3: Convert new-style dash to Unix underscore. */
@@ -1508,11 +1513,9 @@ gl_locale_name_from_win32_LANGID (LANGID langid)
   #define N(name)           (is_utf8 ? name ".UTF-8" : name)
   #define NM(name,modifier) (is_utf8 ? name ".UTF-8" modifier : name modifier)
   {
-    int primary, sub;
-
     /* Split into language and territory part.  */
-    primary = PRIMARYLANGID (langid);
-    sub = SUBLANGID (langid);
+    int primary = PRIMARYLANGID (langid);
+    int sub = SUBLANGID (langid);
 
     /* Dispatch on language.
        See also https://www.unicode.org/unicode/onlinedat/languages.html .
@@ -2529,10 +2532,8 @@ static
 const char *
 gl_locale_name_from_win32_LCID (LCID lcid)
 {
-  LANGID langid;
-
   /* Strip off the sorting rules, keep only the language part.  */
-  langid = LANGIDFROMLCID (lcid);
+  LANGID langid = LANGIDFROMLCID (lcid);
 
   return gl_locale_name_from_win32_LANGID (langid);
 }
@@ -2549,11 +2550,11 @@ static BOOL CALLBACK
 enum_locales_fn (LPSTR locale_num_str)
 {
   char *endp;
-  char locval[2 * LOCALE_NAME_MAX_LENGTH + 1 + 1];
   LCID try_lcid = strtoul (locale_num_str, &endp, 16);
 
+  char locval[2 * LOCALE_NAME_MAX_LENGTH + 1 + 1];
   if (GetLocaleInfo (try_lcid, LOCALE_SENGLANGUAGE,
-                    locval, LOCALE_NAME_MAX_LENGTH))
+                     locval, LOCALE_NAME_MAX_LENGTH))
     {
       strcat (locval, "_");
       if (GetLocaleInfo (try_lcid, LOCALE_SENGCOUNTRY,
@@ -2846,19 +2847,21 @@ gl_locale_name_default (void)
 const char *
 gl_locale_name_unsafe (int category, const char *categoryname)
 {
-  const char *retval;
-
   if (category == LC_ALL)
     /* Invalid argument.  */
     abort ();
 
-  retval = gl_locale_name_thread_unsafe (category, categoryname);
-  if (retval != NULL)
-    return retval;
+  {
+    const char *retval = gl_locale_name_thread_unsafe (category, categoryname);
+    if (retval != NULL)
+      return retval;
+  }
 
-  retval = gl_locale_name_posix_unsafe (category, categoryname);
-  if (retval != NULL)
-    return retval;
+  {
+    const char *retval = gl_locale_name_posix_unsafe (category, categoryname);
+    if (retval != NULL)
+      return retval;
+  }
 
   return gl_locale_name_default ();
 }
index 2590410f27388144c52d1fc13451a12def680d9f..a1cf9cb7143eb9bae50b8b250c5d2e0fb3b345ee 100644 (file)
@@ -71,19 +71,21 @@ gl_locale_name_posix (int category, const char *categoryname)
 const char *
 gl_locale_name (int category, const char *categoryname)
 {
-  const char *retval;
-
   if (category == LC_ALL)
     /* Invalid argument.  */
     abort ();
 
-  retval = gl_locale_name_thread (category, categoryname);
-  if (retval != NULL)
-    return retval;
-
-  retval = gl_locale_name_posix (category, categoryname);
-  if (retval != NULL)
-    return retval;
+  {
+    const char *retval = gl_locale_name_thread (category, categoryname);
+    if (retval != NULL)
+      return retval;
+  }
+
+  {
+    const char *retval = gl_locale_name_posix (category, categoryname);
+    if (retval != NULL)
+      return retval;
+  }
 
   return gl_locale_name_default ();
 }
index 92d993e8d9259bb6555adaa58ee9557cc9eaeaee..2a8d2760229902e13734aa0f1e557ad1a4649507 100644 (file)
@@ -59,9 +59,7 @@ log2 (double x)
      Then log2(x) = e + log2(y) = e + log(y)/log(2).  */
   {
     int e;
-    double y;
-
-    y = frexp (x, &e);
+    double y = frexp (x, &e);
     if (y < SQRT_HALF)
       {
         y = 2.0 * y;
index 0ec7024937b98eb1952c0d6867fdfe36d3a96bac..228768cfbe11e8fa2adef40e825f328b61d7831d 100644 (file)
@@ -69,9 +69,7 @@ log2f (float x)
      Then log2(x) = e + log2(y) = e + log(y)/log(2).  */
   {
     int e;
-    float y;
-
-    y = frexpf (x, &e);
+    float y = frexpf (x, &e);
     if (y < SQRT_HALF)
       {
         y = 2.0f * y;
index 4242d4fff527d99a253110a8a85b11362ec62780..14971bfce62e048b8c48b4260fcc64049ff1958a 100644 (file)
@@ -69,9 +69,7 @@ log2l (long double x)
      Then log2(x) = e + log2(y) = e + log(y)/log(2).  */
   {
     int e;
-    long double y;
-
-    y = frexpl (x, &e);
+    long double y = frexpl (x, &e);
     if (y < SQRT_HALF)
       {
         y = 2.0L * y;
index f7926171f691b61df24e41b5e6c3135b56d4aee9..96b689d3ca3bc69a551814c8c9569350d4d3f50c 100644 (file)
@@ -48,13 +48,10 @@ login_tty (int slave_fd)
     return -1;
 #else
   {
-    char *slave_name;
-    int dummy_fd;
-
-    slave_name = ttyname (slave_fd);
+    char *slave_name = ttyname (slave_fd);
     if (slave_name == NULL)
       return -1;
-    dummy_fd = open (slave_name, O_RDWR | O_CLOEXEC);
+    int dummy_fd = open (slave_name, O_RDWR | O_CLOEXEC);
     if (dummy_fd < 0)
       return -1;
     close (dummy_fd);
index a8cb1e7b41e49f6fc2c835851fea07c3a42d530c..a0a7d2dada088618d61500cbb1d6433205664fcd 100644 (file)
@@ -199,10 +199,6 @@ static const long double
 long double
 logl (long double x)
 {
-  long double z, y, w;
-  long double t;
-  int k, e;
-
   /* Check for IEEE special cases.  */
 
   /* log(NaN) = NaN. */
@@ -227,6 +223,7 @@ logl (long double x)
     }
 
   /* Extract exponent and reduce domain to 0.703125 <= u < 1.40625  */
+  int e;
   x = frexpl (x, &e);
   if (x < 0.703125L)
     {
@@ -235,6 +232,9 @@ logl (long double x)
     }
 
   /* On this interval the table is not used due to cancellation error.  */
+  long double z;
+  int k;
+  long double t;
   if ((x <= 1.0078125L) && (x >= 0.9921875L))
     {
       z = x - 1.0L;
@@ -249,20 +249,20 @@ logl (long double x)
     }
 
   /* Series expansion of log(1+z).  */
-  w = z * z;
-  y = ((((((((((((l15 * z
-                  + l14) * z
-                 + l13) * z
-                + l12) * z
-               + l11) * z
-              + l10) * z
-             + l9) * z
-            + l8) * z
-           + l7) * z
-          + l6) * z
-         + l5) * z
-        + l4) * z
-       + l3) * z * w;
+  long double w = z * z;
+  long double y = ((((((((((((l15 * z
+                              + l14) * z
+                             + l13) * z
+                            + l12) * z
+                           + l11) * z
+                          + l10) * z
+                         + l9) * z
+                        + l8) * z
+                       + l7) * z
+                      + l6) * z
+                     + l5) * z
+                    + l4) * z
+                   + l3) * z * w;
   y -= 0.5 * w;
   y += e * ln2b;  /* Base 2 exponent offset times ln(2).  */
   y += z;
index 3ceacd009dc5e2422722229f6556ae699b7f29bc..e89e95919b3cf6a702db252b1b1cae4c1538f8db 100644 (file)
@@ -50,34 +50,34 @@ parse_long_options (int argc,
                     void (*usage_func) (int),
                     /* const char *author1, ...*/ ...)
 {
-  int c;
-  int saved_opterr;
-
-  saved_opterr = opterr;
+  int saved_opterr = opterr;
 
   /* Don't print an error message for unrecognized options.  */
   opterr = 0;
 
-  if (argc == 2
-      && (c = getopt_long (argc, argv, "+", long_options, NULL)) != -1)
+  if (argc == 2)
     {
-      switch (c)
+      int c = getopt_long (argc, argv, "+", long_options, NULL);
+      if (c != -1)
         {
-        case 'h':
-          (*usage_func) (EXIT_SUCCESS);
-          break;
-
-        case 'v':
-          {
-            va_list authors;
-            va_start (authors, usage_func);
-            version_etc_va (stdout, command_name, package, version, authors);
-            exit (EXIT_SUCCESS);
-          }
-
-        default:
-          /* Don't process any other long-named options.  */
-          break;
+          switch (c)
+            {
+            case 'h':
+              (*usage_func) (EXIT_SUCCESS);
+              break;
+
+            case 'v':
+              {
+                va_list authors;
+                va_start (authors, usage_func);
+                version_etc_va (stdout, command_name, package, version, authors);
+                exit (EXIT_SUCCESS);
+              }
+
+            default:
+              /* Don't process any other long-named options.  */
+              break;
+            }
         }
     }
 
@@ -104,7 +104,6 @@ parse_gnu_standard_options_only (int argc,
                                  void (*usage_func) (int),
                                  /* const char *author1, ...*/ ...)
 {
-  int c;
   int saved_opterr = opterr;
 
   /* Print an error message for unrecognized options.  */
@@ -112,7 +111,8 @@ parse_gnu_standard_options_only (int argc,
 
   const char *optstring = scan_all ? "" : "+";
 
-  if ((c = getopt_long (argc, argv, optstring, long_options, NULL)) != -1)
+  int c = getopt_long (argc, argv, optstring, long_options, NULL);
+  if (c != -1)
     {
       switch (c)
         {
index c852f319b4fe30d323457b388322f9f4e6b0f8d4..ce2567a2eaa9898c3f95de5853aea173656d266e 100644 (file)
@@ -86,9 +86,6 @@ struct mbfile_multi {
 MBFILE_INLINE void
 mbfile_multi_getc (struct mbchar *mbc, struct mbfile_multi *mbf)
 {
-  unsigned int new_bufcount;
-  size_t bytes;
-
   /* Return character pushed back, if there is one.  */
   if (mbf->pushback_count > 0)
     {
@@ -102,7 +99,7 @@ mbfile_multi_getc (struct mbchar *mbc, struct mbfile_multi *mbf)
   if (mbf->eof_seen)
     goto eof;
 
-  new_bufcount = mbf->bufcount;
+  unsigned int new_bufcount = mbf->bufcount;
 
   /* If mbf->state is not in an initial state, some more 32-bit wide character
      may be hiding in the state.  We need to call mbrtoc32 again.  */
@@ -146,6 +143,7 @@ mbfile_multi_getc (struct mbchar *mbc, struct mbfile_multi *mbf)
   /* Use mbrtoc32 on an increasing number of bytes.  Read only as many bytes
      from mbf->fp as needed.  This is needed to give reasonable interactive
      behaviour when mbf->fp is connected to an interactive tty.  */
+  size_t bytes;
   for (;;)
     {
       /* Feed the bytes one by one into mbrtoc32.  */
index 2401902a3fd05201f8fb14def63877bddaea48f2..58d2c91d4ba5220c4681ff8862ab2d8532c600d8 100644 (file)
@@ -44,20 +44,16 @@ apply_c32tolower (const char *inbuf, size_t inbufsize,
                   char *outbuf, size_t outbufsize)
 {
   char *outbuf_orig = outbuf;
-  size_t remaining;
-
-  remaining = inbufsize;
+  size_t remaining = inbufsize;
   while (remaining > 0)
     {
       mbstate_t state;
-
       mbszero (&state);
+
       for (;;)
         {
           char32_t wc1;
-          size_t n1;
-
-          n1 = mbrtoc32 (&wc1, inbuf, remaining, &state);
+          size_t n1 = mbrtoc32 (&wc1, inbuf, remaining, &state);
 
           if (n1 == (size_t)(-1))
             {
@@ -80,8 +76,6 @@ apply_c32tolower (const char *inbuf, size_t inbufsize,
             }
           else
             {
-              wint_t wc2;
-
               if (n1 == 0) /* NUL character? */
                 n1 = 1;
               #if !GNULIB_MBRTOC32_REGULAR
@@ -89,14 +83,13 @@ apply_c32tolower (const char *inbuf, size_t inbufsize,
                 n1 = 0;
               #endif
 
-              wc2 = c32tolower (wc1);
+              wint_t wc2 = c32tolower (wc1);
               if (wc2 != wc1)
                 {
                   mbstate_t state2;
-                  size_t n2;
-
                   mbszero (&state2);
-                  n2 = c32rtomb (outbuf, wc2, &state2);
+
+                  size_t n2 = c32rtomb (outbuf, wc2, &state2);
                   if (n2 != (size_t)(-1))
                     {
                       /* Store the translated multibyte character.  */
@@ -148,8 +141,6 @@ mbmemcasecoll (const char *s1, size_t s1len, const char *s2, size_t s2len,
   size_t t1len;
   char *t2;
   size_t t2len;
-  char *memory;
-  int cmp;
 
   if (MB_CUR_MAX > 1)
     {
@@ -165,7 +156,7 @@ mbmemcasecoll (const char *s1, size_t s1len, const char *s2, size_t s2len,
       t2len = s2len;
     }
   /* Allocate memory for t1 and t2.  */
-  memory = (char *) malloca (t1len + 1 + t2len + 1);
+  char *memory = (char *) malloca (t1len + 1 + t2len + 1);
   if (memory == NULL)
     {
       errno = ENOMEM;
@@ -187,6 +178,7 @@ mbmemcasecoll (const char *s1, size_t s1len, const char *s2, size_t s2len,
     }
 
   /* Compare the two case-folded strings.  */
+  int cmp;
   if (hard_LC_COLLATE)
     cmp = memcoll (t1, t1len, t2, t2len);
   else
index dd6e46cffcbe28751417546f8d2474d379b62694..9ec43216a241b98b501b28ddd957f1ac6e78bec5 100644 (file)
@@ -165,7 +165,6 @@ mbrtoc32 (char32_t *pwc, const char *s, size_t n, mbstate_t *ps)
       char buf[4];
       const char *p;
       size_t m;
-      int res;
 
       switch (nstate)
         {
@@ -198,6 +197,7 @@ mbrtoc32 (char32_t *pwc, const char *s, size_t n, mbstate_t *ps)
 
       /* Here m > 0.  */
 
+      int res;
       {
 #  define FITS_IN_CHAR_TYPE(wc)  1
 #  include "mbrtowc-impl-utf8.h"
index 61be6599cc0efda720038691245a5676109ff5fb..21f6237415e8c71546f6e3a44606ca564334c05c 100644 (file)
@@ -41,8 +41,6 @@
     char buf[4];
     const char *p;
     size_t m;
-    enc_t enc;
-    int res;
 
     switch (nstate)
       {
@@ -75,7 +73,8 @@
 
     /* Here m > 0.  */
 
-    enc = locale_encoding_classification ();
+    enc_t enc = locale_encoding_classification ();
+    int res;
 
     if (enc == enc_utf8) /* UTF-8 */
       {
       {
         /* The hidden internal state of mbtowc would make this function not
            multi-thread safe.  Achieve multi-thread safety through a lock.  */
-        wchar_t wc;
-        res = mbtowc_with_lock (&wc, p, m);
+        {
+          wchar_t wc;
+          res = mbtowc_with_lock (&wc, p, m);
 
-        if (res >= 0)
-          {
-            if ((wc == 0) != (res == 0))
-              abort ();
-            if (pwc != NULL)
-              *pwc = wc;
-            goto success;
-          }
+          if (res >= 0)
+            {
+              if ((wc == 0) != (res == 0))
+                abort ();
+              if (pwc != NULL)
+                *pwc = wc;
+              goto success;
+            }
+        }
 
         /* mbtowc does not distinguish between invalid and incomplete multibyte
            sequences.  But mbrtowc needs to make this distinction.
index 3043204929d0d0690f0e3946c59d8e5d7fb1b6fa..830a802af937523d6fc242047ff308099ea81b96 100644 (file)
@@ -81,9 +81,6 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
 size_t
 rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
 {
-  size_t ret;
-  wchar_t wc;
-
 # if MBRTOWC_RETVAL_BUG || MBRTOWC_EMPTY_INPUT_BUG
   if (s == NULL)
     {
@@ -98,6 +95,7 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
     return (size_t) -2;
 # endif
 
+  wchar_t wc;
   if (! pwc)
     pwc = &wc;
 
@@ -116,7 +114,7 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
         size_t count = 0;
         for (; n > 0; s++, n--)
           {
-            ret = mbrtowc (&wc, s, 1, ps);
+            size_t ret = mbrtowc (&wc, s, 1, ps);
 
             if (ret == (size_t)(-1))
               return (size_t)(-1);
@@ -133,6 +131,7 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
   }
 # endif
 
+  size_t ret;
 # if MBRTOWC_STORES_INCOMPLETE_BUG
   ret = mbrtowc (&wc, s, n, ps);
   if (ret < (size_t) -2 && pwc != NULL)
index 7c43e5eb79dfea48fdcf1145f2cb219d19546ccd..2f1d5da7573b6c5ff832978d64b669337959b4b5 100644 (file)
@@ -60,11 +60,10 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle,
   /* Allocate room for needle_mbchars and the table.  */
   void *memory = nmalloca (m + !!extra_align,
                            sizeof (mbchar_t) + sizeof (size_t));
-  void *table_memory;
   if (memory == NULL)
     return false;
   needle_mbchars = memory;
-  table_memory = needle_mbchars + m;
+  void *table_memory = needle_mbchars + m;
   char *aligned = table_memory;
   aligned += extra_align;
   aligned -= (uintptr_t) aligned % alignof (size_t);
@@ -80,9 +79,7 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle,
 #else
   {
     mbui_iterator_t iter;
-    size_t j;
-
-    j = 0;
+    size_t j = 0;
     for (mbui_init (iter, needle); mbui_avail (iter); mbui_advance (iter), j++)
       {
         mb_copy (&needle_mbchars[j], &mbui_cur (iter));
@@ -162,11 +159,10 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle,
   /* Search, using the table to accelerate the processing.  */
   {
 #if GNULIB_MCEL_PREFER
-    size_t j;
     char const *rhaystack = haystack;
     char const *phaystack = haystack;
 
-    j = 0;
+    size_t j = 0;
     /* Invariant: phaystack = rhaystack + j.  */
     for (;;)
       {
@@ -202,19 +198,16 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle,
       }
     *resultp = rhaystack;
 #else
-    size_t j;
-    mbui_iterator_t rhaystack;
-    mbui_iterator_t phaystack;
-
     *resultp = NULL;
-    j = 0;
+    size_t j = 0;
+    mbui_iterator_t rhaystack;
     mbui_init (rhaystack, haystack);
+    mbui_iterator_t phaystack;
     mbui_init (phaystack, haystack);
     /* Invariant: phaystack = rhaystack + j.  */
     while (mbui_avail (phaystack))
       {
         mbchar_t c;
-
         mb_copy (&c, &mbui_cur (phaystack));
         if (c.wc_valid)
           c.wc = c32tolower (c.wc);
@@ -356,7 +349,6 @@ mbscasestr (const char *haystack, const char *needle)
       return NULL;
 #else
       mbui_iterator_t iter_needle;
-
       mbui_init (iter_needle, needle);
       if (mbui_avail (iter_needle))
         {
@@ -380,20 +372,17 @@ mbscasestr (const char *haystack, const char *needle)
           size_t last_ccount = 0;                  /* last comparison count */
           mbui_iterator_t iter_needle_last_ccount; /* = needle + last_ccount */
 
-          mbchar_t b;
-          mbui_iterator_t iter_haystack;
-
           mbui_init (iter_needle_last_ccount, needle);
 
+          mbchar_t b;
           mb_copy (&b, &mbui_cur (iter_needle));
           if (b.wc_valid)
             b.wc = c32tolower (b.wc);
 
+          mbui_iterator_t iter_haystack;
           mbui_init (iter_haystack, haystack);
           for (;; mbui_advance (iter_haystack))
             {
-              mbchar_t c;
-
               if (!mbui_avail (iter_haystack))
                 /* No match.  */
                 return NULL;
@@ -427,6 +416,7 @@ mbscasestr (const char *haystack, const char *needle)
 
               outer_loop_count++;
               comparison_count++;
+              mbchar_t c;
               mb_copy (&c, &mbui_cur (iter_haystack));
               if (c.wc_valid)
                 c.wc = c32tolower (c.wc);
@@ -434,11 +424,10 @@ mbscasestr (const char *haystack, const char *needle)
                 /* The first character matches.  */
                 {
                   mbui_iterator_t rhaystack;
-                  mbui_iterator_t rneedle;
-
                   memcpy (&rhaystack, &iter_haystack, sizeof (mbui_iterator_t));
                   mbui_advance (rhaystack);
 
+                  mbui_iterator_t rneedle;
                   mbui_init (rneedle, needle);
                   if (!mbui_avail (rneedle))
                     abort ();
index 70e0773a79a452153ea5eeb40c3d8c960ca54176..012f2d66ca872676a580bccb5d9f5a68a70af261 100644 (file)
@@ -47,23 +47,24 @@ mbscspn (const char *string, const char *accept)
   if (MB_CUR_MAX > 1)
     {
 #if GNULIB_MCEL_PREFER
-      mcel_t a, g;
       size_t i;
-      for (i = 0; string[i]; i += g.len)
+      for (i = 0; string[i]; )
         {
-          g = mcel_scanz (string + i);
+          mcel_t g = mcel_scanz (string + i);
           if (g.len == 1)
             {
               if (mbschr (accept, string[i]))
                 return i;
             }
           else
-            for (char const *aiter = accept; *aiter; aiter += a.len)
+            for (char const *aiter = accept; *aiter; )
               {
-                a = mcel_scanz (aiter);
+                mcel_t a = mcel_scanz (aiter);
                 if (mcel_eq (g, a))
                   return i;
+                aiter += a.len;
               }
+          i += g.len;
         }
       return i;
 #else
index e1e8f4a9dd795e09b2ef2187223faec9bfbea192..4f6009cafa1f838debdb4bac61ebcacd88cce397 100644 (file)
@@ -30,7 +30,6 @@ FUNC (DCHAR_T *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps
         for (; srclen > 0 && len > 0; destptr++, len--)
           {
             size_t src_avail;
-            size_t ret;
 
             /* An optimized variant of
                src_avail = strnlen1 (src, MIN (srclen, MB_LEN_MAX));  */
@@ -46,7 +45,7 @@ FUNC (DCHAR_T *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps
               src_avail = 4 + strnlen1 (src + 4, MIN (srclen, MB_LEN_MAX) - 4);
 
             /* Parse the next multibyte character.  */
-            ret = MBRTOWC (destptr, src, src_avail, ps);
+            size_t ret = MBRTOWC (destptr, src, src_avail, ps);
 
             if (ret == (size_t)(-2))
               /* Encountered a multibyte character that extends past a '\0' byte
@@ -81,7 +80,6 @@ FUNC (DCHAR_T *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps
         for (; srclen > 0; totalcount++)
           {
             size_t src_avail;
-            size_t ret;
 
             /* An optimized variant of
                src_avail = strnlen1 (src, MIN (srclen, MB_LEN_MAX));  */
@@ -97,7 +95,7 @@ FUNC (DCHAR_T *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps
               src_avail = 4 + strnlen1 (src + 4, MIN (srclen, MB_LEN_MAX) - 4);
 
             /* Parse the next multibyte character.  */
-            ret = MBRTOWC (NULL, src, src_avail, &state);
+            size_t ret = MBRTOWC (NULL, src, src_avail, &state);
 
             if (ret == (size_t)(-2))
               /* Encountered a multibyte character that extends past a '\0' byte
index 31db68f18dcc656155f117a406bec428bde350db..2715c7ee87ea088da5ac172f19cb115f2132e4b4 100644 (file)
@@ -44,22 +44,23 @@ mbspbrk (const char *string, const char *accept)
     {
       char const *iter = string;
 #if GNULIB_MCEL_PREFER
-      mcel_t a, g;
-      for (; *iter; iter += g.len)
+      for (; *iter; )
         {
-          g = mcel_scanz (iter);
+          mcel_t g = mcel_scanz (iter);
           if (g.len == 1)
             {
               if (mbschr (accept, *iter))
                 return (char *) iter;
             }
           else
-            for (char const *aiter = accept; *aiter; aiter += a.len)
+            for (char const *aiter = accept; *aiter; )
               {
-                a = mcel_scanz (aiter);
+                mcel_t a = mcel_scanz (aiter);
                 if (mcel_eq (a, g))
                   return (char *) iter;
+                aiter += a.len;
               }
+          iter += g.len;
         }
 #else
       mbuif_state_t state;
index 044c786f2f52a222e41abacfa6ee4e6a9aea6b2d..7247b82bc24508a2ec12a444cfedd85c4bf5b436 100644 (file)
@@ -30,7 +30,6 @@ FUNC (DCHAR_T *dest, const char **srcp, size_t len, mbstate_t *ps)
         for (; len > 0; destptr++, len--)
           {
             size_t src_avail;
-            size_t ret;
 
             /* An optimized variant of
                src_avail = strnlen1 (src, MB_LEN_MAX);  */
@@ -46,7 +45,7 @@ FUNC (DCHAR_T *dest, const char **srcp, size_t len, mbstate_t *ps)
               src_avail = 4 + strnlen1 (src + 4, MB_LEN_MAX - 4);
 
             /* Parse the next multibyte character.  */
-            ret = MBRTOWC (destptr, src, src_avail, ps);
+            size_t ret = MBRTOWC (destptr, src, src_avail, ps);
 
             if (ret == (size_t)(-2))
               /* Encountered a multibyte character that extends past a '\0' byte
@@ -78,7 +77,6 @@ FUNC (DCHAR_T *dest, const char **srcp, size_t len, mbstate_t *ps)
         for (;; totalcount++)
           {
             size_t src_avail;
-            size_t ret;
 
             /* An optimized variant of
                src_avail = strnlen1 (src, MB_LEN_MAX);  */
@@ -94,7 +92,7 @@ FUNC (DCHAR_T *dest, const char **srcp, size_t len, mbstate_t *ps)
               src_avail = 4 + strnlen1 (src + 4, MB_LEN_MAX - 4);
 
             /* Parse the next multibyte character.  */
-            ret = MBRTOWC (NULL, src, src_avail, &state);
+            size_t ret = MBRTOWC (NULL, src, src_avail, &state);
 
             if (ret == (size_t)(-2))
               /* Encountered a multibyte character that extends past a '\0' byte
index 3d66be1f3bbc0836d22b60e8725c7b9a014d5561..8e2dac4c9ac6331f34548a866a62c12d5c62b966 100644 (file)
@@ -46,11 +46,12 @@ mbsspn (const char *string, const char *reject)
       if (MB_CUR_MAX > 1)
         {
 #if GNULIB_MCEL_PREFER
-          for (mcel_t g; *iter; iter += g.len)
+          for (; *iter; )
             {
-              g = mcel_scanz (iter);
+              mcel_t g = mcel_scanz (iter);
               if (! (g.len == 1 && (unsigned char) *iter == uc))
                 break;
+              iter += g.len;
             }
 #else
           mbuif_state_t state;
index 9181ec9612f0ac80ca7c828a96f47b15723b6ffe..1c80d2fed41ce76c01070c90c95c5958b6d92822 100644 (file)
@@ -59,11 +59,10 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle,
   /* Allocate room for needle_mbchars and the table.  */
   void *memory = nmalloca (m + !!extra_align,
                            sizeof (mbchar_t) + sizeof (size_t));
-  void *table_memory;
   if (memory == NULL)
     return false;
   needle_mbchars = memory;
-  table_memory = needle_mbchars + m;
+  void *table_memory = needle_mbchars + m;
   char *aligned = table_memory;
   aligned += extra_align;
   aligned -= (uintptr_t) aligned % alignof (size_t);
@@ -76,9 +75,7 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle,
 #else
   {
     mbui_iterator_t iter;
-    size_t j;
-
-    j = 0;
+    size_t j = 0;
     for (mbui_init (iter, needle); mbui_avail (iter); mbui_advance (iter), j++)
       mb_copy (&needle_mbchars[j], &mbui_cur (iter));
   }
@@ -154,11 +151,10 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle,
   /* Search, using the table to accelerate the processing.  */
   {
 #if GNULIB_MCEL_PREFER
-    size_t j;
     char const *rhaystack = haystack;
     char const *phaystack = haystack;
 
-    j = 0;
+    size_t j = 0;
     /* Invariant: phaystack = rhaystack + j.  */
     for (;;)
       {
@@ -193,13 +189,11 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle,
       }
     *resultp = rhaystack;
 #else
-    size_t j;
-    mbui_iterator_t rhaystack;
-    mbui_iterator_t phaystack;
-
     *resultp = NULL;
-    j = 0;
+    size_t j = 0;
+    mbui_iterator_t rhaystack;
     mbui_init (rhaystack, haystack);
+    mbui_iterator_t phaystack;
     mbui_init (phaystack, haystack);
     /* Invariant: phaystack = rhaystack + j.  */
     while (mbui_avail (phaystack))
@@ -283,7 +277,7 @@ mbsstr (const char *haystack, const char *needle)
 
       char const *iter_haystack = haystack;
 
-      for (mcel_t hg; *iter_haystack; iter_haystack += hg.len)
+      for (; *iter_haystack; )
         {
           /* See whether it's advisable to use an asymptotically faster
              algorithm.  */
@@ -312,7 +306,7 @@ mbsstr (const char *haystack, const char *needle)
 
           outer_loop_count++;
           comparison_count++;
-          hg = mcel_scanz (iter_haystack);
+          mcel_t hg = mcel_scanz (iter_haystack);
           if (mcel_eq (hg, ng))
             /* The first character matches.  */
             {
@@ -331,12 +325,13 @@ mbsstr (const char *haystack, const char *needle)
                 }
               while (mcel_eq (rhg, rng));
             }
+
+          iter_haystack += hg.len;
         }
 
       return NULL;
 #else
       mbui_iterator_t iter_needle;
-
       mbui_init (iter_needle, needle);
       if (mbui_avail (iter_needle))
         {
@@ -358,11 +353,11 @@ mbsstr (const char *haystack, const char *needle)
           size_t outer_loop_count = 0;
           size_t comparison_count = 0;
           size_t last_ccount = 0;                  /* last comparison count */
+
           mbui_iterator_t iter_needle_last_ccount; /* = needle + last_ccount */
+          mbui_init (iter_needle_last_ccount, needle);
 
           mbui_iterator_t iter_haystack;
-
-          mbui_init (iter_needle_last_ccount, needle);
           mbui_init (iter_haystack, haystack);
           for (;; mbui_advance (iter_haystack))
             {
@@ -403,11 +398,10 @@ mbsstr (const char *haystack, const char *needle)
                 /* The first character matches.  */
                 {
                   mbui_iterator_t rhaystack;
-                  mbui_iterator_t rneedle;
-
                   memcpy (&rhaystack, &iter_haystack, sizeof (mbui_iterator_t));
                   mbui_advance (rhaystack);
 
+                  mbui_iterator_t rneedle;
                   mbui_init (rneedle, needle);
                   if (!mbui_avail (rneedle))
                     abort ();
index 73eb138e89b315ec40fe188d9fd6302d5fdcc0ad..b7ba964dd16969aa9e347b286e66ab876c2970ae 100644 (file)
@@ -31,7 +31,6 @@ size_t
 mbstoc32s (char32_t *dest, const char *src, size_t len)
 {
   mbstate_t state;
-
   mbszero (&state);
   return mbsrtoc32s (dest, &src, len, &state);
 }
index 61ca8b380142bb978f6852edc4de63cee0047e59..9fc544f45266d13ffd484a5c08183c45857a11d2 100644 (file)
@@ -27,7 +27,6 @@ size_t
 mbstowcs (wchar_t *dest, const char *src, size_t len)
 {
   mbstate_t state;
-
   mbszero (&state);
   return mbsrtowcs (dest, &src, len, &state);
 }
index f5c7918bd1ec999029f4f7d3bf35c4d1a4f93f0c..caf87b1c52e43f1da4ac8828747e93cbe1a960d4 100644 (file)
@@ -58,9 +58,7 @@ mbsnwidth (const char *string, size_t nbytes, int flags)
 {
   const char *p = string;
   const char *plimit = p + nbytes;
-  int width;
-
-  width = 0;
+  int width = 0;
   if (MB_CUR_MAX > 1)
     {
       while (p < plimit)
@@ -98,10 +96,7 @@ mbsnwidth (const char *string, size_t nbytes, int flags)
                 for (;;)
                   {
                     char32_t wc;
-                    size_t bytes;
-                    int w;
-
-                    bytes = mbrtoc32 (&wc, p, plimit - p, &mbstate);
+                    size_t bytes = mbrtoc32 (&wc, p, plimit - p, &mbstate);
 
                     if (bytes == (size_t) -1)
                       /* An invalid multibyte sequence was encountered.  */
@@ -137,7 +132,7 @@ mbsnwidth (const char *string, size_t nbytes, int flags)
                       bytes = 0;
                     #endif
 
-                    w = c32width (wc);
+                    int w = c32width (wc);
                     if (w >= 0)
                       /* A printable multibyte character.  */
                       {
index 3366c9daf218b2a4a34479d6abf6963c4a66536f..992cffaf7a5eca6bca68c7db85df3d6cf0a4befa 100644 (file)
@@ -27,11 +27,10 @@ mbtowc (wchar_t *pwc, const char *s, size_t n)
   else
     {
       mbstate_t state;
-      wchar_t wc;
-      size_t result;
-
       mbszero (&state);
-      result = mbrtowc (&wc, s, n, &state);
+
+      wchar_t wc;
+      size_t result = mbrtowc (&wc, s, n, &state);
       if (result == (size_t)-1 || result == (size_t)-2)
         {
           errno = EILSEQ;
index 1e67c96ec82aeafb3350d5d2d34dba96aec7a153..d411ec15c5efee3a39f02c04314ab9b282d69077 100644 (file)
@@ -50,10 +50,9 @@ static int
 mbtowc_with_lock (wchar_t *pwc, const char *p, size_t m)
 {
   CRITICAL_SECTION *lock = gl_get_mbtowc_lock ();
-  int ret;
 
   EnterCriticalSection (lock);
-  ret = mbtowc_unlocked (pwc, p, m);
+  int ret = mbtowc_unlocked (pwc, p, m);
   LeaveCriticalSection (lock);
 
   return ret;
@@ -89,11 +88,10 @@ mbtowc_with_lock (wchar_t *pwc, const char *p, size_t m)
   if (pthread_in_use())
     {
       pthread_mutex_t *lock = gl_get_mbtowc_lock ();
-      int ret;
 
       if (pthread_mutex_lock (lock))
         abort ();
-      ret = mbtowc_unlocked (pwc, p, m);
+      int ret = mbtowc_unlocked (pwc, p, m);
       if (pthread_mutex_unlock (lock))
         abort ();
 
@@ -111,11 +109,10 @@ static int
 mbtowc_with_lock (wchar_t *pwc, const char *p, size_t m)
 {
   mtx_t *lock = gl_get_mbtowc_lock ();
-  int ret;
 
   if (mtx_lock (lock) != thrd_success)
     abort ();
-  ret = mbtowc_unlocked (pwc, p, m);
+  int ret = mbtowc_unlocked (pwc, p, m);
   if (mtx_unlock (lock) != thrd_success)
     abort ();
 
index 37d0382935e7576aa95a4dca207acd2129e82ca7..daa959b45d66b18b6c7fd7e214e54077c98a0809 100644 (file)
    You can use this multi-byte code:
 
       char *p = ..., *lim = ...;
-      for (mcel_t g; p < lim; p += g.len)
+      for (; p < lim; )
         {
-          g = mcel_scan (p, lim);
+          mcel_t g = mcel_scan (p, lim);
           process (g);
+          p += g.len;
         }
 
    You can select from G using G.ch, G.err, and G.len.
    You can use this multi-byte code:
 
       char *p = ...;
-      for (mcel_t g; *p; p += g.len)
+      for (; *p; )
         {
-          g = mcel_scanz (p);
+          mcel_t g = mcel_scanz (p);
           process (g);
+          p += g.len;
         }
 
    mcel_scant (P, TERMINATOR) is like mcel_scanz (P) except the
index 363afe7f6cc6d56439df043ac832f78409c5eac7..d14b86354516fd777611bb5c007c9c9bc1ebc50b 100644 (file)
 int
 md2_stream (FILE *stream, void *resblock)
 {
-  struct md2_ctx ctx;
-  size_t sum;
-
   char *buffer = malloc (BLOCKSIZE + 72);
   if (!buffer)
     return 1;
 
   /* Initialize the computation context.  */
+  struct md2_ctx ctx;
   md2_init_ctx (&ctx);
 
   /* Iterate over full file contents.  */
+  size_t sum;
   while (1)
     {
       /* We read the file in blocks of BLOCKSIZE bytes.  One call of the
          computation function processes the whole buffer so that with the
          next round of the loop another block can be read.  */
-      size_t n;
       sum = 0;
 
       /* Read block.  Take care for partial reads.  */
       while (1)
         {
-          n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
+          size_t n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
 
           sum += n;
 
index 799c421fedc668c73404b8a4bc93b92f895fe2a7..905c6137dc05e5a3cfc9d32a5e39d5cbd108f4e5 100644 (file)
--- a/lib/md2.c
+++ b/lib/md2.c
@@ -58,10 +58,8 @@ md2_read_ctx (const struct md2_ctx *ctx, void *resbuf)
 void *
 md2_finish_ctx (struct md2_ctx *ctx, void *resbuf)
 {
-  unsigned long k;
-
   /* pad the message */
-  k = 16 - ctx->curlen;
+  unsigned long k = 16 - ctx->curlen;
   for (unsigned long i = ctx->curlen; i < 16; i++)
     {
       ctx->buf[i] = (unsigned char) k;
@@ -101,11 +99,10 @@ void
 md2_process_bytes (const void *buffer, size_t len, struct md2_ctx *ctx)
 {
   const char *in = buffer;
-  unsigned long n;
 
   while (len > 0)
     {
-      n = MIN (len, (16 - ctx->curlen));
+      unsigned long n = MIN (len, (16 - ctx->curlen));
       memcpy (ctx->buf + ctx->curlen, in, (size_t) n);
       ctx->curlen += n;
       in += n;
@@ -146,9 +143,7 @@ static const unsigned char PI_SUBST[256] = {
 static void
 md2_update_chksum (struct md2_ctx *ctx)
 {
-  unsigned char L;
-
-  L = ctx->chksum[15];
+  unsigned char L = ctx->chksum[15];
   for (int j = 0; j < 16; j++)
     {
       /* caution, the RFC says its "C[j] = S[M[i*16+j] xor L]" but the
@@ -160,8 +155,6 @@ md2_update_chksum (struct md2_ctx *ctx)
 static void
 md2_compress (struct md2_ctx *ctx)
 {
-  unsigned char t;
-
   /* copy block */
   for (size_t j = 0; j < 16; j++)
     {
@@ -169,7 +162,7 @@ md2_compress (struct md2_ctx *ctx)
       ctx->X[32 + j] = ctx->X[j] ^ ctx->X[16 + j];
     }
 
-  t = (unsigned char) 0;
+  unsigned char t = (unsigned char) 0;
 
   /* do 18 rounds */
   for (size_t j = 0; j < 18; j++)
index 85253e809ce4da8f6087231552c5c69c9c32e898..1c0d23ac1c76fb131fe3ec6d7ff92ee1757beca7 100644 (file)
 int
 md4_stream (FILE * stream, void *resblock)
 {
-  struct md4_ctx ctx;
-  size_t sum;
-
   char *buffer = malloc (BLOCKSIZE + 72);
   if (!buffer)
     return 1;
 
   /* Initialize the computation context.  */
+  struct md4_ctx ctx;
   md4_init_ctx (&ctx);
 
   /* Iterate over full file contents.  */
+  size_t sum;
   while (1)
     {
       /* We read the file in blocks of BLOCKSIZE bytes.  One call of the
          computation function processes the whole buffer so that with the
          next round of the loop another block can be read.  */
-      size_t n;
       sum = 0;
 
       /* Read block.  Take care for partial reads.  */
       while (1)
         {
-          n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
+          size_t n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
 
           sum += n;
 
index 391f8ec0ad380f212e14ee54aceb65203fbe99c4..ce2f076fc65270775d9f91447b6a816c3e245a64 100644 (file)
--- a/lib/md4.c
+++ b/lib/md4.c
@@ -84,14 +84,13 @@ md4_finish_ctx (struct md4_ctx *ctx, void *resbuf)
 {
   /* Take yet unprocessed bytes into account.  */
   uint32_t bytes = ctx->buflen;
-  size_t pad;
 
   /* Now count remaining bytes.  */
   ctx->total[0] += bytes;
   if (ctx->total[0] < bytes)
     ++ctx->total[1];
 
-  pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
+  size_t pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
   memcpy (&((char*)ctx->buffer)[bytes], fillbuf, pad);
 
   /* Put the 64-bit file length in *bits* at the end of the buffer.  */
@@ -213,7 +212,6 @@ md4_process_block (const void *buffer, size_t len, struct md4_ctx *ctx)
   const uint32_t *words = buffer;
   size_t nwords = len / sizeof (uint32_t);
   const uint32_t *endp = words + nwords;
-  uint32_t x[16];
   uint32_t A = ctx->A;
   uint32_t B = ctx->B;
   uint32_t C = ctx->C;
@@ -230,6 +228,7 @@ md4_process_block (const void *buffer, size_t len, struct md4_ctx *ctx)
      the loop.  */
   while (words < endp)
     {
+      uint32_t x[16];
       for (int t = 0; t < 16; t++)
         {
           x[t] = SWAP (*words);
index a5d6a3109a4fb2c367495175b4b320889dd4ffe9..76d7c4146645f41243ff8c8391e1d377fa2f5255 100644 (file)
@@ -69,15 +69,14 @@ md5_stream (FILE *stream, void *resblock)
 
   struct md5_ctx ctx;
   md5_init_ctx (&ctx);
-  size_t sum;
 
   /* Iterate over full file contents.  */
+  size_t sum;
   while (1)
     {
       /* We read the file in blocks of BLOCKSIZE bytes.  One call of the
          computation function processes the whole buffer so that with the
          next round of the loop another block can be read.  */
-      size_t n;
       sum = 0;
 
       /* Read block.  Take care for partial reads.  */
@@ -91,7 +90,7 @@ md5_stream (FILE *stream, void *resblock)
           if (feof (stream))
             goto process_partial_block;
 
-          n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
+          size_t n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
 
           sum += n;
 
index 81540e05672644230961c4b0c27169df34b82616..0d1b76c55338bf7dd3d73afeaafb94eda7f7243a 100644 (file)
@@ -88,14 +88,11 @@ hash_destroy (hash_table *htab)
 static size_t
 compute_hashval (const void *key, size_t keylen)
 {
-  size_t cnt;
-  size_t hval;
-
   /* Compute the hash value for the given string.  The algorithm
      is taken from [Aho,Sethi,Ullman], fixed according to
      https://haible.de/bruno/hashfunc.html.  */
-  cnt = 0;
-  hval = keylen;
+  size_t cnt = 0;
+  size_t hval = keylen;
   while (cnt < keylen)
     {
       hval = (hval << 9) | (hval >> (sizeof (size_t) * CHAR_BIT - 9));
@@ -117,14 +114,12 @@ lookup (const hash_table *htab,
         const void *key, size_t keylen,
         size_t hval)
 {
-  size_t hash;
-  size_t idx;
   hash_entry *table = htab->table;
 
   /* First hash function: simply take the modul but prevent zero.  */
-  hash = 1 + hval % htab->size;
+  size_t hash = 1 + hval % htab->size;
 
-  idx = hash;
+  size_t idx = hash;
 
   if (table[idx].used)
     {
index c1fe49646202f4b5fa60fed828d337162d8caa34..ea3bc0eb8d90ce9811edda4a5c39591b196a124a 100644 (file)
@@ -65,101 +65,103 @@ __memchr (void const *s, int c_in, size_t n)
      performance.  */
   typedef unsigned long int longword;
 
-  const unsigned char *char_ptr;
-  const longword *longword_ptr;
-  longword repeated_one;
-  longword repeated_c;
-  unsigned reg_char c;
+  unsigned reg_char c = (unsigned char) c_in;
 
-  c = (unsigned char) c_in;
+  const longword *longword_ptr;
 
   /* Handle the first few bytes by reading one byte at a time.
      Do this until CHAR_PTR is aligned on a longword boundary.  */
-  for (char_ptr = (const unsigned char *) s;
-       n > 0 && (size_t) char_ptr % sizeof (longword) != 0;
-       --n, ++char_ptr)
-    if (*char_ptr == c)
-      return (void *) char_ptr;
+  {
+    const unsigned char *char_ptr;
+    for (char_ptr = (const unsigned char *) s;
+         n > 0 && (size_t) char_ptr % sizeof (longword) != 0;
+         --n, ++char_ptr)
+      if (*char_ptr == c)
+        return (void *) char_ptr;
 
-  longword_ptr = (const longword *) char_ptr;
+    longword_ptr = (const longword *) char_ptr;
+  }
 
   /* All these elucidatory comments refer to 4-byte longwords,
      but the theory applies equally well to any size longwords.  */
-
-  /* Compute auxiliary longword values:
-     repeated_one is a value which has a 1 in every byte.
-     repeated_c has c in every byte.  */
-  repeated_one = 0x01010101;
-  repeated_c = c | (c << 8);
-  repeated_c |= repeated_c << 16;
-  if (0xffffffffU < (longword) -1)
-    {
-      repeated_one |= repeated_one << 31 << 1;
-      repeated_c |= repeated_c << 31 << 1;
-      if (8 < sizeof (longword))
-        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
-     longword at a time.  The tricky part is testing if *any of the four*
-     bytes in the longword in question are equal to c.  We first use an xor
-     with repeated_c.  This reduces the task to testing whether *any of the
-     four* bytes in longword1 is zero.
-
-     We compute tmp =
-       ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
-     That is, we perform the following operations:
-       1. Subtract repeated_one.
-       2. & ~longword1.
-       3. & a mask consisting of 0x80 in every byte.
-     Consider what happens in each byte:
-       - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
-         and step 3 transforms it into 0x80.  A carry can also be propagated
-         to more significant bytes.
-       - If a byte of longword1 is nonzero, let its lowest 1 bit be at
-         position k (0 <= k <= 7); so the lowest k bits are 0.  After step 1,
-         the byte ends in a single bit of value 0 and k bits of value 1.
-         After step 2, the result is just k bits of value 1: 2^k - 1.  After
-         step 3, the result is 0.  And no carry is produced.
-     So, if longword1 has only non-zero bytes, tmp is zero.
-     Whereas if longword1 has a zero byte, call j the position of the least
-     significant zero byte.  Then the result has a zero at positions 0, ...,
-     j-1 and a 0x80 at position j.  We cannot predict the result at the more
-     significant bytes (positions j+1..3), but it does not matter since we
-     already have a non-zero bit at position 8*j+7.
-
-     So, the test whether any byte in longword1 is zero is equivalent to
-     testing whether tmp is nonzero.  */
-
-  while (n >= sizeof (longword))
-    {
-      longword longword1 = *longword_ptr ^ repeated_c;
-
-      if ((((longword1 - repeated_one) & ~longword1)
-           & (repeated_one << 7)) != 0)
-        break;
-      longword_ptr++;
-      n -= sizeof (longword);
-    }
-
-  char_ptr = (const unsigned char *) longword_ptr;
-
-  /* At this point, we know that either n < sizeof (longword), or one of the
-     sizeof (longword) bytes starting at char_ptr is == c.  On little-endian
-     machines, we could determine the first such byte without any further
-     memory accesses, just by looking at the tmp result from the last loop
-     iteration.  But this does not work on big-endian machines.  Choose code
-     that works in both cases.  */
-
-  for (; n > 0; --n, ++char_ptr)
-    {
-      if (*char_ptr == c)
-        return (void *) char_ptr;
-    }
+  {
+    /* Compute auxiliary longword values:
+       repeated_one is a value which has a 1 in every byte.
+       repeated_c has c in every byte.  */
+    longword repeated_one = 0x01010101;
+    longword repeated_c = c | (c << 8);
+    repeated_c |= repeated_c << 16;
+    if (0xffffffffU < (longword) -1)
+      {
+        repeated_one |= repeated_one << 31 << 1;
+        repeated_c |= repeated_c << 31 << 1;
+        if (8 < sizeof (longword))
+          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
+       longword at a time.  The tricky part is testing if *any of the four*
+       bytes in the longword in question are equal to c.  We first use an xor
+       with repeated_c.  This reduces the task to testing whether *any of the
+       four* bytes in longword1 is zero.
+
+       We compute tmp =
+         ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
+       That is, we perform the following operations:
+         1. Subtract repeated_one.
+         2. & ~longword1.
+         3. & a mask consisting of 0x80 in every byte.
+       Consider what happens in each byte:
+         - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
+           and step 3 transforms it into 0x80.  A carry can also be propagated
+           to more significant bytes.
+         - If a byte of longword1 is nonzero, let its lowest 1 bit be at
+           position k (0 <= k <= 7); so the lowest k bits are 0.  After step 1,
+           the byte ends in a single bit of value 0 and k bits of value 1.
+           After step 2, the result is just k bits of value 1: 2^k - 1.  After
+           step 3, the result is 0.  And no carry is produced.
+       So, if longword1 has only non-zero bytes, tmp is zero.
+       Whereas if longword1 has a zero byte, call j the position of the least
+       significant zero byte.  Then the result has a zero at positions 0, ...,
+       j-1 and a 0x80 at position j.  We cannot predict the result at the more
+       significant bytes (positions j+1..3), but it does not matter since we
+       already have a non-zero bit at position 8*j+7.
+
+       So, the test whether any byte in longword1 is zero is equivalent to
+       testing whether tmp is nonzero.  */
+
+    while (n >= sizeof (longword))
+      {
+        longword longword1 = *longword_ptr ^ repeated_c;
+
+        if ((((longword1 - repeated_one) & ~longword1)
+             & (repeated_one << 7)) != 0)
+          break;
+        longword_ptr++;
+        n -= sizeof (longword);
+      }
+  }
+
+  {
+    const unsigned char *char_ptr = (const unsigned char *) longword_ptr;
+
+    /* At this point, we know that either n < sizeof (longword), or one of the
+       sizeof (longword) bytes starting at char_ptr is == c.  On little-endian
+       machines, we could determine the first such byte without any further
+       memory accesses, just by looking at the tmp result from the last loop
+       iteration.  But this does not work on big-endian machines.  Choose code
+       that works in both cases.  */
+
+    for (; n > 0; --n, ++char_ptr)
+      {
+        if (*char_ptr == c)
+          return (void *) char_ptr;
+      }
+  }
 
   return NULL;
 }
index 8ad96500bd93927731e028fcebab01cc717b317d..dcd191d41d9b9d862e6642685c311551b2cea036 100644 (file)
@@ -42,124 +42,119 @@ memchr2 (void const *s, int c1_in, int c2_in, size_t n)
      performance.  */
   typedef unsigned long int longword;
 
-  const unsigned char *char_ptr;
-  void const *void_ptr;
-  const longword *longword_ptr;
-  longword repeated_one;
-  longword repeated_c1;
-  longword repeated_c2;
-  unsigned char c1;
-  unsigned char c2;
-
-  c1 = (unsigned char) c1_in;
-  c2 = (unsigned char) c2_in;
+  unsigned char c1 = (unsigned char) c1_in;
+  unsigned char c2 = (unsigned char) c2_in;
 
   if (c1 == c2)
     return (void *) memchr (s, c1, n);
 
   /* Handle the first few bytes by reading one byte at a time.
      Do this until VOID_PTR is aligned on a longword boundary.  */
+  void const *void_ptr;
   for (void_ptr = s;
        n > 0 && (uintptr_t) void_ptr % sizeof (longword) != 0;
        --n)
     {
-      char_ptr = void_ptr;
+      const unsigned char *char_ptr = void_ptr;
       if (*char_ptr == c1 || *char_ptr == c2)
         return (void *) void_ptr;
       void_ptr = char_ptr + 1;
     }
 
-  longword_ptr = void_ptr;
+  const longword *longword_ptr = void_ptr;
 
   /* All these elucidatory comments refer to 4-byte longwords,
      but the theory applies equally well to any size longwords.  */
-
-  /* Compute auxiliary longword values:
-     repeated_one is a value which has a 1 in every byte.
-     repeated_c1 has c1 in every byte.
-     repeated_c2 has c2 in every byte.  */
-  repeated_one = 0x01010101;
-  repeated_c1 = c1 | (c1 << 8);
-  repeated_c2 = c2 | (c2 << 8);
-  repeated_c1 |= repeated_c1 << 16;
-  repeated_c2 |= repeated_c2 << 16;
-  if (0xffffffffU < (longword) -1)
-    {
-      repeated_one |= repeated_one << 31 << 1;
-      repeated_c1 |= repeated_c1 << 31 << 1;
-      repeated_c2 |= repeated_c2 << 31 << 1;
-      if (8 < sizeof (longword))
-        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
-     longword at a time.  The tricky part is testing if *any of the four*
-     bytes in the longword in question are equal to c1 or c2.  We first use
-     an xor with repeated_c1 and repeated_c2, respectively.  This reduces
-     the task to testing whether *any of the four* bytes in longword1 or
-     longword2 is zero.
-
-     Let's consider longword1.  We compute tmp1 =
-       ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
-     That is, we perform the following operations:
-       1. Subtract repeated_one.
-       2. & ~longword1.
-       3. & a mask consisting of 0x80 in every byte.
-     Consider what happens in each byte:
-       - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
-         and step 3 transforms it into 0x80.  A carry can also be propagated
-         to more significant bytes.
-       - If a byte of longword1 is nonzero, let its lowest 1 bit be at
-         position k (0 <= k <= 7); so the lowest k bits are 0.  After step 1,
-         the byte ends in a single bit of value 0 and k bits of value 1.
-         After step 2, the result is just k bits of value 1: 2^k - 1.  After
-         step 3, the result is 0.  And no carry is produced.
-     So, if longword1 has only non-zero bytes, tmp1 is zero.
-     Whereas if longword1 has a zero byte, call j the position of the least
-     significant zero byte.  Then the result has a zero at positions 0, ...,
-     j-1 and a 0x80 at position j.  We cannot predict the result at the more
-     significant bytes (positions j+1..3), but it does not matter since we
-     already have a non-zero bit at position 8*j+7.
-
-     Similarly, we compute tmp2 =
-       ((longword2 - repeated_one) & ~longword2) & (repeated_one << 7).
-
-     The test whether any byte in longword1 or longword2 is zero is equivalent
-     to testing whether tmp1 is nonzero or tmp2 is nonzero.  We can combine
-     this into a single test, whether (tmp1 | tmp2) is nonzero.  */
-
-  while (n >= sizeof (longword))
-    {
-      longword longword1 = *longword_ptr ^ repeated_c1;
-      longword longword2 = *longword_ptr ^ repeated_c2;
-
-      if (((((longword1 - repeated_one) & ~longword1)
-            | ((longword2 - repeated_one) & ~longword2))
-           & (repeated_one << 7)) != 0)
-        break;
-      longword_ptr++;
-      n -= sizeof (longword);
-    }
-
-  char_ptr = (const unsigned char *) longword_ptr;
-
-  /* At this point, we know that either n < sizeof (longword), or one of the
-     sizeof (longword) bytes starting at char_ptr is == c1 or == c2.  On
-     little-endian machines, we could determine the first such byte without
-     any further memory accesses, just by looking at the (tmp1 | tmp2) result
-     from the last loop iteration.  But this does not work on big-endian
-     machines.  Choose code that works in both cases.  */
-
-  for (; n > 0; --n, ++char_ptr)
-    {
-      if (*char_ptr == c1 || *char_ptr == c2)
-        return (void *) char_ptr;
-    }
+  {
+    /* Compute auxiliary longword values:
+       repeated_one is a value which has a 1 in every byte.
+       repeated_c1 has c1 in every byte.
+       repeated_c2 has c2 in every byte.  */
+    longword repeated_one = 0x01010101;
+    longword repeated_c1 = c1 | (c1 << 8);
+    longword repeated_c2 = c2 | (c2 << 8);
+    repeated_c1 |= repeated_c1 << 16;
+    repeated_c2 |= repeated_c2 << 16;
+    if (0xffffffffU < (longword) -1)
+      {
+        repeated_one |= repeated_one << 31 << 1;
+        repeated_c1 |= repeated_c1 << 31 << 1;
+        repeated_c2 |= repeated_c2 << 31 << 1;
+        if (8 < sizeof (longword))
+          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
+       longword at a time.  The tricky part is testing if *any of the four*
+       bytes in the longword in question are equal to c1 or c2.  We first use
+       an xor with repeated_c1 and repeated_c2, respectively.  This reduces
+       the task to testing whether *any of the four* bytes in longword1 or
+       longword2 is zero.
+
+       Let's consider longword1.  We compute tmp1 =
+         ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
+       That is, we perform the following operations:
+         1. Subtract repeated_one.
+         2. & ~longword1.
+         3. & a mask consisting of 0x80 in every byte.
+       Consider what happens in each byte:
+         - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
+           and step 3 transforms it into 0x80.  A carry can also be propagated
+           to more significant bytes.
+         - If a byte of longword1 is nonzero, let its lowest 1 bit be at
+           position k (0 <= k <= 7); so the lowest k bits are 0.  After step 1,
+           the byte ends in a single bit of value 0 and k bits of value 1.
+           After step 2, the result is just k bits of value 1: 2^k - 1.  After
+           step 3, the result is 0.  And no carry is produced.
+       So, if longword1 has only non-zero bytes, tmp1 is zero.
+       Whereas if longword1 has a zero byte, call j the position of the least
+       significant zero byte.  Then the result has a zero at positions 0, ...,
+       j-1 and a 0x80 at position j.  We cannot predict the result at the more
+       significant bytes (positions j+1..3), but it does not matter since we
+       already have a non-zero bit at position 8*j+7.
+
+       Similarly, we compute tmp2 =
+         ((longword2 - repeated_one) & ~longword2) & (repeated_one << 7).
+
+       The test whether any byte in longword1 or longword2 is zero is equivalent
+       to testing whether tmp1 is nonzero or tmp2 is nonzero.  We can combine
+       this into a single test, whether (tmp1 | tmp2) is nonzero.  */
+
+    while (n >= sizeof (longword))
+      {
+        longword longword1 = *longword_ptr ^ repeated_c1;
+        longword longword2 = *longword_ptr ^ repeated_c2;
+
+        if (((((longword1 - repeated_one) & ~longword1)
+              | ((longword2 - repeated_one) & ~longword2))
+             & (repeated_one << 7)) != 0)
+          break;
+        longword_ptr++;
+        n -= sizeof (longword);
+      }
+  }
+
+  {
+    const unsigned char *char_ptr = (const unsigned char *) longword_ptr;
+
+    /* At this point, we know that either n < sizeof (longword), or one of the
+       sizeof (longword) bytes starting at char_ptr is == c1 or == c2.  On
+       little-endian machines, we could determine the first such byte without
+       any further memory accesses, just by looking at the (tmp1 | tmp2) result
+       from the last loop iteration.  But this does not work on big-endian
+       machines.  Choose code that works in both cases.  */
+
+    for (; n > 0; --n, ++char_ptr)
+      {
+        if (*char_ptr == c1 || *char_ptr == c2)
+          return (void *) char_ptr;
+      }
+  }
 
   return NULL;
 }
index 0c4022caff10918ccc798cf30add0ba35b173956..0321cb3b0de1174d755322da8b80989ef739ded9 100644 (file)
@@ -52,103 +52,104 @@ __memrchr (void const *s, int c_in, size_t n)
      performance.  */
   typedef unsigned long int longword;
 
-  const unsigned char *char_ptr;
-  const longword *longword_ptr;
-  longword repeated_one;
-  longword repeated_c;
-  unsigned reg_char c;
+  unsigned reg_char c = (unsigned char) c_in;
 
-  c = (unsigned char) c_in;
+  const longword *longword_ptr;
 
   /* Handle the last few bytes by reading one byte at a time.
      Do this until CHAR_PTR is aligned on a longword boundary.  */
-  for (char_ptr = (const unsigned char *) s + n;
-       n > 0 && (size_t) char_ptr % sizeof (longword) != 0;
-       --n)
-    if (*--char_ptr == c)
-      return (void *) char_ptr;
+  {
+    const unsigned char *char_ptr;
+    for (char_ptr = (const unsigned char *) s + n;
+         n > 0 && (size_t) char_ptr % sizeof (longword) != 0;
+         --n)
+      if (*--char_ptr == c)
+        return (void *) char_ptr;
 
-  longword_ptr = (const void *) char_ptr;
+    longword_ptr = (const void *) char_ptr;
+  }
 
   /* All these elucidatory comments refer to 4-byte longwords,
      but the theory applies equally well to any size longwords.  */
-
-  /* Compute auxiliary longword values:
-     repeated_one is a value which has a 1 in every byte.
-     repeated_c has c in every byte.  */
-  repeated_one = 0x01010101;
-  repeated_c = c | (c << 8);
-  repeated_c |= repeated_c << 16;
-  if (0xffffffffU < (longword) -1)
-    {
-      repeated_one |= repeated_one << 31 << 1;
-      repeated_c |= repeated_c << 31 << 1;
-      if (8 < sizeof (longword))
-        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
-     longword at a time.  The tricky part is testing if *any of the four*
-     bytes in the longword in question are equal to c.  We first use an xor
-     with repeated_c.  This reduces the task to testing whether *any of the
-     four* bytes in longword1 is zero.
-
-     We compute tmp =
-       ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
-     That is, we perform the following operations:
-       1. Subtract repeated_one.
-       2. & ~longword1.
-       3. & a mask consisting of 0x80 in every byte.
-     Consider what happens in each byte:
-       - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
-         and step 3 transforms it into 0x80.  A carry can also be propagated
-         to more significant bytes.
-       - If a byte of longword1 is nonzero, let its lowest 1 bit be at
-         position k (0 <= k <= 7); so the lowest k bits are 0.  After step 1,
-         the byte ends in a single bit of value 0 and k bits of value 1.
-         After step 2, the result is just k bits of value 1: 2^k - 1.  After
-         step 3, the result is 0.  And no carry is produced.
-     So, if longword1 has only non-zero bytes, tmp is zero.
-     Whereas if longword1 has a zero byte, call j the position of the least
-     significant zero byte.  Then the result has a zero at positions 0, ...,
-     j-1 and a 0x80 at position j.  We cannot predict the result at the more
-     significant bytes (positions j+1..3), but it does not matter since we
-     already have a non-zero bit at position 8*j+7.
+  {
+    /* Compute auxiliary longword values:
+       repeated_one is a value which has a 1 in every byte.
+       repeated_c has c in every byte.  */
+    longword repeated_one = 0x01010101;
+    longword repeated_c = c | (c << 8);
+    repeated_c |= repeated_c << 16;
+    if (0xffffffffU < (longword) -1)
+      {
+        repeated_one |= repeated_one << 31 << 1;
+        repeated_c |= repeated_c << 31 << 1;
+        if (8 < sizeof (longword))
+          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
+       longword at a time.  The tricky part is testing if *any of the four*
+       bytes in the longword in question are equal to c.  We first use an xor
+       with repeated_c.  This reduces the task to testing whether *any of the
+       four* bytes in longword1 is zero.
+
+       We compute tmp =
+         ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
+       That is, we perform the following operations:
+         1. Subtract repeated_one.
+         2. & ~longword1.
+         3. & a mask consisting of 0x80 in every byte.
+       Consider what happens in each byte:
+         - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
+           and step 3 transforms it into 0x80.  A carry can also be propagated
+           to more significant bytes.
+         - If a byte of longword1 is nonzero, let its lowest 1 bit be at
+           position k (0 <= k <= 7); so the lowest k bits are 0.  After step 1,
+           the byte ends in a single bit of value 0 and k bits of value 1.
+           After step 2, the result is just k bits of value 1: 2^k - 1.  After
+           step 3, the result is 0.  And no carry is produced.
+       So, if longword1 has only non-zero bytes, tmp is zero.
+       Whereas if longword1 has a zero byte, call j the position of the least
+       significant zero byte.  Then the result has a zero at positions 0, ...,
+       j-1 and a 0x80 at position j.  We cannot predict the result at the more
+       significant bytes (positions j+1..3), but it does not matter since we
+       already have a non-zero bit at position 8*j+7.
 
      So, the test whether any byte in longword1 is zero is equivalent to
      testing whether tmp is nonzero.  */
 
-  while (n >= sizeof (longword))
-    {
-      longword longword1 = *--longword_ptr ^ repeated_c;
-
-      if ((((longword1 - repeated_one) & ~longword1)
-           & (repeated_one << 7)) != 0)
-        {
-          longword_ptr++;
-          break;
-        }
-      n -= sizeof (longword);
-    }
-
-  char_ptr = (const unsigned char *) longword_ptr;
-
-  /* At this point, we know that either n < sizeof (longword), or one of the
-     sizeof (longword) bytes starting at char_ptr is == c.  On little-endian
-     machines, we could determine the first such byte without any further
-     memory accesses, just by looking at the tmp result from the last loop
-     iteration.  But this does not work on big-endian machines.  Choose code
-     that works in both cases.  */
-
-  while (n-- > 0)
-    {
-      if (*--char_ptr == c)
-        return (void *) char_ptr;
-    }
+    while (n >= sizeof (longword))
+      {
+        longword longword1 = *--longword_ptr ^ repeated_c;
+
+        if ((((longword1 - repeated_one) & ~longword1)
+             & (repeated_one << 7)) != 0)
+          {
+            longword_ptr++;
+            break;
+          }
+        n -= sizeof (longword);
+      }
+  }
+
+  {
+    const unsigned char *char_ptr = (const unsigned char *) longword_ptr;
+
+    /* At this point, we know that either n < sizeof (longword), or one of the
+       sizeof (longword) bytes starting at char_ptr is == c.  On little-endian
+       machines, we could determine the first such byte without any further
+       memory accesses, just by looking at the tmp result from the last loop
+       iteration.  But this does not work on big-endian machines.  Choose code
+       that works in both cases.  */
+    while (n-- > 0)
+      {
+        if (*--char_ptr == c)
+          return (void *) char_ptr;
+      }
+  }
 
   return NULL;
 }
index 44da49a93f0884e12f1d53402f42adc6db102aca..84838ef59c1df5372d53e3f9e59f38149e74b0a1 100644 (file)
@@ -65,10 +65,6 @@ realloc_groupbuf (gid_t *g, size_t num)
 int
 mgetgroups (char const *username, gid_t gid, gid_t **groups)
 {
-  int max_n_groups;
-  int ng;
-  gid_t *g;
-
 #if HAVE_GETGROUPLIST
   /* We prefer to use getgrouplist if available, because it has better
      performance characteristics.
@@ -81,26 +77,26 @@ mgetgroups (char const *username, gid_t gid, gid_t **groups)
   if (username)
     {
       enum { N_GROUPS_INIT = 10 };
-      max_n_groups = N_GROUPS_INIT;
+      int max_n_groups = N_GROUPS_INIT;
 
-      g = realloc_groupbuf (NULL, max_n_groups);
+      gid_t *g = realloc_groupbuf (NULL, max_n_groups);
       if (g == NULL)
         return -1;
 
       while (1)
         {
-          gid_t *h;
           int last_n_groups = max_n_groups;
 
           /* getgrouplist updates max_n_groups to num required.  */
-          ng = getgrouplist (username, gid, g, &max_n_groups);
+          int ng = getgrouplist (username, gid, g, &max_n_groups);
 
           /* Some systems (like Darwin) have a bug where they
              never increase max_n_groups.  */
           if (ng < 0 && last_n_groups == max_n_groups)
             max_n_groups *= 2;
 
-          if ((h = realloc_groupbuf (g, max_n_groups)) == NULL)
+          gid_t *h = realloc_groupbuf (g, max_n_groups);
+          if (h == NULL)
             {
               free (g);
               return -1;
@@ -119,34 +115,38 @@ mgetgroups (char const *username, gid_t gid, gid_t **groups)
   /* else no username, so fall through and use getgroups. */
 #endif
 
-  max_n_groups = (username
-                  ? getugroups (0, NULL, username, gid)
-                  : getgroups (0, NULL));
+  int max_n_groups = (username
+                      ? getugroups (0, NULL, username, gid)
+                      : getgroups (0, NULL));
 
   /* If we failed to count groups because there is no supplemental
      group support, then return an array containing just GID.
      Otherwise, we fail for the same reason.  */
   if (max_n_groups < 0)
     {
-      if (errno == ENOSYS && (g = realloc_groupbuf (NULL, 1)))
+      if (errno == ENOSYS)
         {
-          *groups = g;
-          *g = gid;
-          return gid != (gid_t) -1;
+          gid_t *g = realloc_groupbuf (NULL, 1);
+          if (g)
+            {
+              *groups = g;
+              *g = gid;
+              return gid != (gid_t) -1;
+            }
         }
       return -1;
     }
 
   if (max_n_groups == 0 || (!username && gid != (gid_t) -1))
     max_n_groups++;
-  g = realloc_groupbuf (NULL, max_n_groups);
+  gid_t *g = realloc_groupbuf (NULL, max_n_groups);
   if (g == NULL)
     return -1;
 
-  ng = (username
-        ? getugroups (max_n_groups, g, username, gid)
-        : getgroups (max_n_groups - (gid != (gid_t) -1),
-                                g + (gid != (gid_t) -1)));
+  int ng = (username
+            ? getugroups (max_n_groups, g, username, gid)
+            : getgroups (max_n_groups - (gid != (gid_t) -1),
+                                    g + (gid != (gid_t) -1)));
 
   if (ng < 0)
     {
index fcd8c99eec9c8911432931e4b4ad9f7ffc49cc5d..e4d6e851e76dd1f95f225c7c53cc4fdf70639788 100644 (file)
@@ -97,16 +97,13 @@ mkancesdirs (char *file, struct savewd *wd,
            affect the algorithm.  */
         if (! (sep - component == 1 && component[0] == '.'))
           {
-            int make_dir_errno = 0;
-            int savewd_chdir_options = 0;
-            int chdir_result;
-
             /* Temporarily modify FILE to isolate this file name
                component.  */
             *sep = '\0';
 
             /* Invoke MAKE_DIR on this component, except don't bother
                with ".." since it must exist if its "parent" does.  */
+            int make_dir_errno = 0;
             if (sep - component == 2
                 && component[0] == '.' && component[1] == '.')
               made_dir = false;
@@ -115,10 +112,11 @@ mkancesdirs (char *file, struct savewd *wd,
             else
               made_dir = true;
 
+            int savewd_chdir_options = 0;
             if (made_dir)
               savewd_chdir_options |= SAVEWD_CHDIR_NOFOLLOW;
 
-            chdir_result =
+            int chdir_result =
               savewd_chdir (wd, component, savewd_chdir_options, NULL);
 
             /* Undo the temporary modification to FILE, unless there
index 6c10819401229a0f6ff404a428853b5c960632a8..be9111561a808df26830c3e36bddbaac73466405 100644 (file)
@@ -97,9 +97,9 @@ make_dir_parents (char *dir,
 
   if (mkdir_errno == 0)
     {
-      ptrdiff_t prefix_len = 0;
       int savewd_chdir_options = (HAVE_FCHMOD ? SAVEWD_CHDIR_SKIP_READABLE : 0);
 
+      ptrdiff_t prefix_len = 0;
       if (make_ancestor)
         {
           prefix_len = mkancesdirs (dir, wd, make_ancestor, options);
index b680db2ae1249ed4cccd4259082cac286006bf2f..eb0e698df31c80def73737dc33410dcf3259c4fe 100644 (file)
 int
 rpl_mkdir (char const *dir, maybe_unused mode_t mode)
 {
-  int ret_val;
-  char *tmp_dir;
   size_t len = strlen (dir);
 
+  char *tmp_dir;
   if (len && dir[len - 1] == '/')
     {
       tmp_dir = strdup (dir);
@@ -69,6 +68,7 @@ rpl_mkdir (char const *dir, maybe_unused mode_t mode)
     {
       tmp_dir = (char *) dir;
     }
+
 #if FUNC_MKDIR_DOT_BUG
   /* Additionally, cygwin 1.5 mistakenly creates a directory "d/./".  */
   {
@@ -84,7 +84,7 @@ rpl_mkdir (char const *dir, maybe_unused mode_t mode)
   }
 #endif /* FUNC_MKDIR_DOT_BUG */
 
-  ret_val = mkdir (tmp_dir, mode);
+  int ret_val = mkdir (tmp_dir, mode);
 
   if (tmp_dir != dir)
     free (tmp_dir);
index 17a3eecb5b79dcd8595cb98f8e60b1ad9e773e91..44b4e7f14e4a1b62a8b29b6b6eeac426793e455b 100644 (file)
@@ -133,10 +133,6 @@ make_node_op_equals (mode_t new_mode, mode_t mentioned)
 struct mode_change *
 mode_compile (char const *mode_string)
 {
-  /* The array of mode-change directives to be returned.  */
-  struct mode_change *mc;
-  size_t used = 0;
-
   if ('0' <= *mode_string && *mode_string < '8')
     {
       char const *p;
@@ -163,6 +159,9 @@ mode_compile (char const *mode_string)
       return make_node_op_equals (mode, mentioned);
     }
 
+  /* The array of mode-change directives to be returned.  */
+  struct mode_change *mc;
+
   /* Allocate enough space to hold the result.  */
   {
     size_t needed = 1;
@@ -173,6 +172,7 @@ mode_compile (char const *mode_string)
 
   /* One loop iteration for each
      '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+'.  */
+  size_t used = 0;
   char const *p;
   for (p = mode_string; ; p++)
     {
@@ -208,7 +208,6 @@ mode_compile (char const *mode_string)
           mode_t value;
           mode_t mentioned = 0;
           char flag = MODE_COPY_EXISTING;
-          struct mode_change *change;
 
           switch (*p)
             {
@@ -285,6 +284,7 @@ mode_compile (char const *mode_string)
             no_more_values:;
             }
 
+          struct mode_change *change;
           change = &mc[used++];
           change->op = op;
           change->flag = flag;
index aa5d70ec01059f85f8ce1ab8206e9aab5a1ef6bc..ac41e41b423dcd2bd5ad061abc1e84e8e0b753e3 100644 (file)
@@ -367,9 +367,7 @@ fsp_to_string (const struct statfs *fsp)
 static char *
 fstype_to_string (int t)
 {
-  struct vfs_ent *e;
-
-  e = getvfsbytype (t);
+  struct vfs_ent *e = getvfsbytype (t);
   if (!e || !e->vfsent_name)
     return "none";
   else
@@ -398,10 +396,9 @@ dev_from_mount_options (char const *mount_options)
       char const *optval = devopt + sizeof dev_pattern - 1;
       if (c_isxdigit (*optval))
         {
-          char *optvalend;
-          unsigned long int dev;
           errno = 0;
-          dev = strtoul (optval, &optvalend, 16);
+          char *optvalend;
+          unsigned long int dev = strtoul (optval, &optvalend, 16);
           if (optval != optvalend
               && (*optvalend == '\0' || *optvalend == ',')
               && ! (dev == ULONG_MAX && errno == ERANGE)
@@ -469,15 +466,13 @@ read_file_system_list (bool need_fs_type)
 #ifdef MOUNTED_GETMNTENT1       /* glibc, HP-UX, Cygwin, Android,
                                    also (obsolete) 4.3BSD, SunOS */
   {
-    FILE *fp;
-
 # if defined __linux__ || defined __ANDROID__
     /* Try parsing mountinfo first, as that make device IDs available.
        Note we could use libmount routines to simplify this parsing a little
        (and that code is in previous versions of this function), however
        libmount depends on libselinux which pulls in many dependencies.  */
     char const *mountinfo = "/proc/self/mountinfo";
-    fp = fopen (mountinfo, "re");
+    FILE *fp = fopen (mountinfo, "re");
     if (fp != NULL)
       {
         char *line = NULL;
@@ -568,14 +563,14 @@ read_file_system_list (bool need_fs_type)
     else /* fallback to /proc/self/mounts (/etc/mtab).  */
 # endif /* __linux__ || __ANDROID__ */
       {
-        struct mntent *mnt;
         char const *table = MOUNTED;
 
-        fp = setmntent (table, "r");
-        if (fp == NULL)
+        FILE *mfp = setmntent (table, "r");
+        if (mfp == NULL)
           return NULL;
 
-        while ((mnt = getmntent (fp)))
+        struct mntent *mnt;
+        while ((mnt = getmntent (mfp)))
           {
             bool bind = hasmntopt (mnt, "bind");
 
@@ -594,7 +589,7 @@ read_file_system_list (bool need_fs_type)
             mtail = &me->me_next;
           }
 
-        if (endmntent (fp) == 0)
+        if (endmntent (mfp) == 0)
           goto free_then_fail;
       }
   }
@@ -603,9 +598,7 @@ read_file_system_list (bool need_fs_type)
 #ifdef MOUNTED_GETMNTINFO       /* Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD */
   {
     struct statfs *fsp;
-    int entries;
-
-    entries = getmntinfo (&fsp, MNT_NOWAIT);
+    int entries = getmntinfo (&fsp, MNT_NOWAIT);
     if (entries < 0)
       return NULL;
     for (; entries-- > 0; fsp++)
@@ -632,9 +625,7 @@ read_file_system_list (bool need_fs_type)
 #ifdef MOUNTED_GETMNTINFO2      /* NetBSD, Minix */
   {
     struct statvfs *fsp;
-    int entries;
-
-    entries = getmntinfo (&fsp, MNT_NOWAIT);
+    int entries = getmntinfo (&fsp, MNT_NOWAIT);
     if (entries < 0)
       return NULL;
     for (; entries-- > 0; fsp++)
@@ -668,7 +659,6 @@ read_file_system_list (bool need_fs_type)
        We therefore get the list of subdirectories of /, and the list
        of all file systems, and match the two lists.  */
 
-    DIR *dirp;
     struct rootdir_entry
       {
         char *name;
@@ -676,16 +666,11 @@ read_file_system_list (bool need_fs_type)
         ino_t ino;
         struct rootdir_entry *next;
       };
-    struct rootdir_entry *rootdir_list;
-    struct rootdir_entry **rootdir_tail;
-    int32 pos;
-    dev_t dev;
-    fs_info fi;
 
     /* All volumes are mounted in the rootfs, directly under /. */
-    rootdir_list = NULL;
-    rootdir_tail = &rootdir_list;
-    dirp = opendir ("/");
+    struct rootdir_entry *rootdir_list = NULL;
+    struct rootdir_entry **rootdir_tail = &rootdir_list;
+    DIR *dirp = opendir ("/");
     if (dirp)
       {
         struct dirent *d;
@@ -725,29 +710,33 @@ read_file_system_list (bool need_fs_type)
       }
     *rootdir_tail = NULL;
 
-    for (pos = 0; (dev = next_dev (&pos)) >= 0; )
-      if (fs_stat_dev (dev, &fi) >= 0)
-        {
-          /* Note: fi.dev == dev. */
-          for (struct rootdir_entry *re = rootdir_list; re; re = re->next)
-            if (re->dev == fi.dev && re->ino == fi.root)
-              break;
-
-          me = xmalloc (sizeof *me);
-          me->me_devname = xstrdup (fi.device_name[0] != '\0'
-                                    ? fi.device_name : fi.fsh_name);
-          me->me_mountdir = xstrdup (re != NULL ? re->name : fi.fsh_name);
-          me->me_mntroot = NULL;
-          me->me_type = xstrdup (fi.fsh_name);
-          me->me_type_malloced = 1;
-          me->me_dev = fi.dev;
-          me->me_dummy = 0;
-          me->me_remote = (fi.flags & B_FS_IS_SHARED) != 0;
-
-          /* Add to the linked list. */
-          *mtail = me;
-          mtail = &me->me_next;
-        }
+    dev_t dev;
+    for (int32 pos = 0; (dev = next_dev (&pos)) >= 0; )
+      {
+        fs_info fi;
+        if (fs_stat_dev (dev, &fi) >= 0)
+          {
+            /* Note: fi.dev == dev. */
+            for (struct rootdir_entry *re = rootdir_list; re; re = re->next)
+              if (re->dev == fi.dev && re->ino == fi.root)
+                break;
+
+            me = xmalloc (sizeof *me);
+            me->me_devname = xstrdup (fi.device_name[0] != '\0'
+                                      ? fi.device_name : fi.fsh_name);
+            me->me_mountdir = xstrdup (re != NULL ? re->name : fi.fsh_name);
+            me->me_mntroot = NULL;
+            me->me_type = xstrdup (fi.fsh_name);
+            me->me_type_malloced = 1;
+            me->me_dev = fi.dev;
+            me->me_dummy = 0;
+            me->me_remote = (fi.flags & B_FS_IS_SHARED) != 0;
+
+            /* Add to the linked list. */
+            *mtail = me;
+            mtail = &me->me_next;
+          }
+      }
     *mtail = NULL;
 
     while (rootdir_list != NULL)
@@ -762,17 +751,15 @@ read_file_system_list (bool need_fs_type)
 
 #if defined MOUNTED_GETFSSTAT   /* (obsolete) Apple Darwin 1.3 */
   {
-    int numsys;
-    size_t bufsize;
-    struct statfs *stats;
 
-    numsys = getfsstat (NULL, 0L, MNT_NOWAIT);
+    int numsys = getfsstat (NULL, 0L, MNT_NOWAIT);
     if (numsys < 0)
       return NULL;
+
+    struct statfs *stats;
     if (SIZE_MAX / sizeof *stats <= numsys)
       xalloc_die ();
-
-    bufsize = (1 + numsys) * sizeof *stats;
+    size_t bufsize = (1 + numsys) * sizeof *stats;
     stats = xmalloc (bufsize);
     numsys = getfsstat (stats, bufsize, MNT_NOWAIT);
 
@@ -805,14 +792,13 @@ read_file_system_list (bool need_fs_type)
 
 #if defined MOUNTED_FREAD_FSTYP /* (obsolete) SVR3 */
   {
-    struct mnttab mnt;
     char *table = "/etc/mnttab";
-    FILE *fp;
 
-    fp = fopen (table, "re");
+    FILE *fp = fopen (table, "re");
     if (fp == NULL)
       return NULL;
 
+    struct mnttab mnt;
     while (fread (&mnt, sizeof mnt, 1, fp) > 0)
       {
         me = xmalloc (sizeof *me);
@@ -858,20 +844,19 @@ read_file_system_list (bool need_fs_type)
 
 #ifdef MOUNTED_GETEXTMNTENT     /* Solaris >= 8 */
   {
-    struct extmnttab mnt;
     const char *table = MNTTAB;
-    FILE *fp;
-    int ret;
 
     /* No locking is needed, because the contents of /etc/mnttab is generated
        by the kernel.  */
 
     errno = 0;
-    fp = fopen (table, "re");
+    FILE *fp = fopen (table, "re");
+    int ret;
     if (fp == NULL)
       ret = errno;
     else
       {
+        struct extmnttab mnt;
         while ((ret = getextmntent (fp, &mnt, 1)) == 0)
           {
             me = xmalloc (sizeof *me);
@@ -905,10 +890,7 @@ read_file_system_list (bool need_fs_type)
 
 #ifdef MOUNTED_GETMNTENT2       /* Solaris < 8, also (obsolete) SVR4 */
   {
-    struct mnttab mnt;
     const char *table = MNTTAB;
-    FILE *fp;
-    int ret;
     int lockfd = -1;
 
 # if defined F_RDLCK && defined F_SETLKW
@@ -941,11 +923,13 @@ read_file_system_list (bool need_fs_type)
 # endif
 
     errno = 0;
-    fp = fopen (table, "re");
+    FILE *fp = fopen (table, "re");
+    int ret;
     if (fp == NULL)
       ret = errno;
     else
       {
+        struct mnttab mnt;
         while ((ret = getmntent (fp, &mnt)) == 0)
           {
             me = xmalloc (sizeof *me);
@@ -980,34 +964,24 @@ read_file_system_list (bool need_fs_type)
 
 #ifdef MOUNTED_VMOUNT           /* AIX */
   {
-    int bufsize;
-    void *entries;
-    char *thisent;
-    struct vmount *vmp;
-    int n_entries;
-    int i;
-
     /* Ask how many bytes to allocate for the mounted file system info.  */
-    entries = &bufsize;
-    if (mntctl (MCTL_QUERY, sizeof bufsize, entries) != 0)
+    int bufsize;
+    if (mntctl (MCTL_QUERY, sizeof bufsize, &bufsize) != 0)
       return NULL;
-    entries = xmalloc (bufsize);
+    void *entries = xmalloc (bufsize);
 
     /* Get the list of mounted file systems.  */
-    n_entries = mntctl (MCTL_QUERY, bufsize, entries);
+    int n_entries = mntctl (MCTL_QUERY, bufsize, entries);
     if (n_entries < 0)
       {
         free (entries);
         return NULL;
       }
 
-    for (i = 0, thisent = entries;
-         i < n_entries;
-         i++, thisent += vmp->vmt_length)
+    char *thisent = entries;
+    for (int i = 0; i < n_entries; i++)
       {
-        char *options, *ignore;
-
-        vmp = (struct vmount *) thisent;
+        struct vmount *vmp = (struct vmount *) thisent;
         me = xmalloc (sizeof *me);
         if (vmp->vmt_flags & MNT_REMOTE)
           {
@@ -1032,8 +1006,8 @@ read_file_system_list (bool need_fs_type)
         me->me_mntroot = NULL;
         me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype));
         me->me_type_malloced = 1;
-        options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off;
-        ignore = strstr (options, "ignore");
+        char *options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off;
+        char *ignore = strstr (options, "ignore");
         me->me_dummy = (ignore
                         && (ignore == options || ignore[-1] == ',')
                         && (ignore[sizeof "ignore" - 1] == ','
@@ -1043,6 +1017,8 @@ read_file_system_list (bool need_fs_type)
         /* Add to the linked list. */
         *mtail = me;
         mtail = &me->me_next;
+
+        thisent += vmp->vmt_length;
       }
     free (entries);
   }
@@ -1051,25 +1027,23 @@ read_file_system_list (bool need_fs_type)
 #ifdef MOUNTED_INTERIX_STATVFS  /* Interix */
   {
     DIR *dirp = opendir ("/dev/fs");
-    char node[9 + NAME_MAX];
-
     if (!dirp)
       goto free_then_fail;
 
     while (1)
       {
-        struct statvfs dev;
-        struct dirent entry;
-        struct dirent *result;
-
         /* FIXME: readdir_r is planned to be withdrawn from POSIX and
            marked obsolescent in glibc.  Use readdir instead.  */
+        struct dirent entry;
+        struct dirent *result;
         if (readdir_r (dirp, &entry, &result) || result == NULL)
           break;
 
+        char node[9 + NAME_MAX];
         strcpy (node, "/dev/fs/");
         strcat (node, entry.d_name);
 
+        struct statvfs dev;
         if (statvfs (node, &dev) == 0)
           {
             me = xmalloc (sizeof *me);
@@ -1109,11 +1083,12 @@ read_file_system_list (bool need_fs_type)
         if (value & (1U << i))
           {
             char mountdir[4];
-            char fs_name[MAX_PATH + 1];
             mountdir[0] = 'A' + i;
             mountdir[1] = ':';
             mountdir[2] = '\\';
             mountdir[3] = '\0';
+
+            char fs_name[MAX_PATH + 1];
             /* Test whether the drive actually exists, and
                get the name of the file system.  See:
                <https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumeinformationa>.  */
@@ -1136,10 +1111,10 @@ read_file_system_list (bool need_fs_type)
                      For testing of SUBST:   <https://ss64.com/nt/subst.html>
                      For testing of NET USE: <https://ss64.com/nt/net-use.html>  */
                   wchar_t drive[3];
-                  wchar_t mapping[MAX_PATH + 1];
                   drive[0] = L'A' + i;
                   drive[1] = L':';
                   drive[2] = L'\0';
+                  wchar_t mapping[MAX_PATH + 1];
                   DWORD mapping_len = QueryDosDeviceW (drive, mapping, sizeof (mapping) / sizeof (mapping[0]));
                   if (mapping_len > 4 && wcsncmp (mapping, L"\\??\\", 4) == 0)
                     {
index 76b7598600a61a6136448085ed28a07f5db45a4d..f44c7f56776cf0818a90dd39c5115aba8f4bffad 100644 (file)
@@ -44,14 +44,12 @@ mpsort_into_tmp (void const **restrict base, size_t n,
   size_t alim = n1;
   size_t b = n1;
   size_t blim = n;
-  void const *ba;
-  void const *bb;
 
   mpsort_with_tmp (base + n1, n2, tmp, cmp);
   mpsort_with_tmp (base, n1, tmp, cmp);
 
-  ba = base[a];
-  bb = base[b];
+  void const *ba = base[a];
+  void const *bb = base[b];
 
   for (;;)
     if (cmp (ba, bb) <= 0)
@@ -108,8 +106,6 @@ mpsort_with_tmp (void const **restrict base, size_t n,
       size_t tlim = n1;
       size_t b = n1;
       size_t blim = n;
-      void const *bb;
-      void const *tt;
 
       mpsort_with_tmp (base + n1, n2, tmp, cmp);
 
@@ -118,8 +114,8 @@ mpsort_with_tmp (void const **restrict base, size_t n,
       else
         mpsort_into_tmp (base, n1, tmp, cmp);
 
-      tt = tmp[t];
-      bb = base[b];
+      void const *tt = tmp[t];
+      void const *bb = base[b];
 
       for (size_t i = 0; ; )
         if (cmp (tt, bb) <= 0)
index 9bb8a15638d9b8a82a52b3b25c98dd7aebe35124..57dbe28a5cfeb6babaa653225966b2e81f809440 100644 (file)
@@ -179,9 +179,9 @@ extern struct gl_msvc_inval_per_thread *gl_msvc_inval_current (void);
 #   define TRY_MSVC_INVAL \
       do                                                                       \
         {                                                                      \
-          struct gl_msvc_inval_per_thread *msvc_inval_current;                 \
           gl_msvc_inval_ensure_handler ();                                     \
-          msvc_inval_current = gl_msvc_inval_current ();                       \
+          struct gl_msvc_inval_per_thread *msvc_inval_current =                \
+            gl_msvc_inval_current ();                                          \
           /* First, initialize gl_msvc_inval_restart.  */                      \
           if (setjmp (msvc_inval_current->restart) == 0)                       \
             {                                                                  \
index 6c3edd23b0ea288d9231260e6fd74a0187b7e668..72e3467501259103187fa50e0d6c0543c6328ff8 100644 (file)
--- a/lib/mtx.c
+++ b/lib/mtx.c
@@ -207,26 +207,32 @@ mtx_init (mtx_t *mutex, int type)
   if ((type & mtx_recursive) != 0)
     {
       pthread_mutexattr_t attributes;
-      int err;
-
-      err = pthread_mutexattr_init (&attributes);
-      if (err != 0)
-        return thrd_error;
-      err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE);
-      if (err != 0)
-        {
-          pthread_mutexattr_destroy (&attributes);
+      {
+        int err = pthread_mutexattr_init (&attributes);
+        if (err != 0)
           return thrd_error;
-        }
-      err = pthread_mutex_init (mutex, &attributes);
-      if (err != 0)
-        {
-          pthread_mutexattr_destroy (&attributes);
+      }
+      {
+        int err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE);
+        if (err != 0)
+          {
+            pthread_mutexattr_destroy (&attributes);
+            return thrd_error;
+          }
+      }
+      {
+        int err = pthread_mutex_init (mutex, &attributes);
+        if (err != 0)
+          {
+            pthread_mutexattr_destroy (&attributes);
+            return thrd_error;
+          }
+      }
+      {
+        int err = pthread_mutexattr_destroy (&attributes);
+        if (err != 0)
           return thrd_error;
-        }
-      err = pthread_mutexattr_destroy (&attributes);
-      if (err != 0)
-        return thrd_error;
+      }
     }
   else
     {
index cfafa4e37e18849efacaab3ba0877be609544d2a..904680c76f56d3a463165a5544b2be38edae2a62 100644 (file)
@@ -64,9 +64,8 @@ nanosleep (const struct timespec *requested_delay,
 
     while (limit < seconds)
       {
-        int result;
         intermediate.tv_sec = limit;
-        result = nanosleep (&intermediate, remaining_delay);
+        int result = nanosleep (&intermediate, remaining_delay);
         seconds -= limit;
         if (result)
           {
index f575c256c6169000cba2705e4c14c7d45c27c52b..db7b7556f161f51045a229c6190264d779b7a98b 100644 (file)
@@ -79,15 +79,13 @@ ctype_codeset (void)
   /* This function is only used on platforms which don't have uselocale().
      Therefore we don't need to look at the per-thread locale first, here.  */
   static char result[2 + 10 + 1];
-  char buf[2 + 10 + 1];
-  char locale[SETLOCALE_NULL_MAX];
-  char *codeset;
-  size_t codesetlen;
 
+  char locale[SETLOCALE_NULL_MAX];
   if (setlocale_null_r (LC_CTYPE, locale, sizeof (locale)))
     locale[0] = '\0';
 
-  codeset = buf;
+  char buf[2 + 10 + 1];
+  char *codeset = buf;
   codeset[0] = '\0';
 
   if (locale[0])
@@ -105,7 +103,7 @@ ctype_codeset (void)
             codeset = codeset_start;
           else
             {
-              codesetlen = modifier - codeset_start;
+              size_t codesetlen = modifier - codeset_start;
               if (codesetlen < sizeof buf)
                 {
                   codeset = memcpy (buf, codeset_start, codesetlen);
@@ -121,7 +119,7 @@ ctype_codeset (void)
      GetACP, which returns the locale's codepage as a number (although
      this doesn't change according to what the 'setlocale' call specified).
      Either way, prepend "CP" to make it a valid codeset name.  */
-  codesetlen = strlen (codeset);
+  size_t codesetlen = strlen (codeset);
   if (0 < codesetlen && codesetlen < sizeof buf - 2)
     memmove (buf + 2, codeset, codesetlen + 1);
   else
@@ -209,10 +207,9 @@ static char *
 nl_langinfo_with_lock (nl_item item)
 {
   CRITICAL_SECTION *lock = gl_get_nl_langinfo_lock ();
-  char *ret;
 
   EnterCriticalSection (lock);
-  ret = nl_langinfo_unlocked (item);
+  char *ret = nl_langinfo_unlocked (item);
   LeaveCriticalSection (lock);
 
   return ret;
@@ -248,11 +245,10 @@ nl_langinfo_with_lock (nl_item item)
   if (pthread_in_use())
     {
       pthread_mutex_t *lock = gl_get_nl_langinfo_lock ();
-      char *ret;
 
       if (pthread_mutex_lock (lock))
         abort ();
-      ret = nl_langinfo_unlocked (item);
+      char *ret = nl_langinfo_unlocked (item);
       if (pthread_mutex_unlock (lock))
         abort ();
 
@@ -270,11 +266,10 @@ static char *
 nl_langinfo_with_lock (nl_item item)
 {
   mtx_t *lock = gl_get_nl_langinfo_lock ();
-  char *ret;
 
   if (mtx_lock (lock) != thrd_success)
     abort ();
-  ret = nl_langinfo_unlocked (item);
+  char *ret = nl_langinfo_unlocked (item);
   if (mtx_unlock (lock) != thrd_success)
     abort ();
 
index c03cab72614c8e7ee56f3eeab9f7057a44d4b3a5..2e2d321e9982352a3731b07c6871f1934b218aa9 100644 (file)
@@ -135,9 +135,7 @@ set_nonblocking_flag (int desc, bool value)
 int
 get_nonblocking_flag (int desc)
 {
-  int fcntl_flags;
-
-  fcntl_flags = fcntl (desc, F_GETFL, 0);
+  int fcntl_flags = fcntl (desc, F_GETFL, 0);
   if (fcntl_flags < 0)
     return -1;
   return (fcntl_flags & O_NONBLOCK) != 0;
@@ -146,9 +144,7 @@ get_nonblocking_flag (int desc)
 int
 set_nonblocking_flag (int desc, bool value)
 {
-  int fcntl_flags;
-
-  fcntl_flags = fcntl (desc, F_GETFL, 0);
+  int fcntl_flags = fcntl (desc, F_GETFL, 0);
   if (fcntl_flags < 0)
     return -1;
   if (((fcntl_flags & O_NONBLOCK) != 0) == value)
index 1cccfc56065b879f7f22c96aad4531ab11ee97dd..75adbbdc42e3814e34343b8d60d8ca4ba4640671 100644 (file)
@@ -100,9 +100,7 @@ num_processors_via_affinity_mask (void)
   }
 #elif HAVE_PTHREAD_GETAFFINITY_NP && defined __NetBSD__ && 0
   {
-    cpuset_t *set;
-
-    set = cpuset_create ();
+    cpuset_t *set = cpuset_create ();
     if (set != NULL)
       {
         unsigned long count = 0;
@@ -187,9 +185,7 @@ num_processors_via_affinity_mask (void)
   }
 #elif HAVE_SCHED_GETAFFINITY_NP /* NetBSD >= 5 */
   {
-    cpuset_t *set;
-
-    set = cpuset_create ();
+    cpuset_t *set = cpuset_create ();
     if (set != NULL)
       {
         unsigned long count = 0;
@@ -370,18 +366,19 @@ num_processors_available (enum nproc_query query)
 static char *
 cgroup2_mount (void)
 {
-  FILE *fp;
-  char *ret = NULL;
 
   /* Check the usual location first.  */
   if (access ("/sys/fs/cgroup/cgroup.controllers", F_OK) == 0)
     return strdup ("/sys/fs/cgroup");
 
+  char *ret = NULL;
+
 #if HAVE_SETMNTENT
   /* Otherwise look for the mount point.  */
-  struct mntent *mnt;
-  if (! (fp = setmntent ("/proc/mounts", "r")))
+  FILE *fp = setmntent ("/proc/mounts", "r");
+  if (! fp)
     return NULL;
+  struct mntent *mnt;
   while ((mnt = getmntent (fp)) != NULL)
     {
       if (streq (mnt->mnt_type, "cgroup2"))
@@ -403,9 +400,8 @@ static unsigned long int
 get_cgroup2_cpu_quota (void)
 {
   unsigned long int cpu_quota = ULONG_MAX;
-  FILE *fp;
 
-  fp = fopen ("/proc/self/cgroup", "r");
+  FILE *fp = fopen ("/proc/self/cgroup", "r");
   if (! fp)
     return cpu_quota;
 
@@ -518,10 +514,8 @@ cpu_quota (void)
 static unsigned long int
 parse_omp_threads (char const* threads)
 {
-  unsigned long int ret = 0;
-
   if (threads == NULL)
-    return ret;
+    return 0;
 
   /* The OpenMP spec says that the value assigned to the environment variables
      "may have leading and trailing white space".  */
@@ -543,7 +537,7 @@ parse_omp_threads (char const* threads)
         return value;
     }
 
-  return ret;
+  return 0;
 }
 
 unsigned long int
@@ -555,9 +549,11 @@ num_processors (enum nproc_query query)
      programs that are based on OpenMP.  */
   if (query == NPROC_CURRENT_OVERRIDABLE)
     {
-      unsigned long int omp_env_threads, omp_env_limit;
-      omp_env_threads = parse_omp_threads (getenv ("OMP_NUM_THREADS"));
-      omp_env_limit = parse_omp_threads (getenv ("OMP_THREAD_LIMIT"));
+      unsigned long int omp_env_threads =
+        parse_omp_threads (getenv ("OMP_NUM_THREADS"));
+
+      unsigned long int omp_env_limit =
+        parse_omp_threads (getenv ("OMP_THREAD_LIMIT"));
       if (! omp_env_limit)
         omp_env_limit = ULONG_MAX;
 
index fed3f6f71109acab60ae0726741bd570a48a7781..5ba0e07ee7fd437451e1e5c871aa4ffdd16f7cdc 100644 (file)
@@ -194,9 +194,7 @@ void
 _obstack_newchunk (struct obstack *h, _OBSTACK_INDEX_T length)
 {
   struct _obstack_chunk *old_chunk = h->chunk;
-  struct _obstack_chunk *new_chunk;
   size_t obj_size = h->next_free - h->object_base;
-  char *object_base;
 
   /* Compute size for new chunk.  */
   _OBSTACK_CHUNK_SIZE_T s, new_size;
@@ -212,7 +210,8 @@ _obstack_newchunk (struct obstack *h, _OBSTACK_INDEX_T length)
     new_size = h->chunk_size;
 
   /* Allocate and initialize the new chunk.  */
-  new_chunk = v ? NULL : call_chunkfun (h, new_size);
+  struct _obstack_chunk *new_chunk =
+    v ? NULL : call_chunkfun (h, new_size);
   if (!new_chunk)
     (*obstack_alloc_failed_handler)();
   h->chunk = new_chunk;
@@ -223,7 +222,7 @@ _obstack_newchunk (struct obstack *h, _OBSTACK_INDEX_T length)
                  h->alignment_mask);
 
   /* Compute an aligned object_base in the new chunk */
-  object_base =
+  char *object_base =
     __PTR_ALIGN ((char *) new_chunk, new_chunk->contents, h->alignment_mask);
 
   /* Move the existing object to the new chunk.  */
@@ -259,16 +258,14 @@ int _obstack_allocated_p (struct obstack *h, void *obj) __attribute_pure__;
 int
 _obstack_allocated_p (struct obstack *h, void *obj)
 {
-  struct _obstack_chunk *lp;    /* below addr of any objects in this chunk */
-  struct _obstack_chunk *plp;   /* point to previous chunk if any */
-
-  lp = (h)->chunk;
+  struct _obstack_chunk *lp = /* below addr of any objects in this chunk */
+    h->chunk;
   /* We use >= rather than > since the object cannot be exactly at
      the beginning of the chunk but might be an empty object exactly
      at the end of an adjacent chunk.  */
   while (lp != NULL && ((void *) lp >= obj || (void *) (lp)->limit < obj))
     {
-      plp = lp->prev;
+      struct _obstack_chunk *plp = lp->prev; /* point to previous chunk */
       lp = plp;
     }
   return lp != NULL;
@@ -280,16 +277,14 @@ _obstack_allocated_p (struct obstack *h, void *obj)
 void
 __obstack_free (struct obstack *h, void *obj)
 {
-  struct _obstack_chunk *lp;    /* below addr of any objects in this chunk */
-  struct _obstack_chunk *plp;   /* point to previous chunk if any */
-
-  lp = h->chunk;
+  struct _obstack_chunk *lp = /* below addr of any objects in this chunk */
+    h->chunk;
   /* We use >= because there cannot be an object at the beginning of a chunk.
      But there can be an empty object at that address
      at the end of another chunk.  */
   while (lp != NULL && ((void *) lp >= obj || (void *) (lp)->limit < obj))
     {
-      plp = lp->prev;
+      struct _obstack_chunk *plp = lp->prev; /* point to previous chunk */
       call_freefun (h, lp);
       lp = plp;
       /* If we switch chunks, we can't tell whether the new current
index 03e22e6fcbd09d09ac29cb66ece414aae135c8e2..6e9f09b2a6c67f8e9b3d70f3b123135d8884c5c2 100644 (file)
@@ -42,10 +42,8 @@ RESULT_TYPE
 OBSTACK_PRINTF (struct obstack *obs, const char *format, ...)
 {
   va_list args;
-  RESULT_TYPE result;
-
   va_start (args, format);
-  result = OBSTACK_VPRINTF (obs, format, args);
+  RESULT_TYPE result = OBSTACK_VPRINTF (obs, format, args);
   va_end (args);
   return result;
 }
@@ -67,14 +65,13 @@ OBSTACK_VPRINTF (struct obstack *obs, const char *format, va_list args)
   char buf[CUTOFF];
   char *base = obstack_next_free (obs);
   size_t len = obstack_room (obs);
-  char *str;
 
   if (len < CUTOFF)
     {
       base = buf;
       len = CUTOFF;
     }
-  str = vasnprintf (base, &len, format, args);
+  char *str = vasnprintf (base, &len, format, args);
   if (!str)
     {
       if (errno == ENOMEM)
index b72bec9f238c5adb70b8eb3459e9fa04b3a62541..829dea339274dc3bc6370989c002538eb2dbac14 100644 (file)
 static unsigned long int
 parse_omp_threads (char const* threads)
 {
-  unsigned long int ret = 0;
-
   if (threads == NULL)
-    return ret;
+    return 0;
 
   /* The OpenMP spec says that the value assigned to the environment variables
      "may have leading and trailing white space".  */
@@ -56,7 +54,7 @@ parse_omp_threads (char const* threads)
         return value;
     }
 
-  return ret;
+  return 0;
 }
 
 #endif
index a333a3f8785bd7ac21b0deaa92434168e7ffa8e7..39854c12384513716f40871c788ec88a996cdd5d 100644 (file)
@@ -46,9 +46,6 @@
 char *
 openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file)
 {
-  char *result = buf;
-  int dirlen;
-
   /* Make sure the caller gets ENOENT when appropriate.  */
   if (!*file)
     {
@@ -56,6 +53,9 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file)
       return buf;
     }
 
+  char *result = buf;
+  int dirlen;
+
 #if !(defined __KLIBC__ || defined __MVS__)
   /* Generic code for Linux, Solaris, and similar platforms.  */
 # define PROC_SELF_FD_FORMAT "/proc/self/fd/%d/"
index bfa2a8ee7f197dcc3a8ec412b819fd2e0dd85669..51a490352c7b5f385e7ee860240951e0985f85ae 100644 (file)
@@ -174,8 +174,6 @@ do_openat2 (int *fd, char const *filename,
             int flags, char resolve, mode_t mode,
             char **buf, idx_t bufsize)
 {
-  int dfd = *fd;
-
   /* RESOLVED_CACHED cannot be implemented properly in user space,
      so pretend nothing is cached.  */
   if (resolve & RESOLVE_CACHED)
@@ -212,6 +210,8 @@ do_openat2 (int *fd, char const *filename,
 
   long int maxlinks = resolve & RESOLVE_NO_SYMLINKS ? 0 : __eloop_threshold ();
 
+  int dfd = *fd;
+
   /* Iterates through file name components, possibly expanded by
      symlink contents.  */
   while (true)
@@ -498,12 +498,12 @@ int
 openat2 (int dfd, char const *filename,
          struct open_how const *how, size_t howsize)
 {
-  int r;
-
 #ifdef SYS_openat2
-  r = syscall (SYS_openat2, dfd, filename, how, howsize);
-  if (! (r < 0 && errno == ENOSYS))
-    return r;
+  {
+    int r = syscall (SYS_openat2, dfd, filename, how, howsize);
+    if (! (r < 0 && errno == ENOSYS))
+      return r;
+  }
 
   /* Keep going, to support the dubious practice of compiling for an
      older kernel.  The openat2 syscall was introduced in Linux 5.6.
@@ -511,6 +511,8 @@ openat2 (int dfd, char const *filename,
      we can simply return the syscall result instead of continuing.  */
 #endif
 
+  int r;
+
   /* Check for invalid arguments.  Once the size test has succeeded,
      *HOW's members are safe to access, so use & and | as there is
      little point to using && or || when invalid arguments are rare.
@@ -557,13 +559,11 @@ openat2 (int dfd, char const *filename,
       char resolve = how->resolve;
       mode_t mode = how->mode;
 
-      int fd;
-
       /* For speed use a single openat if it suffices.  */
       if (O_RESOLVE_BENEATH ? !(resolve & ~RESOLVE_BENEATH) : !resolve)
         {
-          fd = openat (dfd, filename,
-                       flags | (resolve ? O_RESOLVE_BENEATH : 0), mode);
+          int fd = openat (dfd, filename,
+                           flags | (resolve ? O_RESOLVE_BENEATH : 0), mode);
 
           /* Return FD now unless openat failed with an errno that might
              be an O_RESOLVE_BENEATH failure.  On platforms with
@@ -574,7 +574,7 @@ openat2 (int dfd, char const *filename,
             return fd;
         }
 
-      fd = dfd;
+      int fd = dfd;
       char stackbuf[256];
       char *buf = stackbuf;
 
index a121e1befa5996710cf532747520082e529909d1..fb3db0501ef2ed3cc08a73ab6190e76c80288fa9 100644 (file)
@@ -90,12 +90,6 @@ opendir (const char *dir_name)
 
 #else
 
-  char dir_name_mask[MAX_PATH + 1 + 1 + 1];
-  int status;
-  HANDLE current;
-  WIN32_FIND_DATA entry;
-  struct gl_directory *dirp;
-
   if (dir_name[0] == '\0')
     {
       errno = ENOENT;
@@ -105,6 +99,7 @@ opendir (const char *dir_name)
   /* Make the dir_name absolute, so that we continue reading the same
      directory if the current directory changed between this opendir()
      call and a subsequent rewinddir() call.  */
+  char dir_name_mask[MAX_PATH + 1 + 1 + 1];
   if (!GetFullPathName (dir_name, MAX_PATH, dir_name_mask, NULL))
     {
       errno = EINVAL;
@@ -124,8 +119,9 @@ opendir (const char *dir_name)
   }
 
   /* Start searching the directory.  */
-  status = -1;
-  current = FindFirstFile (dir_name_mask, &entry);
+  int status = -1;
+  WIN32_FIND_DATA entry;
+  HANDLE current = FindFirstFile (dir_name_mask, &entry);
   if (current == INVALID_HANDLE_VALUE)
     {
       switch (GetLastError ())
@@ -149,7 +145,7 @@ opendir (const char *dir_name)
     }
 
   /* Allocate the result.  */
-  dirp =
+  struct gl_directory *dirp =
     (struct gl_directory *)
     malloc (offsetof (struct gl_directory, dir_name_mask[0])
             + strlen (dir_name_mask) + 1);
index 0d6f80f40b14ad1dcef8a1386407d45284de355b..913661353be475694bfe1a93f504928765981839 100644 (file)
@@ -63,12 +63,8 @@ int
 openpty (int *amaster, int *aslave, char *name,
          struct termios const *termp, struct winsize const *winp)
 {
-  int master;
-  char *slave_name;
-  int slave;
-
   /* This call uses the 'posix_openpt' module.  */
-  master = posix_openpt (O_RDWR | O_NOCTTY);
+  int master = posix_openpt (O_RDWR | O_NOCTTY);
   if (master < 0)
     return -1;
 
@@ -82,11 +78,11 @@ openpty (int *amaster, int *aslave, char *name,
   if (unlockpt (master))
     goto fail;
 
-  slave_name = ptsname (master);
+  char *slave_name = ptsname (master);
   if (slave_name == NULL)
     goto fail;
 
-  slave = open (slave_name, O_RDWR | O_NOCTTY);
+  int slave = open (slave_name, O_RDWR | O_NOCTTY);
   if (slave == -1)
     goto fail;
 
index 97a13aebf5c6358fe2e3cc20ad69dc0574a15dde..ce587d21f5c8b3662e774f7fdd7456f1a8cda78f 100644 (file)
@@ -100,15 +100,14 @@ undup_safer_noinherit (int tempfd, int origfd)
 const char **
 prepare_spawn (const char * const *argv, char **mem_to_free)
 {
-  size_t argc;
-  const char **new_argv;
-
   /* Count number of arguments.  */
+  size_t argc;
   for (argc = 0; argv[argc] != NULL; argc++)
     ;
 
   /* Allocate new argument vector.  */
-  new_argv = (const char **) malloc ((1 + argc + 1) * sizeof (const char *));
+  const char **new_argv =
+    (const char **) malloc ((1 + argc + 1) * sizeof (const char *));
   if (new_argv == NULL)
     return NULL;
 
@@ -175,11 +174,6 @@ spawnpvech (int mode,
   static int libcx_spawn2_loaded = 0;
 #endif
 
-  int saved_stdin = STDIN_FILENO;
-  int saved_stdout = STDOUT_FILENO;
-  int saved_stderr = STDERR_FILENO;
-  int ret = -1;
-
 #if HAVE_LIBCX_SPAWN2_H
   if (libcx_spawn2_loaded == -1)
     {
@@ -202,15 +196,19 @@ spawnpvech (int mode,
 
   /* Save standard file handles.  */
   /* 0 means no changes. This is a behavior of spawn2().  */
+  int saved_stdin = STDIN_FILENO;
   if (new_stdin != 0)
     saved_stdin = dup_safer_noinherit (STDIN_FILENO);
 
+  int saved_stdout = STDOUT_FILENO;
   if (!(new_stdout == 0 || new_stdout == 1))
     saved_stdout = dup_safer_noinherit (STDOUT_FILENO);
 
+  int saved_stderr = STDERR_FILENO;
   if (!(new_stderr == 0 || new_stderr == 2))
     saved_stderr = dup_safer_noinherit (STDERR_FILENO);
 
+  int ret = -1;
   if ((saved_stdin == STDIN_FILENO || dup2 (new_stdin, STDIN_FILENO) >= 0)
       && (saved_stdout == STDOUT_FILENO
           || dup2 (new_stdout, STDOUT_FILENO) >= 0)
index b730cceabd4937a54dc1368da1aec83b79347628..9abbf441dcc1483e718fe722bfd8f5e914e2068d 100644 (file)
@@ -119,13 +119,11 @@ get_default_impl (void)
 void *
 pagealign_alloc (size_t size)
 {
-  void *ret;
-  pagealign_impl_t impl;
-
-  impl = pagealign_impl;
+  pagealign_impl_t impl = pagealign_impl;
   if (impl == PA_IMPL_DEFAULT)
     impl = get_default_impl ();
 
+  void *ret;
   switch (impl)
     {
     case PA_IMPL_MALLOC:
@@ -216,9 +214,7 @@ pagealign_alloc (size_t size)
 void *
 pagealign_xalloc (size_t size)
 {
-  void *ret;
-
-  ret = pagealign_alloc (size);
+  void *ret = pagealign_alloc (size);
   if (ret == NULL)
     xalloc_die ();
   return ret;
@@ -228,9 +224,7 @@ pagealign_xalloc (size_t size)
 void
 pagealign_free (void *aligned_ptr)
 {
-  pagealign_impl_t impl;
-
-  impl = pagealign_impl;
+  pagealign_impl_t impl = pagealign_impl;
   if (impl == PA_IMPL_DEFAULT)
     impl = get_default_impl ();
 
index 7b750da824b81b4362b05d382a193ff15d82036a..1c53959740a8dc050fc21c10062a2ce347ef39b9 100644 (file)
@@ -155,13 +155,12 @@ static time_t
 parse_scaled_value (time_t base, cch_t ** ppz, cch_t * endp, int scale)
 {
   cch_t * pz = *ppz;
-  time_t val;
 
   if (base == BAD_TIME)
     return base;
 
   errno = 0;
-  val = str_const_to_ul (pz, &pz, 10);
+  time_t val = str_const_to_ul (pz, &pz, 10);
   if (errno != 0)
     return BAD_TIME;
   while (isspace ((unsigned char)*pz))
@@ -181,9 +180,7 @@ parse_scaled_value (time_t base, cch_t ** ppz, cch_t * endp, int scale)
 static time_t
 parse_year_month_day (cch_t * pz, cch_t * ps)
 {
-  time_t res = 0;
-
-  res = parse_scaled_value (0, &pz, ps, SEC_PER_YEAR);
+  time_t res = parse_scaled_value (0, &pz, ps, SEC_PER_YEAR);
 
   pz++; /* over the first '-' */
   ps = strchr (pz, '-');
@@ -203,20 +200,18 @@ parse_year_month_day (cch_t * pz, cch_t * ps)
 static time_t
 parse_yearmonthday (cch_t * in_pz)
 {
-  time_t res = 0;
-  char   buf[8];
-  cch_t * pz;
-
   if (strlen (in_pz) != 8)
     {
       errno = EINVAL;
       return BAD_TIME;
     }
 
+  char buf[8];
+
   memcpy (buf, in_pz, 4);
   buf[4] = NUL;
-  pz = buf;
-  res = parse_scaled_value (0, &pz, buf + 4, SEC_PER_YEAR);
+  cch_t *pz = buf;
+  time_t res = parse_scaled_value (0, &pz, buf + 4, SEC_PER_YEAR);
 
   memcpy (buf, in_pz + 4, 2);
   buf[2] = NUL;
@@ -234,33 +229,39 @@ static time_t
 parse_YMWD (cch_t * pz)
 {
   time_t res = 0;
-  cch_t * ps = strchr (pz, 'Y');
-  if (ps != NULL)
-    {
-      res = parse_scaled_value (0, &pz, ps, SEC_PER_YEAR);
-      pz++;
-    }
 
-  ps = strchr (pz, 'M');
-  if (ps != NULL)
-    {
-      res = parse_scaled_value (res, &pz, ps, SEC_PER_MONTH);
-      pz++;
-    }
-
-  ps = strchr (pz, 'W');
-  if (ps != NULL)
-    {
-      res = parse_scaled_value (res, &pz, ps, SEC_PER_WEEK);
-      pz++;
-    }
-
-  ps = strchr (pz, 'D');
-  if (ps != NULL)
-    {
-      res = parse_scaled_value (res, &pz, ps, SEC_PER_DAY);
-      pz++;
-    }
+  {
+    cch_t *ps = strchr (pz, 'Y');
+    if (ps != NULL)
+      {
+        res = parse_scaled_value (0, &pz, ps, SEC_PER_YEAR);
+        pz++;
+      }
+  }
+  {
+    cch_t *ps = strchr (pz, 'M');
+    if (ps != NULL)
+      {
+        res = parse_scaled_value (res, &pz, ps, SEC_PER_MONTH);
+        pz++;
+      }
+  }
+  {
+    cch_t *ps = strchr (pz, 'W');
+    if (ps != NULL)
+      {
+        res = parse_scaled_value (res, &pz, ps, SEC_PER_WEEK);
+        pz++;
+      }
+  }
+  {
+    cch_t *ps = strchr (pz, 'D');
+    if (ps != NULL)
+      {
+        res = parse_scaled_value (res, &pz, ps, SEC_PER_DAY);
+        pz++;
+      }
+  }
 
   while (isspace ((unsigned char)*pz))
     pz++;
@@ -278,9 +279,7 @@ parse_YMWD (cch_t * pz)
 static time_t
 parse_hour_minute_second (cch_t * pz, cch_t * ps)
 {
-  time_t res = 0;
-
-  res = parse_scaled_value (0, &pz, ps, SEC_PER_HR);
+  time_t res = parse_scaled_value (0, &pz, ps, SEC_PER_HR);
 
   pz++;
   ps = strchr (pz, ':');
@@ -301,29 +300,27 @@ parse_hour_minute_second (cch_t * pz, cch_t * ps)
 static time_t
 parse_hourminutesecond (cch_t * in_pz)
 {
-  time_t res = 0;
-  char   buf[4];
-  cch_t * pz;
-
   if (strlen (in_pz) != 6)
     {
       errno = EINVAL;
       return BAD_TIME;
     }
 
+  char buf[4];
+
   memcpy (buf, in_pz, 2);
   buf[2] = NUL;
-  pz = buf;
-  res = parse_scaled_value (0, &pz, buf + 2, SEC_PER_HR);
+  cch_t *pz = buf;
+  time_t res = parse_scaled_value (0, &pz, buf + 2, SEC_PER_HR);
 
   memcpy (buf, in_pz + 2, 2);
   buf[2] = NUL;
-  pz =   buf;
+  pz = buf;
   res = parse_scaled_value (res, &pz, buf + 2, SEC_PER_MIN);
 
   memcpy (buf, in_pz + 4, 2);
   buf[2] = NUL;
-  pz =   buf;
+  pz = buf;
   return parse_scaled_value (res, &pz, buf + 2, 1);
 }
 
@@ -332,26 +329,31 @@ static time_t
 parse_HMS (cch_t * pz)
 {
   time_t res = 0;
-  cch_t * ps = strchr (pz, 'H');
-  if (ps != NULL)
-    {
-      res = parse_scaled_value (0, &pz, ps, SEC_PER_HR);
-      pz++;
-    }
 
-  ps = strchr (pz, 'M');
-  if (ps != NULL)
-    {
-      res = parse_scaled_value (res, &pz, ps, SEC_PER_MIN);
-      pz++;
-    }
-
-  ps = strchr (pz, 'S');
-  if (ps != NULL)
-    {
-      res = parse_scaled_value (res, &pz, ps, 1);
-      pz++;
-    }
+  {
+    cch_t *ps = strchr (pz, 'H');
+    if (ps != NULL)
+      {
+        res = parse_scaled_value (0, &pz, ps, SEC_PER_HR);
+        pz++;
+      }
+  }
+  {
+    cch_t *ps = strchr (pz, 'M');
+    if (ps != NULL)
+      {
+        res = parse_scaled_value (res, &pz, ps, SEC_PER_MIN);
+        pz++;
+      }
+  }
+  {
+    cch_t *ps = strchr (pz, 'S');
+    if (ps != NULL)
+      {
+        res = parse_scaled_value (res, &pz, ps, 1);
+        pz++;
+      }
+  }
 
   while (isspace ((unsigned char)*pz))
     pz++;
@@ -368,13 +370,12 @@ parse_HMS (cch_t * pz)
 static time_t
 parse_time (cch_t * pz)
 {
-  cch_t * ps;
   time_t  res;
 
   /*
    *  Scan for a hyphen
    */
-  ps = strchr (pz, ':');
+  cch_t *ps = strchr (pz, ':');
   if (ps != NULL)
     {
       res = parse_hour_minute_second (pz, ps);
@@ -422,11 +423,7 @@ trim (char * pz)
 static time_t
 parse_period (cch_t * in_pz)
 {
-  char * pT;
-  char * ps;
-  char * pz   = strdup (in_pz);
-  void * fptr = pz;
-  time_t res  = 0;
+  char *pz = strdup (in_pz);
 
   if (pz == NULL)
     {
@@ -434,7 +431,9 @@ parse_period (cch_t * in_pz)
       return BAD_TIME;
     }
 
-  pT = strchr (pz, 'T');
+  void * fptr = pz;
+
+  char *pT = strchr (pz, 'T');
   if (pT != NULL)
     {
       *(pT++) = NUL;
@@ -442,10 +441,12 @@ parse_period (cch_t * in_pz)
       pT = trim (pT);
     }
 
+  time_t res;
+
   /*
    *  Scan for a hyphen
    */
-  ps = strchr (pz, '-');
+  char *ps = strchr (pz, '-');
   if (ps != NULL)
     {
       res = parse_year_month_day (pz, ps);
@@ -482,10 +483,8 @@ parse_non_iso8601 (cch_t * pz)
   time_t res = 0;
 
   do  {
-    time_t val;
-
     errno = 0;
-    val = str_const_to_l (pz, &pz, 10);
+    time_t val = str_const_to_l (pz, &pz, 10);
     if (errno != 0)
       goto bad_time;
 
index 0ae37a1ba094a33445eeb644af2eec7629b2bfe2..9322e10a9f6238db10616e503e161c34d2a5ec36 100644 (file)
 int
 sendfd (int sock, int fd)
 {
+  /* send at least one char */
   char byte = 0;
   struct iovec iov;
-  struct msghdr msg;
-# if defined CMSG_FIRSTHDR
-  struct cmsghdr *cmsg;
-  char buf[CMSG_SPACE (sizeof fd)];
-# endif
-
-  /* send at least one char */
-  memset (&msg, 0, sizeof msg);
   iov.iov_base = &byte;
   iov.iov_len = 1;
+  struct msghdr msg;
+  memset (&msg, 0, sizeof msg);
   msg.msg_iov = &iov;
   msg.msg_iovlen = 1;
   msg.msg_name = NULL;
   msg.msg_namelen = 0;
 
 # if defined CMSG_FIRSTHDR
+  char buf[CMSG_SPACE (sizeof fd)];
   msg.msg_control = buf;
   msg.msg_controllen = sizeof buf;
-  cmsg = CMSG_FIRSTHDR (&msg);
+  struct cmsghdr *cmsg = CMSG_FIRSTHDR (&msg);
   cmsg->cmsg_level = SOL_SOCKET;
   cmsg->cmsg_type = SCM_RIGHTS;
   cmsg->cmsg_len = CMSG_LEN (sizeof fd);
@@ -107,36 +103,31 @@ sendfd (_GL_UNUSED int sock, _GL_UNUSED int fd)
 int
 recvfd (int sock, int flags)
 {
-  char byte = 0;
-  struct iovec iov;
-  struct msghdr msg;
-  int fd = -1;
-  ssize_t len;
-# if defined CMSG_FIRSTHDR
-  struct cmsghdr *cmsg;
-  char buf[CMSG_SPACE (sizeof fd)];
-  int flags_recvmsg = flags & O_CLOEXEC ? MSG_CMSG_CLOEXEC : 0;
-# endif
-
   if ((flags & ~O_CLOEXEC) != 0)
     {
       errno = EINVAL;
       return -1;
     }
 
-  /* send at least one char */
-  memset (&msg, 0, sizeof msg);
+  int fd = -1;
+
+  /* receive at least one char */
+  char byte = 0;
+  struct iovec iov;
   iov.iov_base = &byte;
   iov.iov_len = 1;
+  struct msghdr msg;
+  memset (&msg, 0, sizeof msg);
   msg.msg_iov = &iov;
   msg.msg_iovlen = 1;
   msg.msg_name = NULL;
   msg.msg_namelen = 0;
 
 # if defined CMSG_FIRSTHDR
+  char buf[CMSG_SPACE (sizeof fd)];
   msg.msg_control = buf;
   msg.msg_controllen = sizeof buf;
-  cmsg = CMSG_FIRSTHDR (&msg);
+  struct cmsghdr *cmsg = CMSG_FIRSTHDR (&msg);
   cmsg->cmsg_level = SOL_SOCKET;
   cmsg->cmsg_type = SCM_RIGHTS;
   cmsg->cmsg_len = CMSG_LEN (sizeof fd);
@@ -144,7 +135,7 @@ recvfd (int sock, int flags)
   memcpy (CMSG_DATA (cmsg), &fd, sizeof fd);
   msg.msg_controllen = CMSG_SPACE (sizeof fd);
 
-  len = recvmsg (sock, &msg, flags_recvmsg);
+  ssize_t len = recvmsg (sock, &msg, flags & O_CLOEXEC ? MSG_CMSG_CLOEXEC : 0);
   if (len < 0)
     return -1;
   if (len == 0)
index da7fb2c6bf84cdd070b2fe5b8c1e7deffa96f65d..4437d4204aa7253703c552704f4fe7bc15aee62c 100644 (file)
@@ -33,12 +33,11 @@ void
 perror (const char *string)
 {
   char stackbuf[STACKBUF_LEN];
-  int ret;
 
   /* Our implementation guarantees that this will be a non-empty
      string, even if it returns EINVAL; and stackbuf should be sized
      large enough to avoid ERANGE.  */
-  ret = strerror_r (errno, stackbuf, sizeof stackbuf);
+  int ret = strerror_r (errno, stackbuf, sizeof stackbuf);
   if (ret == ERANGE)
     abort ();
 
index 0216896cab07992d32c158c9c8efedc7c768a9aa..bf77a07cc0d79a576277d55d8e6b1c442a371a2f 100644 (file)
@@ -138,14 +138,13 @@ physmem_total (void)
 
 #if defined _WIN32
   { /* this works on windows */
-    PFN_MS_EX pfnex;
     HMODULE h = GetModuleHandle ("kernel32.dll");
-
     if (!h)
       return 0.0;
 
     /*  Use GlobalMemoryStatusEx if available.  */
-    if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx")))
+    PFN_MS_EX pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx");
+    if (pfnex)
       {
         lMEMORYSTATUSEX lms_ex;
         lms_ex.dwLength = sizeof lms_ex;
@@ -292,14 +291,14 @@ physmem_claimable (double aggressivity)
 
 #if defined _WIN32
   { /* this works on windows */
-    PFN_MS_EX pfnex;
     HMODULE h = GetModuleHandle ("kernel32.dll");
 
     if (!h)
       return 0.0;
 
     /*  Use GlobalMemoryStatusEx if available.  */
-    if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx")))
+    PFN_MS_EX pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx");
+    if (pfnex)
       {
         lMEMORYSTATUSEX lms_ex;
         lms_ex.dwLength = sizeof lms_ex;
index a04da1c461d4adf81bdc3196b588e7b5b84019fd..e02ecd925a9752571b130da3437aca429d229117 100644 (file)
@@ -163,12 +163,10 @@ filter_loop (struct pipe_filter_gi *filter, const char *wbuf, size_t count)
     {
       for (;;)
         {
-          ssize_t nwritten;
-
           /* Allow the reader thread to continue.  */
           LeaveCriticalSection (&filter->lock);
 
-          nwritten =
+          ssize_t nwritten =
             write (filter->fd[1], wbuf, count > SSIZE_MAX ? SSIZE_MAX : count);
 
           /* Get the lock back from the reader thread.  */
@@ -302,10 +300,8 @@ filter_loop (struct pipe_filter_gi *filter, const char *wbuf, size_t count)
       /* Here, if done_writing, filter->reader_terminated is false.  When
          filter->reader_terminated becomes true, this loop is terminated.  */
 # if HAVE_SELECT
-      int n, retval;
-
       /* See whether reading or writing is possible.  */
-      n = 1;
+      int n = 1;
       if (!filter->reader_terminated)
         {
           FD_SET (filter->fd[0], &filter->readfds);
@@ -320,13 +316,16 @@ filter_loop (struct pipe_filter_gi *filter, const char *wbuf, size_t count)
       /* Do EINTR handling here instead of in pipe-filter-aux.h,
          because select() cannot be referred to from an inline
          function on AIX 7.1.  */
-      do
-        retval = select (n,
-                         (!filter->reader_terminated ? &filter->readfds : NULL),
-                         (!done_writing ? &filter->writefds : NULL),
-                         NULL, NULL);
-      while (retval < 0 && errno == EINTR);
-      n = retval;
+      {
+        int retval;
+        do
+          retval = select (n,
+                           (!filter->reader_terminated ? &filter->readfds : NULL),
+                           (!done_writing ? &filter->writefds : NULL),
+                           NULL, NULL);
+        while (retval < 0 && errno == EINTR);
+        n = retval;
+      }
 
       if (n < 0)
         {
@@ -490,9 +489,7 @@ pipe_filter_gi_create (const char *progname,
                        done_read_fn done_read,
                        void *private_data)
 {
-  struct pipe_filter_gi *filter;
-
-  filter =
+  struct pipe_filter_gi *filter =
     (struct pipe_filter_gi *) xmalloc (sizeof (struct pipe_filter_gi));
 
   /* Open a bidirectional pipe to a subprocess.  */
@@ -552,10 +549,8 @@ pipe_filter_gi_write (struct pipe_filter_gi *filter,
 int
 pipe_filter_gi_close (struct pipe_filter_gi *filter)
 {
-  int ret;
-
   filter_terminate (filter);
-  ret = filter_retcode (filter);
+  int ret = filter_retcode (filter);
   free (filter);
   return ret;
 }
index 1131265009f5a4d6b8e6d14bea24e39a754fbeea..9c1f0f1ba0c5aedaf6add248055f9e7462afef49 100644 (file)
@@ -60,9 +60,7 @@ static HANDLE
 _beginthreadex (void *s, unsigned n, unsigned int WINAPI (*start) (void *),
                 void *arg, unsigned fl, unsigned *th)
 {
-  HANDLE h;
-
-  h = malloc (sizeof (*h));
+  HANDLE h = malloc (sizeof (*h));
   if (!h)
     return NULL;
 
@@ -77,8 +75,8 @@ _beginthreadex (void *s, unsigned n, unsigned int WINAPI (*start) (void *),
 
       DosCloseEventSem (h->hevDone);
     }
-  free (h);
 
+  free (h);
   return NULL;
 }
 
@@ -111,12 +109,7 @@ static DWORD
 WaitForMultipleObjects (DWORD nCount, const HANDLE *pHandles, BOOL bWaitAll,
                         DWORD ms)
 {
-  HMUX hmux;
-  PSEMRECORD psr;
-  ULONG ulUser;
-  ULONG rc = (ULONG) -1;
-
-  psr = malloc (sizeof (*psr) * nCount);
+  PSEMRECORD psr = malloc (sizeof (*psr) * nCount);
   if (!psr)
     return (DWORD) -1;
 
@@ -126,10 +119,12 @@ WaitForMultipleObjects (DWORD nCount, const HANDLE *pHandles, BOOL bWaitAll,
       psr[i].ulUser  = WAIT_OBJECT_0 + i;
     }
 
+  HMUX hmux;
   if (! DosCreateMuxWaitSem (NULL, &hmux, nCount, psr,
                              bWaitAll ? DCMW_WAIT_ALL : DCMW_WAIT_ANY))
     {
-      rc = DosWaitMuxWaitSem (hmux, ms, &ulUser);
+      ULONG ulUser;
+      ULONG rc = DosWaitMuxWaitSem (hmux, ms, &ulUser);
       DosCloseMuxWaitSem (hmux);
       free (psr);
       return rc ? (DWORD) -1 : ulUser;
@@ -277,8 +272,6 @@ pipe_filter_ii_execute (const char *progname,
     HANDLE handles[2];
     #define writer_thread_handle handles[0]
     #define reader_thread_handle handles[1]
-    bool writer_cleaned_up;
-    bool reader_cleaned_up;
 
     l.prepare_write = prepare_write;
     l.done_write = done_write;
@@ -306,13 +299,12 @@ pipe_filter_ii_execute (const char *progname,
           CloseHandle (writer_thread_handle);
         goto fail;
       }
-    writer_cleaned_up = false;
-    reader_cleaned_up = false;
+    bool writer_cleaned_up = false;
+    bool reader_cleaned_up = false;
     for (;;)
       {
-        DWORD ret;
-
         /* Here !(writer_cleaned_up && reader_cleaned_up).  */
+        DWORD ret;
         if (writer_cleaned_up)
           ret = WaitForSingleObject (reader_thread_handle, INFINITE);
         else if (reader_cleaned_up)
@@ -381,12 +373,6 @@ pipe_filter_ii_execute (const char *progname,
   }
 
   {
-# if HAVE_SELECT
-    fd_set readfds;  /* All bits except fd[0] are always cleared.  */
-    fd_set writefds; /* All bits except fd[1] are always cleared.  */
-# endif
-    bool done_writing;
-
     /* Enable non-blocking I/O.  This permits the read() and write() calls
        to return -1/EAGAIN without blocking; this is important for polling
        if HAVE_SELECT is not defined.  It also permits the read() and write()
@@ -412,17 +398,17 @@ pipe_filter_ii_execute (const char *progname,
     }
 
 # if HAVE_SELECT
+    fd_set readfds;  /* All bits except fd[0] are always cleared.  */
     FD_ZERO (&readfds);
+    fd_set writefds; /* All bits except fd[1] are always cleared.  */
     FD_ZERO (&writefds);
 # endif
-    done_writing = false;
+    bool done_writing = false;
     for (;;)
       {
 # if HAVE_SELECT
-        int n, retval;
-
         FD_SET (fd[0], &readfds);
-        n = fd[0] + 1;
+        int n = fd[0] + 1;
         if (!done_writing)
           {
             FD_SET (fd[1], &writefds);
@@ -433,11 +419,14 @@ pipe_filter_ii_execute (const char *progname,
         /* Do EINTR handling here instead of in pipe-filter-aux.h,
            because select() cannot be referred to from an inline
            function on AIX 7.1.  */
-        do
-          retval = select (n, &readfds, (!done_writing ? &writefds : NULL),
-                           NULL, NULL);
-        while (retval < 0 && errno == EINTR);
-        n = retval;
+        {
+          int retval;
+          do
+            retval = select (n, &readfds, (!done_writing ? &writefds : NULL),
+                             NULL, NULL);
+          while (retval < 0 && errno == EINTR);
+          n = retval;
+        }
 
         if (n < 0)
           {
index ef1b92c3aedf4a8c102359823e14c1770a778f48..a24c7a4e75aeb8d1689ce4191570217f188e7381 100644 (file)
@@ -115,13 +115,12 @@ static BOOL IsConsoleHandle (HANDLE h)
 static BOOL
 IsSocketHandle (HANDLE h)
 {
-  WSANETWORKEVENTS ev;
-
   if (IsConsoleHandle (h))
     return FALSE;
 
   /* Under Wine, it seems that getsockopt returns 0 for pipes too.
      WSAEnumNetworkEvents instead distinguishes the two correctly.  */
+  WSANETWORKEVENTS ev;
   ev.lNetworkEvents = 0xDEADBEEF;
   WSAEnumNetworkEvents ((SOCKET) h, NULL, &ev);
   return ev.lNetworkEvents != 0xDEADBEEF;
@@ -167,12 +166,6 @@ typedef DWORD (WINAPI *PNtQueryInformationFile)
 static int
 windows_compute_revents (HANDLE h, int *p_sought)
 {
-  int ret, happened;
-  INPUT_RECORD *irbuffer;
-  DWORD avail, nbuffer;
-  BOOL bRet;
-  IO_STATUS_BLOCK iosb;
-  FILE_PIPE_LOCAL_INFORMATION fpli;
   static PNtQueryInformationFile NtQueryInformationFile;
   static BOOL once_only;
 
@@ -187,46 +180,51 @@ windows_compute_revents (HANDLE h, int *p_sought)
           once_only = TRUE;
         }
 
-      happened = 0;
-      if (PeekNamedPipe (h, NULL, 0, NULL, &avail, NULL) != 0)
-        {
-          if (avail)
-            happened |= *p_sought & (POLLIN | POLLRDNORM);
-        }
-      else if (GetLastError () == ERROR_BROKEN_PIPE)
-        happened |= POLLHUP;
-
-      else
-        {
-          /* It was the write-end of the pipe.  Check if it is writable.
-             If NtQueryInformationFile fails, optimistically assume the pipe is
-             writable.  This could happen on Windows 9x, where
-             NtQueryInformationFile is not available, or if we inherit a pipe
-             that doesn't permit FILE_READ_ATTRIBUTES access on the write end
-             (I think this should not happen since Windows XP SP2; WINE seems
-             fine too).  Otherwise, ensure that enough space is available for
-             atomic writes.  */
-          memset (&iosb, 0, sizeof (iosb));
-          memset (&fpli, 0, sizeof (fpli));
-
-          if (!NtQueryInformationFile
-              || NtQueryInformationFile (h, &iosb, &fpli, sizeof (fpli),
-                                         FilePipeLocalInformation)
-              || fpli.WriteQuotaAvailable >= PIPE_BUF
-              || (fpli.OutboundQuota < PIPE_BUF &&
-                  fpli.WriteQuotaAvailable == fpli.OutboundQuota))
-            happened |= *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND);
-        }
-      return happened;
+      {
+        int happened = 0;
+        DWORD avail;
+        if (PeekNamedPipe (h, NULL, 0, NULL, &avail, NULL) != 0)
+          {
+            if (avail)
+              happened |= *p_sought & (POLLIN | POLLRDNORM);
+          }
+        else if (GetLastError () == ERROR_BROKEN_PIPE)
+          happened |= POLLHUP;
+        else
+          {
+            /* It was the write-end of the pipe.  Check if it is writable.
+               If NtQueryInformationFile fails, optimistically assume the pipe is
+               writable.  This could happen on Windows 9x, where
+               NtQueryInformationFile is not available, or if we inherit a pipe
+               that doesn't permit FILE_READ_ATTRIBUTES access on the write end
+               (I think this should not happen since Windows XP SP2; WINE seems
+               fine too).  Otherwise, ensure that enough space is available for
+               atomic writes.  */
+            IO_STATUS_BLOCK iosb;
+            memset (&iosb, 0, sizeof (iosb));
+            FILE_PIPE_LOCAL_INFORMATION fpli;
+            memset (&fpli, 0, sizeof (fpli));
+
+            if (!NtQueryInformationFile
+                || NtQueryInformationFile (h, &iosb, &fpli, sizeof (fpli),
+                                           FilePipeLocalInformation)
+                || fpli.WriteQuotaAvailable >= PIPE_BUF
+                || (fpli.OutboundQuota < PIPE_BUF &&
+                    fpli.WriteQuotaAvailable == fpli.OutboundQuota))
+              happened |= *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND);
+          }
+        return happened;
+      }
 
     case FILE_TYPE_CHAR:
-      ret = WaitForSingleObject (h, 0);
-      if (!IsConsoleHandle (h))
-        return ret == WAIT_OBJECT_0 ? *p_sought & ~(POLLPRI | POLLRDBAND) : 0;
-
-      nbuffer = avail = 0;
-      bRet = GetNumberOfConsoleInputEvents (h, &nbuffer);
-      if (bRet)
+      {
+        int ret = WaitForSingleObject (h, 0);
+        if (!IsConsoleHandle (h))
+          return ret == WAIT_OBJECT_0 ? *p_sought & ~(POLLPRI | POLLRDBAND) : 0;
+      }
+
+      DWORD nbuffer = 0;
+      if (GetNumberOfConsoleInputEvents (h, &nbuffer))
         {
           /* Input buffer.  */
           *p_sought &= POLLIN | POLLRDNORM;
@@ -235,9 +233,10 @@ windows_compute_revents (HANDLE h, int *p_sought)
           if (!*p_sought)
             return 0;
 
-          irbuffer = (INPUT_RECORD *) alloca (nbuffer * sizeof (INPUT_RECORD));
-          bRet = PeekConsoleInput (h, irbuffer, nbuffer, &avail);
-          if (!bRet || avail == 0)
+          INPUT_RECORD *irbuffer =
+            (INPUT_RECORD *) alloca (nbuffer * sizeof (INPUT_RECORD));
+          DWORD avail = 0;
+          if (! PeekConsoleInput (h, irbuffer, nbuffer, &avail) || avail == 0)
             return POLLHUP;
 
           for (int i = 0; i < avail; i++)
@@ -253,9 +252,11 @@ windows_compute_revents (HANDLE h, int *p_sought)
         }
 
     default:
-      ret = WaitForSingleObject (h, 0);
-      if (ret == WAIT_OBJECT_0)
-        return *p_sought & ~(POLLPRI | POLLRDBAND);
+      {
+        int ret = WaitForSingleObject (h, 0);
+        if (ret == WAIT_OBJECT_0)
+          return *p_sought & ~(POLLPRI | POLLRDBAND);
+      }
 
       return *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND);
     }
@@ -270,15 +271,12 @@ windows_compute_revents_socket (SOCKET h, int sought, long lNetworkEvents)
 
   if ((lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE)) == FD_ACCEPT)
     happened |= (POLLIN | POLLRDNORM) & sought;
-
   else if (lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE))
     {
-      int r, error;
-
       char data[64];
       WSASetLastError (0);
-      r = recv (h, data, sizeof (data), MSG_PEEK);
-      error = WSAGetLastError ();
+      int r = recv (h, data, sizeof (data), MSG_PEEK);
+      int error = WSAGetLastError ();
       WSASetLastError (0);
 
       if (r > 0 || error == WSAENOTCONN)
@@ -302,7 +300,7 @@ windows_compute_revents_socket (SOCKET h, int sought, long lNetworkEvents)
   return happened;
 }
 
-#else /* !MinGW */
+#else /* !WINDOWS_NATIVE */
 
 /* Convert select(2) returned fd_sets into poll(2) revents values.  */
 static int
@@ -357,18 +355,12 @@ compute_revents (int fd, int sought, fd_set *rfds, fd_set *wfds, fd_set *efds)
 
   return happened;
 }
-#endif /* !MinGW */
+#endif /* !WINDOWS_NATIVE */
 
 int
 poll (struct pollfd *pfd, nfds_t nfd, int timeout)
 {
 #ifndef WINDOWS_NATIVE
-  fd_set rfds, wfds, efds;
-  struct timeval tv;
-  struct timeval *ptv;
-  int maxfd, rc;
-  nfds_t i;
-
   if (nfd > INT_MAX)
     {
       errno = EINVAL;
@@ -388,6 +380,8 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
     }
 
   /* convert timeout number into a timeval structure */
+  struct timeval tv;
+  struct timeval *ptv;
   if (timeout == 0)
     {
       ptv = &tv;
@@ -411,9 +405,12 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
     }
 
   /* create fd sets and determine max fd */
-  maxfd = -1;
+  int maxfd = -1;
+  fd_set rfds;
   FD_ZERO (&rfds);
+  fd_set wfds;
   FD_ZERO (&wfds);
+  fd_set efds;
   FD_ZERO (&efds);
   for (int i = 0; i < nfd; i++)
     {
@@ -441,12 +438,14 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
     }
 
   /* examine fd sets */
-  rc = select (maxfd + 1, &rfds, &wfds, &efds, ptv);
-  if (rc < 0)
-    return rc;
+  {
+    int rc = select (maxfd + 1, &rfds, &wfds, &efds, ptv);
+    if (rc < 0)
+      return rc;
+  }
 
   /* establish results */
-  rc = 0;
+  int rc = 0;
   for (int i = 0; i < nfd; i++)
     {
       pfd[i].revents = (pfd[i].fd < 0
@@ -460,13 +459,6 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
 #else
   static struct timeval tv0;
   static HANDLE hEvent;
-  WSANETWORKEVENTS ev;
-  HANDLE h, handle_array[FD_SETSIZE + 2];
-  DWORD ret, wait_timeout, nhandles;
-  fd_set rfds, wfds, xfds;
-  BOOL poll_again;
-  MSG msg;
-  int rc = 0;
 
   if (nfd > INT_MAX || timeout < -1)
     {
@@ -477,11 +469,16 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
   if (!hEvent)
     hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
 
+  HANDLE handle_array[FD_SETSIZE + 2];
+
 restart:
   handle_array[0] = hEvent;
-  nhandles = 1;
+  DWORD nhandles = 1;
+  fd_set rfds;
   FD_ZERO (&rfds);
+  fd_set wfds;
   FD_ZERO (&wfds);
+  fd_set xfds;
   FD_ZERO (&xfds);
 
   /* Classify socket handles and create fd sets. */
@@ -493,7 +490,7 @@ restart:
           && (sought & (POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLWRBAND
                         | POLLPRI | POLLRDBAND)))
         {
-          h = (HANDLE) _get_osfhandle (pfd[i].fd);
+          HANDLE h = (HANDLE) _get_osfhandle (pfd[i].fd);
           assure (h != NULL);
           if (IsSocketHandle (h))
             {
@@ -534,6 +531,8 @@ restart:
         }
     }
 
+  BOOL poll_again;
+  DWORD wait_timeout;
   if (select (0, &rfds, &wfds, &xfds, &tv0) > 0)
     {
       /* Do MsgWaitForMultipleObjects anyway to dispatch messages, but
@@ -552,14 +551,14 @@ restart:
 
   for (;;)
     {
-      ret = MsgWaitForMultipleObjects (nhandles, handle_array, FALSE,
-                                       wait_timeout, QS_ALLINPUT);
+      DWORD ret = MsgWaitForMultipleObjects (nhandles, handle_array, FALSE,
+                                             wait_timeout, QS_ALLINPUT);
 
       if (ret == WAIT_OBJECT_0 + nhandles)
         {
           /* new input of some other kind */
-          BOOL bRet;
-          while ((bRet = PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) != 0)
+          MSG msg;
+          while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE) != 0)
             {
               TranslateMessage (&msg);
               DispatchMessage (&msg);
@@ -572,6 +571,8 @@ restart:
   if (poll_again)
     select (0, &rfds, &wfds, &xfds, &tv0);
 
+  int rc = 0;
+
   /* Place a sentinel at the end of the array.  */
   handle_array[nhandles] = NULL;
   nhandles = 1;
@@ -583,10 +584,11 @@ restart:
           && (pfd[i].events & (POLLIN | POLLRDNORM |
                                POLLOUT | POLLWRNORM | POLLWRBAND)))
         {
-          h = (HANDLE) _get_osfhandle (pfd[i].fd);
+          HANDLE h = (HANDLE) _get_osfhandle (pfd[i].fd);
           if (h != handle_array[nhandles])
             {
               /* It's a socket.  */
+              WSANETWORKEVENTS ev;
               WSAEnumNetworkEvents ((SOCKET) h, NULL, &ev);
               WSAEventSelect ((SOCKET) h, 0, 0);
 
index a8ed25db1c29f02f40fcd36a877a100a64dca5f5..ed4699980cf0d89d836f8d734bb5dd2180598ffd 100644 (file)
@@ -61,10 +61,8 @@ rpl_popen (const char *filename, const char *mode)
      temporarily marking them cloexec around the real popen call, but
      we would also have to override pclose, and the bookkeeping seems
      extreme given that cygwin 1.7 no longer has the bug.  */
-  FILE *result;
   int cloexec0 = fcntl (STDIN_FILENO, F_GETFD);
   int cloexec1 = fcntl (STDOUT_FILENO, F_GETFD);
-  int saved_errno;
 
   /* If either stdin or stdout was closed (that is, fcntl failed),
      then we open a dummy close-on-exec fd to occupy that slot.  That
@@ -89,14 +87,16 @@ rpl_popen (const char *filename, const char *mode)
                     fcntl (STDOUT_FILENO, F_GETFD) | FD_CLOEXEC) == -1)
         abort ();
     }
-  result = popen (filename, mode);
+  FILE *result = popen (filename, mode);
   /* Now, close any dummy fd's created in the parent.  */
-  saved_errno = errno;
-  if (cloexec0 < 0)
-    close (STDIN_FILENO);
-  if (cloexec1 < 0)
-    close (STDOUT_FILENO);
-  errno = saved_errno;
+  {
+    int saved_errno = errno;
+    if (cloexec0 < 0)
+      close (STDIN_FILENO);
+    if (cloexec1 < 0)
+      close (STDOUT_FILENO);
+    errno = saved_errno;
+  }
   return result;
 }
 
index f680a55ccbb336f4a0c21d1b328f794181a03ba3..c5c6d4faae6b54cfc5bf5044127bbe1abc4b277c 100644 (file)
@@ -63,12 +63,10 @@ posix_openpt (int flags)
 
   /* On OpenBSD, master and slave of a pseudo-terminal are allocated together,
      by opening /dev/ptm and applying the PTMGET ioctl to it.  */
-  int fd;
-  struct ptmget data;
-
-  fd = open (PATH_PTMDEV, O_RDWR);
+  int fd = open (PATH_PTMDEV, O_RDWR);
   if (fd >= 0)
     {
+      struct ptmget data;
       if (ioctl (fd, PTMGET, &data) >= 0)
         {
           master = data.cfd;
index 92b84d6cee7bcb2400a8cbfc496c38f1c2b170f4..d6d2889411e78186790fd226e8ceae58774a549e 100644 (file)
@@ -91,12 +91,11 @@ year (struct tm *tm, const int *digit_pair, idx_t n, unsigned int syntax_bits)
 static bool
 posix_time_parse (struct tm *tm, const char *s, unsigned int syntax_bits)
 {
-  const char *dot = NULL;
-  int pair[6];
 
   idx_t s_len = strlen (s);
-  idx_t len = s_len;
 
+  const char *dot = NULL;
+  idx_t len = s_len;
   if (syntax_bits & PDS_SECONDS)
     {
       dot = strchr (s, '.');
@@ -116,6 +115,8 @@ posix_time_parse (struct tm *tm, const char *s, unsigned int syntax_bits)
       return false;
 
   len /= 2;
+
+  int pair[6];
   for (idx_t i = 0; i < len; i++)
     pair[i] = 10 * (s[2*i] - '0') + s[2*i + 1] - '0';
 
@@ -159,11 +160,11 @@ bool
 posixtime (time_t *p, const char *s, unsigned int syntax_bits)
 {
   struct tm tm0;
-  bool leapsec = false;
 
   if (! posix_time_parse (&tm0, s, syntax_bits))
     return false;
 
+  bool leapsec = false;
   while (true)
     {
       struct tm tm1;
index 73a426060849baf8d21fd4e282052272a6d6e1ff..2e0e10112d81ae6c90310ba101060f7dc68548aa 100644 (file)
@@ -36,8 +36,6 @@ pread (int fd, void *buf, size_t nbyte, off_t offset)
 {
   /* Since we must not change the file pointer preserve the value so that
      we can restore it later.  */
-  int saved_errno;
-  ssize_t result;
   off_t old_offset = __libc_lseek (fd, 0, SEEK_CUR);
   if (old_offset == (off_t) -1)
     return -1;
@@ -47,12 +45,12 @@ pread (int fd, void *buf, size_t nbyte, off_t offset)
     return -1;
 
   /* Write out the data.  */
-  result = __libc_read (fd, buf, nbyte);
+  ssize_t result = __libc_read (fd, buf, nbyte);
 
   /* Now we have to restore the position.  If this fails we have to
      return this as an error.  But if the writing also failed we
      return this error.  */
-  saved_errno = errno;
+  int saved_errno = errno;
   if (__libc_lseek (fd, old_offset, SEEK_SET) == (off_t) -1)
     {
       if (result == -1)
index af5a0b4f13f63351f70d82b07b8b63af895bd18a..30136ba70e554bd09dc9349975364edfa6f7f620 100644 (file)
 DOUBLE
 FUNC (DOUBLE x, int *expptr)
 {
-  int exponent;
   DECL_ROUNDING
 
   BEGIN_ROUNDING ();
 
+  int exponent;
+
 #ifdef USE_FREXP_LDEXP
   /* frexp and ldexp are usually faster than the loop below.  */
   x = FREXP (x, &exponent);
index 79b350343363cfa9e3d78caf5d920886e93b6f79..98aab01ecfaff60d42ee71fc84d8a63a53add8da 100644 (file)
@@ -323,8 +323,6 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
             }
 
           {
-            arg_type type;
-
             /* Parse argument type/size specifiers.  */
             /* Relevant for the conversion characters d, i.  */
             arg_type signed_type = TYPE_INT;
@@ -561,6 +559,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
             (void) pointer_type;
 
             /* Read the conversion character.  */
+            arg_type type;
             c = *cp++;
             switch (c)
               {
@@ -654,17 +653,14 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
           d->count++;
           if (d->count >= d_allocated)
             {
-              size_t memory_size;
-              DIRECTIVE *memory;
-
               d_allocated = xtimes (d_allocated, 2);
-              memory_size = xtimes (d_allocated, sizeof (DIRECTIVE));
+              size_t memory_size = xtimes (d_allocated, sizeof (DIRECTIVE));
               if (size_overflow_p (memory_size))
                 /* Overflow, would lead to out of memory.  */
                 goto out_of_memory;
-              memory = (DIRECTIVE *) (d->dir != d->direct_alloc_dir
-                                      ? realloc (d->dir, memory_size)
-                                      : malloc (memory_size));
+              DIRECTIVE *memory = (DIRECTIVE *) (d->dir != d->direct_alloc_dir
+                                                 ? realloc (d->dir, memory_size)
+                                                 : malloc (memory_size));
               if (memory == NULL)
                 /* Out of memory.  */
                 goto out_of_memory;
index 5f84036e07a734b91b35e95f6a2350f047a36c16..9f69b103bd6624c862c8cbe0df8b24e2057d7fbd 100644 (file)
 int
 printf (const char *format, ...)
 {
-  int retval;
   va_list args;
-
   va_start (args, format);
-  retval = vfprintf (stdout, format, args);
+  int retval = vfprintf (stdout, format, args);
   va_end (args);
 
   return retval;
index a26c9774225120c13a863c097ab91772eb69d932..df52ee666ac7777846bfbb7a776b901dcef71089 100644 (file)
@@ -180,13 +180,15 @@ maybe_executable (const char *filename)
       /* If we already have an executable_fd, check that filename points to
          the same inode.  */
       struct stat statexe;
-      struct stat statfile;
 
       if (fstat (executable_fd, &statexe) >= 0)
-        return (stat (filename, &statfile) >= 0
-                && statfile.st_dev
-                && statfile.st_dev == statexe.st_dev
-                && statfile.st_ino == statexe.st_ino);
+        {
+          struct stat statfile;
+          return (stat (filename, &statfile) >= 0
+                  && statfile.st_dev
+                  && statfile.st_dev == statexe.st_dev
+                  && statfile.st_ino == statexe.st_ino);
+        }
     }
 # endif
 
@@ -223,16 +225,15 @@ find_executable (const char *argv0)
     return NULL;
   return xstrdup (location);
 #elif defined __EMX__
-  PPIB ppib;
-  char location[CCHMAXPATH];
-
   /* See http://cyberkinetica.homeunix.net/os2tk45/cp1/619_L2H_DosGetInfoBlocksSynt.html
      for specification of DosGetInfoBlocks().  */
+  PPIB ppib;
   if (DosGetInfoBlocks (NULL, &ppib))
     return NULL;
 
   /* See http://cyberkinetica.homeunix.net/os2tk45/cp1/1247_L2H_DosQueryModuleNameSy.html
      for specification of DosQueryModuleName().  */
+  char location[CCHMAXPATH];
   if (DosQueryModuleName (ppib->pib_hmte, sizeof (location), location))
     return NULL;
 
@@ -246,32 +247,28 @@ find_executable (const char *argv0)
      to the true pathname; older Linux versions give only device and ino,
      enclosed in brackets, which we cannot use here.  */
   {
-    char *link;
-
-    link = xreadlink ("/proc/self/exe");
+    char *link = xreadlink ("/proc/self/exe");
     if (link != NULL && link[0] != '[')
       return link;
     if (executable_fd < 0)
       executable_fd = open ("/proc/self/exe", O_EXEC | O_CLOEXEC, 0);
-
-    {
-      char buf[6+10+5];
-      sprintf (buf, "/proc/%d/exe", getpid ());
-      link = xreadlink (buf);
-      if (link != NULL && link[0] != '[')
-        return link;
-      if (executable_fd < 0)
-        executable_fd = open (buf, O_EXEC | O_CLOEXEC, 0);
+  }
+  {
+    char buf[6+10+5];
+    sprintf (buf, "/proc/%d/exe", getpid ());
+    char *link = xreadlink (buf);
+    if (link != NULL && link[0] != '[')
+      return link;
     }
+    if (executable_fd < 0)
+      executable_fd = open (buf, O_EXEC | O_CLOEXEC, 0);
   }
 # endif
 # if defined __ANDROID__ || defined __FreeBSD_kernel__
   /* On Android and GNU/kFreeBSD, the executable is accessible as
      /proc/<pid>/exe and /proc/self/exe.  */
   {
-    char *link;
-
-    link = xreadlink ("/proc/self/exe");
+    char *link = xreadlink ("/proc/self/exe");
     if (link != NULL)
       return link;
   }
@@ -280,9 +277,7 @@ find_executable (const char *argv0)
   /* In FreeBSD >= 5.0, the executable is accessible as /proc/<pid>/file and
      /proc/curproc/file.  */
   {
-    char *link;
-
-    link = xreadlink ("/proc/curproc/file");
+    char *link = xreadlink ("/proc/curproc/file");
     if (link != NULL)
       {
         if (!streq (link, "unknown"))
@@ -295,9 +290,7 @@ find_executable (const char *argv0)
   /* In NetBSD >= 4.0, the executable is accessible as /proc/<pid>/exe and
      /proc/curproc/exe.  */
   {
-    char *link;
-
-    link = xreadlink ("/proc/curproc/exe");
+    char *link = xreadlink ("/proc/curproc/exe");
     if (link != NULL)
       return link;
   }
@@ -325,9 +318,7 @@ find_executable (const char *argv0)
   /* The executable is accessible as /proc/<pid>/exe, at least in
      Cygwin >= 1.5.  */
   {
-    char *link;
-
-    link = xreadlink ("/proc/self/exe");
+    char *link = xreadlink ("/proc/self/exe");
     if (link != NULL)
       return link;
     if (executable_fd < 0)
@@ -367,19 +358,21 @@ find_executable (const char *argv0)
 
             for (const char *p = path; *p; p = p_next)
               {
-                const char *q;
                 size_t p_len;
-                char *concat_name;
 
-                for (q = p; *q; q++)
-                  if (*q == ':')
-                    break;
-                p_len = q - p;
-                p_next = (*q == '\0' ? q : q + 1);
+                {
+                  const char *q;
+                  for (q = p; *q; q++)
+                    if (*q == ':')
+                      break;
+                  p_len = q - p;
+                  p_next = (*q == '\0' ? q : q + 1);
+                }
 
                 /* We have a path item at p, of length p_len.
                    Now concatenate the path item and argv0.  */
-                concat_name = (char *) xmalloc (p_len + strlen (argv0) + 2);
+                char *concat_name =
+                  (char *) xmalloc (p_len + strlen (argv0) + 2);
 # ifdef NO_XMALLOC
                 if (concat_name == NULL)
                   return NULL;
@@ -417,14 +410,12 @@ static void
 prepare_relocate (const char *orig_installprefix, const char *orig_installdir,
                   const char *argv0)
 {
-  char *curr_prefix;
-
   /* Determine the full pathname of the current executable.  */
   executable_fullname = find_executable (argv0);
 
   /* Determine the current installation prefix from it.  */
-  curr_prefix = compute_curr_prefix (orig_installprefix, orig_installdir,
-                                     executable_fullname);
+  char *curr_prefix = compute_curr_prefix (orig_installprefix, orig_installdir,
+                                           executable_fullname);
   if (curr_prefix != NULL)
     {
       /* Now pass this prefix to all copies of the relocate.c source file.  */
index e927df21b3a5578c975ede8b71d33b8d2ec95e7f..aca37aa085c73f8e07b102272cf1fa7da5189175 100644 (file)
@@ -58,12 +58,13 @@ static bool
 mbsstr_trimmed_wordbounded (const char *string, const char *sub)
 {
   char *tsub = trim (sub);
-  bool found = false;
   bool multibyte_locale = MB_CUR_MAX > 1;
+
   size_t tsublen;
   if (! multibyte_locale)
     tsublen = strlen (tsub);
 
+  bool found = false;
   while (*string != '\0')
     {
       const char *tsub_in_string = mbsstr (string, tsub);
@@ -100,47 +101,51 @@ mbsstr_trimmed_wordbounded (const char *string, const char *sub)
                 break;
               string = tsub_in_string + mcel_scanz (tsub_in_string).len;
 #else
-              mbui_iterator_t string_iter;
               bool word_boundary_before;
-              bool word_boundary_after;
+              {
+                mbui_iterator_t string_iter;
+                mbui_init (string_iter, string);
+                word_boundary_before = true;
+                if (mbui_cur_ptr (string_iter) < tsub_in_string)
+                  {
+                    mbchar_t last_char_before_tsub;
+                    do
+                      {
+                        if (!mbui_avail (string_iter))
+                          abort ();
+                        last_char_before_tsub = mbui_cur (string_iter);
+                        mbui_advance (string_iter);
+                      }
+                    while (mbui_cur_ptr (string_iter) < tsub_in_string);
+                    if (mb_isalnum (last_char_before_tsub))
+                      word_boundary_before = false;
+                  }
+              }
 
-              mbui_init (string_iter, string);
-              word_boundary_before = true;
-              if (mbui_cur_ptr (string_iter) < tsub_in_string)
+              bool word_boundary_after;
+              {
+                mbui_iterator_t string_iter;
+                mbui_init (string_iter, tsub_in_string);
                 {
-                  mbchar_t last_char_before_tsub;
-                  do
+                  mbui_iterator_t tsub_iter;
+
+                  for (mbui_init (tsub_iter, tsub);
+                       mbui_avail (tsub_iter);
+                       mbui_advance (tsub_iter))
                     {
                       if (!mbui_avail (string_iter))
                         abort ();
-                      last_char_before_tsub = mbui_cur (string_iter);
                       mbui_advance (string_iter);
                     }
-                  while (mbui_cur_ptr (string_iter) < tsub_in_string);
-                  if (mb_isalnum (last_char_before_tsub))
-                    word_boundary_before = false;
                 }
-
-              mbui_init (string_iter, tsub_in_string);
-              {
-                mbui_iterator_t tsub_iter;
-
-                for (mbui_init (tsub_iter, tsub);
-                     mbui_avail (tsub_iter);
-                     mbui_advance (tsub_iter))
+                word_boundary_after = true;
+                if (mbui_avail (string_iter))
                   {
-                    if (!mbui_avail (string_iter))
-                      abort ();
-                    mbui_advance (string_iter);
+                    mbchar_t first_char_after_tsub = mbui_cur (string_iter);
+                    if (mb_isalnum (first_char_after_tsub))
+                      word_boundary_after = false;
                   }
               }
-              word_boundary_after = true;
-              if (mbui_avail (string_iter))
-                {
-                  mbchar_t first_char_after_tsub = mbui_cur (string_iter);
-                  if (mb_isalnum (first_char_after_tsub))
-                    word_boundary_after = false;
-                }
 
               if (word_boundary_before && word_boundary_after)
                 {
@@ -148,6 +153,7 @@ mbsstr_trimmed_wordbounded (const char *string, const char *sub)
                   break;
                 }
 
+              mbui_iterator_t string_iter;
               mbui_init (string_iter, tsub_in_string);
               if (!mbui_avail (string_iter))
                 break;
@@ -218,7 +224,6 @@ proper_name_utf8 (const char *name_ascii, const char *name_utf8)
   char *alloc_name_converted_translit = NULL;
   const char *name_converted = NULL;
   const char *name_converted_translit = NULL;
-  const char *name;
 
   if (c_strcasecmp (locale_code, "UTF-8") != 0)
     {
@@ -268,9 +273,10 @@ proper_name_utf8 (const char *name_ascii, const char *name_utf8)
     }
 
   /* The name in locale encoding.  */
-  name = (name_converted != NULL ? name_converted :
-          name_converted_translit != NULL ? name_converted_translit :
-          name_ascii);
+  const char *name =
+    (name_converted != NULL ? name_converted :
+     name_converted_translit != NULL ? name_converted_translit :
+     name_ascii);
 
   /* See whether we have a translation.  Some translators have not understood
      that they should use the UTF-8 form of the name, if possible.  So if the
index f6599f5f23bbf000366cd284a13b1d240e556a40..9af489b96d89fb360e4aced57eccec70ab7475b2 100644 (file)
@@ -41,16 +41,14 @@ pselect (int nfds, fd_set *restrict rfds,
          struct timespec const *restrict timeout,
          sigset_t const *restrict sigmask)
 {
-  int select_result;
-  sigset_t origmask;
-  struct timeval tv, *tvp;
-
   if (nfds < 0 || nfds > FD_SETSIZE)
     {
       errno = EINVAL;
       return -1;
     }
 
+  struct timeval tv;
+  struct timeval *tvp;
   if (timeout)
     {
       if (! (0 <= timeout->tv_nsec && timeout->tv_nsec < 1000000000))
@@ -68,12 +66,13 @@ pselect (int nfds, fd_set *restrict rfds,
   else
     tvp = NULL;
 
+  sigset_t origmask;
   /* Signal mask munging should be atomic, but this is the best we can
      do in this emulation.  */
   if (sigmask)
     pthread_sigmask (SIG_SETMASK, sigmask, &origmask);
 
-  select_result = select (nfds, rfds, wfds, xfds, tvp);
+  int select_result = select (nfds, rfds, wfds, xfds, tvp);
 
   if (sigmask)
     {
index ec4ed905aef76a11200e819f5605af4dba3776a1..dcc7a3f6ce4f3f2452710ad1e9fd2990a091d734 100644 (file)
 static int
 do_pt_chown (void)
 {
-  char *pty;
-  struct stat st;
-  struct group *p;
-  gid_t gid;
-
   /* Check that PTY_FILENO is a valid master pseudo terminal.  */
-  pty = ptsname (PTY_FILENO);
+  char *pty = ptsname (PTY_FILENO);
   if (pty == NULL)
     return errno == EBADF ? FAIL_EBADF : FAIL_EINVAL;
 
   /* Check that the returned slave pseudo terminal is a
      character device.  */
+  struct stat st;
   if (stat (pty, &st) < 0 || !S_ISCHR (st.st_mode))
     return FAIL_EINVAL;
 
   /* Get the group ID of the special 'tty' group.  */
-  p = getgrnam (TTY_GROUP);
-  gid = p ? p->gr_gid : getgid ();
+  struct group *p = getgrnam (TTY_GROUP);
+  gid_t gid = p ? p->gr_gid : getgid ();
 
   /* Set the owner to the real user ID, and the group to that special
      group ID.  */
index 5117f495246c9b570b14a1a42b838afff5cec745..07991af605f422a1eb0104929b8a34a9cffebc09 100644 (file)
@@ -134,10 +134,9 @@ pthread_cond_timedwait (_GL_UNUSED pthread_cond_t *cond,
   for (;;)
     {
       struct timeval currtime;
-      unsigned long remaining;
-
       gettimeofday (&currtime, NULL);
 
+      unsigned long remaining;
       if (currtime.tv_sec > abstime->tv_sec)
         remaining = 0;
       else
index d4213c8f7ad3b7ba8b963aed1491a3c3135d972c..c470b3dc7cb8c8b6e2018bbd527b57e8b1cbcdda 100644 (file)
@@ -57,18 +57,20 @@ int
 pthread_rwlockattr_init (pthread_rwlockattr_t *attr)
 # undef pthread_rwlockattr_init
 {
-  int err;
-
-  err = pthread_rwlockattr_init (attr);
-  if (err != 0)
-    return err;
-  err = pthread_rwlockattr_setkind_np (attr,
-                                       PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
-  if (err != 0)
-    {
-      pthread_rwlockattr_destroy (attr);
+  {
+    int err = pthread_rwlockattr_init (attr);
+    if (err != 0)
       return err;
-    }
+  }
+  {
+    int err = pthread_rwlockattr_setkind_np (attr,
+                                             PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
+    if (err != 0)
+      {
+        pthread_rwlockattr_destroy (attr);
+        return err;
+      }
+  }
   return 0;
 }
 
@@ -144,17 +146,21 @@ int
 pthread_rwlock_init (pthread_rwlock_t *lock,
                      _GL_UNUSED const pthread_rwlockattr_t *attr)
 {
-  int err;
-
-  err = pthread_mutex_init (&lock->lock, NULL);
-  if (err != 0)
-    return err;
-  err = pthread_cond_init (&lock->waiting_readers, NULL);
-  if (err != 0)
-    return err;
-  err = pthread_cond_init (&lock->waiting_writers, NULL);
-  if (err != 0)
-    return err;
+  {
+    int err = pthread_mutex_init (&lock->lock, NULL);
+    if (err != 0)
+      return err;
+  }
+  {
+    int err = pthread_cond_init (&lock->waiting_readers, NULL);
+    if (err != 0)
+      return err;
+  }
+  {
+    int err = pthread_cond_init (&lock->waiting_writers, NULL);
+    if (err != 0)
+      return err;
+  }
   lock->waiting_writers_count = 0;
   lock->runcount = 0;
   return 0;
@@ -163,11 +169,11 @@ pthread_rwlock_init (pthread_rwlock_t *lock,
 int
 pthread_rwlock_rdlock (pthread_rwlock_t *lock)
 {
-  int err;
-
-  err = pthread_mutex_lock (&lock->lock);
-  if (err != 0)
-    return err;
+  {
+    int err = pthread_mutex_lock (&lock->lock);
+    if (err != 0)
+      return err;
+  }
   /* Test whether only readers are currently running, and whether the runcount
      field will not overflow, and whether no writer is waiting.  The latter
      condition is because POSIX recommends that "write locks shall take
@@ -176,7 +182,7 @@ pthread_rwlock_rdlock (pthread_rwlock_t *lock)
     {
       /* This thread has to wait for a while.  Enqueue it among the
          waiting_readers.  */
-      err = pthread_cond_wait (&lock->waiting_readers, &lock->lock);
+      int err = pthread_cond_wait (&lock->waiting_readers, &lock->lock);
       if (err != 0)
         {
           pthread_mutex_unlock (&lock->lock);
@@ -190,18 +196,18 @@ pthread_rwlock_rdlock (pthread_rwlock_t *lock)
 int
 pthread_rwlock_wrlock (pthread_rwlock_t *lock)
 {
-  int err;
-
-  err = pthread_mutex_lock (&lock->lock);
-  if (err != 0)
-    return err;
+  {
+    int err = pthread_mutex_lock (&lock->lock);
+    if (err != 0)
+      return err;
+  }
   /* Test whether no readers or writers are currently running.  */
   while (!(lock->runcount == 0))
     {
       /* This thread has to wait for a while.  Enqueue it among the
          waiting_writers.  */
       lock->waiting_writers_count++;
-      err = pthread_cond_wait (&lock->waiting_writers, &lock->lock);
+      int err = pthread_cond_wait (&lock->waiting_writers, &lock->lock);
       if (err != 0)
         {
           lock->waiting_writers_count--;
@@ -217,11 +223,11 @@ pthread_rwlock_wrlock (pthread_rwlock_t *lock)
 int
 pthread_rwlock_tryrdlock (pthread_rwlock_t *lock)
 {
-  int err;
-
-  err = pthread_mutex_lock (&lock->lock);
-  if (err != 0)
-    return err;
+  {
+    int err = pthread_mutex_lock (&lock->lock);
+    if (err != 0)
+      return err;
+  }
   /* Test whether only readers are currently running, and whether the runcount
      field will not overflow, and whether no writer is waiting.  The latter
      condition is because POSIX recommends that "write locks shall take
@@ -239,11 +245,11 @@ pthread_rwlock_tryrdlock (pthread_rwlock_t *lock)
 int
 pthread_rwlock_trywrlock (pthread_rwlock_t *lock)
 {
-  int err;
-
-  err = pthread_mutex_lock (&lock->lock);
-  if (err != 0)
-    return err;
+  {
+    int err = pthread_mutex_lock (&lock->lock);
+    if (err != 0)
+      return err;
+  }
   /* Test whether no readers or writers are currently running.  */
   if (!(lock->runcount == 0))
     {
@@ -259,11 +265,11 @@ int
 pthread_rwlock_timedrdlock (pthread_rwlock_t *lock,
                             const struct timespec *abstime)
 {
-  int err;
-
-  err = pthread_mutex_lock (&lock->lock);
-  if (err != 0)
-    return err;
+  {
+    int err = pthread_mutex_lock (&lock->lock);
+    if (err != 0)
+      return err;
+  }
   /* Test whether only readers are currently running, and whether the runcount
      field will not overflow, and whether no writer is waiting.  The latter
      condition is because POSIX recommends that "write locks shall take
@@ -272,8 +278,8 @@ pthread_rwlock_timedrdlock (pthread_rwlock_t *lock,
     {
       /* This thread has to wait for a while.  Enqueue it among the
          waiting_readers.  */
-      err = pthread_cond_timedwait (&lock->waiting_readers, &lock->lock,
-                                    abstime);
+      int err = pthread_cond_timedwait (&lock->waiting_readers, &lock->lock,
+                                        abstime);
       if (err != 0)
         {
           pthread_mutex_unlock (&lock->lock);
@@ -288,19 +294,19 @@ int
 pthread_rwlock_timedwrlock (pthread_rwlock_t *lock,
                             const struct timespec *abstime)
 {
-  int err;
-
-  err = pthread_mutex_lock (&lock->lock);
-  if (err != 0)
-    return err;
+  {
+    int err = pthread_mutex_lock (&lock->lock);
+    if (err != 0)
+      return err;
+  }
   /* Test whether no readers or writers are currently running.  */
   while (!(lock->runcount == 0))
     {
       /* This thread has to wait for a while.  Enqueue it among the
          waiting_writers.  */
       lock->waiting_writers_count++;
-      err = pthread_cond_timedwait (&lock->waiting_writers, &lock->lock,
-                                    abstime);
+      int err = pthread_cond_timedwait (&lock->waiting_writers, &lock->lock,
+                                        abstime);
       if (err != 0)
         {
           lock->waiting_writers_count--;
@@ -316,11 +322,11 @@ pthread_rwlock_timedwrlock (pthread_rwlock_t *lock,
 int
 pthread_rwlock_unlock (pthread_rwlock_t *lock)
 {
-  int err;
-
-  err = pthread_mutex_lock (&lock->lock);
-  if (err != 0)
-    return err;
+  {
+    int err = pthread_mutex_lock (&lock->lock);
+    if (err != 0)
+      return err;
+  }
   if (lock->runcount < 0)
     {
       /* Drop a writer lock.  */
@@ -348,7 +354,7 @@ pthread_rwlock_unlock (pthread_rwlock_t *lock)
       if (lock->waiting_writers_count > 0)
         {
           /* Wake up one of the waiting writers.  */
-          err = pthread_cond_signal (&lock->waiting_writers);
+          int err = pthread_cond_signal (&lock->waiting_writers);
           if (err != 0)
             {
               pthread_mutex_unlock (&lock->lock);
@@ -358,7 +364,7 @@ pthread_rwlock_unlock (pthread_rwlock_t *lock)
       else
         {
           /* Wake up all waiting readers.  */
-          err = pthread_cond_broadcast (&lock->waiting_readers);
+          int err = pthread_cond_broadcast (&lock->waiting_readers);
           if (err != 0)
             {
               pthread_mutex_unlock (&lock->lock);
@@ -372,17 +378,21 @@ pthread_rwlock_unlock (pthread_rwlock_t *lock)
 int
 pthread_rwlock_destroy (pthread_rwlock_t *lock)
 {
-  int err;
-
-  err = pthread_mutex_destroy (&lock->lock);
-  if (err != 0)
-    return err;
-  err = pthread_cond_destroy (&lock->waiting_readers);
-  if (err != 0)
-    return err;
-  err = pthread_cond_destroy (&lock->waiting_writers);
-  if (err != 0)
-    return err;
+  {
+    int err = pthread_mutex_destroy (&lock->lock);
+    if (err != 0)
+      return err;
+  }
+  {
+    int err = pthread_cond_destroy (&lock->waiting_readers);
+    if (err != 0)
+      return err;
+  }
+  {
+    int err = pthread_cond_destroy (&lock->waiting_writers);
+    if (err != 0)
+      return err;
+  }
   return 0;
 }
 
@@ -397,28 +407,31 @@ int
 pthread_rwlock_init (pthread_rwlock_t *lock, const pthread_rwlockattr_t *attr)
 #   undef pthread_rwlock_init
 {
-  int err;
-
   if (attr != NULL)
-    err = pthread_rwlock_init (lock, attr);
+    return pthread_rwlock_init (lock, attr);
   else
     {
       pthread_rwlockattr_t replacement_attr;
-
-      err = pthread_rwlockattr_init (&replacement_attr);
-      if (err != 0)
-        return err;
-      err = pthread_rwlockattr_setkind_np (&replacement_attr,
-                                           PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
-      if (err != 0)
-        {
-          pthread_rwlockattr_destroy (&replacement_attr);
+      {
+        int err = pthread_rwlockattr_init (&replacement_attr);
+        if (err != 0)
           return err;
-        }
-      err = pthread_rwlock_init (lock, &replacement_attr);
-      pthread_rwlockattr_destroy (&replacement_attr);
+      }
+      {
+        int err = pthread_rwlockattr_setkind_np (&replacement_attr,
+                                                 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
+        if (err != 0)
+          {
+            pthread_rwlockattr_destroy (&replacement_attr);
+            return err;
+          }
+      }
+      {
+        int err = pthread_rwlock_init (lock, &replacement_attr);
+        pthread_rwlockattr_destroy (&replacement_attr);
+        return err;
+      }
     }
-  return err;
 }
 
 #  endif
@@ -432,16 +445,16 @@ pthread_rwlock_timedrdlock (pthread_rwlock_t *lock,
   /* Poll the lock's state in regular intervals.  Ugh.  */
   for (;;)
     {
-      int err;
-      struct timeval currtime;
-      unsigned long remaining;
-
-      err = pthread_rwlock_tryrdlock (lock);
-      if (err != EBUSY)
-        return err;
+      {
+        int err = pthread_rwlock_tryrdlock (lock);
+        if (err != EBUSY)
+          return err;
+      }
 
+      struct timeval currtime;
       gettimeofday (&currtime, NULL);
 
+      unsigned long remaining;
       if (currtime.tv_sec > abstime->tv_sec)
         remaining = 0;
       else
@@ -489,16 +502,16 @@ pthread_rwlock_timedwrlock (pthread_rwlock_t *lock,
   /* Poll the lock's state in regular intervals.  Ugh.  */
   for (;;)
     {
-      int err;
-      struct timeval currtime;
-      unsigned long remaining;
-
-      err = pthread_rwlock_trywrlock (lock);
-      if (err != EBUSY)
-        return err;
+      {
+        int err = pthread_rwlock_trywrlock (lock);
+        if (err != EBUSY)
+          return err;
+      }
 
+      struct timeval currtime;
       gettimeofday (&currtime, NULL);
 
+      unsigned long remaining;
       if (currtime.tv_sec > abstime->tv_sec)
         remaining = 0;
       else
index 0249dc0c76b3a7d3ec09d2f716b852e66ee9c8e2..fa1bb4f03c365f12fc5297246eda9bebb6d396ed 100644 (file)
@@ -40,16 +40,16 @@ pthread_mutex_timedlock (pthread_mutex_t *mutex, const struct timespec *abstime)
      Therefore start the loop with a pthread_mutex_trylock call.  */
   for (;;)
     {
-      int err;
-      struct timeval currtime;
-      unsigned long remaining;
-
-      err = pthread_mutex_trylock (mutex);
-      if (err != EBUSY)
-        return err;
+      {
+        int err = pthread_mutex_trylock (mutex);
+        if (err != EBUSY)
+          return err;
+      }
 
+      struct timeval currtime;
       gettimeofday (&currtime, NULL);
 
+      unsigned long remaining;
       if (currtime.tv_sec > abstime->tv_sec)
         remaining = 0;
       else
index 0d0a5c211da4dd1b31c3a1dec3eda91fe67ec125..a7d78f246f951898cce4e0877ba94b17b43c9e2b 100644 (file)
@@ -31,21 +31,20 @@ pthread_sigmask (int how, const sigset_t *new_mask, sigset_t *old_mask)
 #undef pthread_sigmask
 {
 #if HAVE_PTHREAD_SIGMASK
-  int ret;
-
 # if PTHREAD_SIGMASK_INEFFECTIVE
-  sigset_t omask, omask_copy;
+  sigset_t omask;
   sigset_t *old_mask_ptr = &omask;
   sigemptyset (&omask);
   /* Add a signal unlikely to be blocked, so that OMASK_COPY
      is unlikely to match the actual mask.  */
   sigaddset (&omask, SIGILL);
+  sigset_t omask_copy;
   memcpy (&omask_copy, &omask, sizeof omask);
 # else
   sigset_t *old_mask_ptr = old_mask;
 # endif
 
-  ret = pthread_sigmask (how, new_mask, old_mask_ptr);
+  int ret = pthread_sigmask (how, new_mask, old_mask_ptr);
 
 # if PTHREAD_SIGMASK_INEFFECTIVE
   if (ret == 0)
index 541af1b0836163cc9bf19971052d4e8c0f35a4c4..cbee3781dfec94adbc9ad647fad3adc25a92b6c8 100644 (file)
@@ -69,9 +69,9 @@ ptsname_r (int fd, char *buf, size_t buflen)
 {
 #if HAVE_ESSENTIALLY_WORKING_PTSNAME_R
 # if defined __NetBSD__ || defined __sun
-  char tmpbuf[32];
   if (buf == NULL)
     return EINVAL;
+  char tmpbuf[32];
   if (buflen >= sizeof (tmpbuf))
     /* ERANGE should not happen in this case.  */
     return ptsname_r (fd, buf, buflen);
@@ -97,17 +97,15 @@ ptsname_r (int fd, char *buf, size_t buflen)
     return errno;
 # endif
 #elif defined __DragonFly__
-  int saved_errno = errno;
-  char tmpbuf[5 + 4 + 10 + 1];
-  int ret;
-  int n;
   if (buf == NULL)
     {
       errno = EINVAL;
       return errno;
     }
+  int saved_errno = errno;
+  char tmpbuf[5 + 4 + 10 + 1];
   /* The result of fdevname_r is typically of the form ptm/N.  */
-  ret = fdevname_r (fd, tmpbuf + 5, sizeof (tmpbuf) - 5);
+  int ret = fdevname_r (fd, tmpbuf + 5, sizeof (tmpbuf) - 5);
   if (ret < 0 || strncmp (tmpbuf + 5, "ptm/", 4) != 0)
     {
       errno = ENOTTY;
@@ -115,7 +113,7 @@ ptsname_r (int fd, char *buf, size_t buflen)
     }
   /* Turn it into /dev/pts/N.  */
   memcpy (tmpbuf, "/dev/pts/", 5 + 4);
-  n = strlen (tmpbuf);
+  int n = strlen (tmpbuf);
   if (n >= buflen)
     {
       errno = ERANGE;
@@ -127,15 +125,15 @@ ptsname_r (int fd, char *buf, size_t buflen)
   errno = saved_errno;
   return 0;
 #else
-  int saved_errno = errno;
-  struct stat st;
-
   if (buf == NULL)
     {
       errno = EINVAL;
       return errno;
     }
 
+  int saved_errno = errno;
+  struct stat st;
+
 # if defined __sun /* Solaris */
   if (fstat (fd, &st) < 0)
     return errno;
@@ -185,17 +183,15 @@ ptsname_r (int fd, char *buf, size_t buflen)
       return errno;
     }
   {
-    int ret;
     int dev;
-    char tmpbuf[9 + 10 + 1];
-    int n;
-    ret = ioctl (fd, ISPTM, &dev);
+    int ret = ioctl (fd, ISPTM, &dev);
     if (ret < 0)
       {
         errno = ENOTTY;
         return errno;
       }
-    n = sprintf (tmpbuf, "/dev/pts/%u", minor (dev));
+    char tmpbuf[9 + 10 + 1];
+    int n = sprintf (tmpbuf, "/dev/pts/%u", minor (dev));
     if (n >= buflen)
       {
         errno = ERANGE;
index 2c29d8033a1d0c5b1e07042c546c46cb5017b166..3407c73299758874c552844d15c295994de82a49 100644 (file)
@@ -96,14 +96,13 @@ putenv (char *string)
       /* _putenv ("NAME=") unsets NAME, so invoke _putenv ("NAME= ")
          to allocate the environ vector and then replace the new
          entry with "NAME=".  */
-      int putenv_result;
       char *name_x = malloc (name_end - string + sizeof "= ");
       if (!name_x)
         return -1;
       memcpy (name_x, string, name_end - string + 1);
       name_x[name_end - string + 1] = ' ';
       name_x[name_end - string + 2] = 0;
-      putenv_result = _putenv (name_x);
+      int putenv_result = _putenv (name_x);
       for (char **ep = environ; *ep; ep++)
         if (streq (*ep, name_x))
           {
index 551443295311f52fddb0ecdd61ddcb060a48ea55..8aa36848f04cae8b5747d0beb030d9816a81e8e5 100644 (file)
@@ -35,8 +35,6 @@ pwrite (int fd, const void *buf, size_t nbyte, off_t offset)
 {
   /* Since we must not change the file pointer preserve the value so that
      we can restore it later.  */
-  int saved_errno;
-  ssize_t result;
   off_t old_offset = __libc_lseek (fd, 0, SEEK_CUR);
   if (old_offset == (off_t) -1)
     return -1;
@@ -46,12 +44,12 @@ pwrite (int fd, const void *buf, size_t nbyte, off_t offset)
     return -1;
 
   /* Write out the data.  */
-  result = __libc_write (fd, buf, nbyte);
+  ssize_t result = __libc_write (fd, buf, nbyte);
 
   /* Now we have to restore the position.  If this fails we have to
      return this as an error.  But if the writing also failed we
      return this error.  */
-  saved_errno = errno;
+  int saved_errno = errno;
   if (__libc_lseek (fd, old_offset, SEEK_SET) == (off_t) -1)
     {
       if (result == -1)
index e86e15544f6b4a94f42bc040d4609ff1b3baad71..6ec98e8d08c436762edce338a0265fad95c841a2 100644 (file)
@@ -114,11 +114,11 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name,
 #else
   /* no XATTR, so we proceed the old dusty way */
   struct permission_context ctx;
-
-  ret = get_permissions (src_name, source_desc, mode, &ctx);
-  if (ret != 0)
+  if (get_permissions (src_name, source_desc, mode, &ctx) != 0)
     return -2;
+
   ret = set_permissions (&ctx, dst_name, dest_desc);
+
   free_permission_context (&ctx);
 #endif
   return ret;
index 7e3f79a2b0a1af5feae762e990d885b82bcad622..657aa43be7cebae87cc543ecf8bede8c76d75802 100644 (file)
@@ -39,11 +39,12 @@ int
 qset_acl (char const *name, int desc, mode_t mode)
 {
   struct permission_context ctx;
-  int ret;
-
   memset (&ctx, 0, sizeof ctx);
   ctx.mode = mode;
-  ret = set_permissions (&ctx, name, desc);
+
+  int ret = set_permissions (&ctx, name, desc);
+
   free_permission_context (&ctx);
+
   return ret;
 }
index 2f5898312b93ea0f37026da97194d88c2f330879..c992235f8ba5f8e2f91fb0691cc8c5d1038b3ccc 100644 (file)
@@ -98,14 +98,14 @@ void
 _quicksort (void *const pbase, size_t total_elems, size_t size,
            __compar_d_fn_t cmp, void *arg)
 {
-  char *base_ptr = (char *) pbase;
-
-  const size_t max_thresh = MAX_THRESH * size;
-
   if (total_elems == 0)
     /* Avoid lossage with unsigned arithmetic below.  */
     return;
 
+  char *base_ptr = (char *) pbase;
+
+  const size_t max_thresh = MAX_THRESH * size;
+
   if (total_elems > MAX_THRESH)
     {
       char *lo = base_ptr;
@@ -214,7 +214,7 @@ _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 *thresh = min (end_ptr, base_ptr + max_thresh);
 
     /* Find smallest element in first threshold and place it at the
        array's beginning.  This is the smallest array element,
@@ -239,9 +239,7 @@ _quicksort (void *const pbase, size_t total_elems, size_t size,
        tmp_ptr += size;
         if (tmp_ptr != run_ptr)
           {
-            char *trav;
-
-           trav = run_ptr + size;
+            char *trav = run_ptr + size;
            while (--trav >= run_ptr)
               {
                 char c = *trav;
index b3c1c9ae4abe55b59fac2e31b02a2ca54b723109..12954cbf125edecc66d77a5cc887cb3201baaa22 100644 (file)
@@ -158,10 +158,9 @@ set_char_quoting (struct quoting_options *o, char c, int i)
 int
 set_quoting_flags (struct quoting_options *o, int i)
 {
-  int r;
   if (!o)
     o = &default_quoting_options;
-  r = o->flags;
+  int r = o->flags;
   o->flags = i;
   return r;
 }
@@ -256,12 +255,13 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
                           char const *left_quote,
                           char const *right_quote)
 {
+  bool unibyte_locale = MB_CUR_MAX == 1;
+
   size_t len = 0;
   size_t orig_buffersize = 0;
   char const *quote_string = NULL;
   size_t quote_string_len = 0;
   bool backslash_escapes = false;
-  bool unibyte_locale = MB_CUR_MAX == 1;
   bool elide_outer_quotes = (flags & QA_ELIDE_OUTER_QUOTES) != 0;
   bool encountered_single_quote = false;
   bool all_c_and_shell_quote_compat = true;
@@ -358,8 +358,8 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
             right_quote = gettext_quote (N_("'"), quoting_style);
           }
         if (!elide_outer_quotes)
-          for (quote_string = left_quote; *quote_string; quote_string++)
-            STORE (*quote_string);
+          for (char const *lq = left_quote; *lq; lq++)
+            STORE (*lq);
         backslash_escapes = true;
         quote_string = right_quote;
         quote_string_len = strlen (quote_string);
@@ -394,8 +394,6 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
 
   for (size_t i = 0;  ! (argsize == SIZE_MAX ? arg[i] == '\0' : i == argsize);  i++)
     {
-      unsigned char c;
-      unsigned char esc;
       bool is_right_quote = false;
       bool escaping = false;
       bool c_and_shell_quote_compat = false;
@@ -416,7 +414,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
           is_right_quote = true;
         }
 
-      c = arg[i];
+      unsigned char c = arg[i];
       switch (c)
         {
         case '\0':
@@ -477,39 +475,43 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
             }
           break;
 
-        case '\a': esc = 'a'; goto c_escape;
-        case '\b': esc = 'b'; goto c_escape;
-        case '\f': esc = 'f'; goto c_escape;
-        case '\n': esc = 'n'; goto c_and_shell_escape;
-        case '\r': esc = 'r'; goto c_and_shell_escape;
-        case '\t': esc = 't'; goto c_and_shell_escape;
-        case '\v': esc = 'v'; goto c_escape;
-        case '\\': esc = c;
-          /* Never need to escape '\' in shell case.  */
-          if (quoting_style == shell_always_quoting_style)
-            {
-              if (elide_outer_quotes)
-                goto force_outer_quoting_style;
-              goto store_c;
-            }
+        {
+          unsigned char esc;
+
+          case '\a': esc = 'a'; goto c_escape;
+          case '\b': esc = 'b'; goto c_escape;
+          case '\f': esc = 'f'; goto c_escape;
+          case '\n': esc = 'n'; goto c_and_shell_escape;
+          case '\r': esc = 'r'; goto c_and_shell_escape;
+          case '\t': esc = 't'; goto c_and_shell_escape;
+          case '\v': esc = 'v'; goto c_escape;
+          case '\\': esc = c;
+            /* Never need to escape '\' in shell case.  */
+            if (quoting_style == shell_always_quoting_style)
+              {
+                if (elide_outer_quotes)
+                  goto force_outer_quoting_style;
+                goto store_c;
+              }
 
-          /* No need to escape the escape if we are trying to elide
-             outer quotes and nothing else is problematic.  */
-          if (backslash_escapes && elide_outer_quotes && quote_string_len)
-            goto store_c;
+            /* No need to escape the escape if we are trying to elide
+               outer quotes and nothing else is problematic.  */
+            if (backslash_escapes && elide_outer_quotes && quote_string_len)
+              goto store_c;
 
-        c_and_shell_escape:
-          if (quoting_style == shell_always_quoting_style
-              && elide_outer_quotes)
-            goto force_outer_quoting_style;
-          /* fall through */
-        c_escape:
-          if (backslash_escapes)
-            {
-              c = esc;
-              goto store_escape;
-            }
-          break;
+          c_and_shell_escape:
+            if (quoting_style == shell_always_quoting_style
+                && elide_outer_quotes)
+              goto force_outer_quoting_style;
+            /* fall through */
+          c_escape:
+            if (backslash_escapes)
+              {
+                c = esc;
+                goto store_escape;
+              }
+            break;
+        }
 
         case '{': case '}': /* sometimes special if isolated */
           if (! (argsize == SIZE_MAX ? arg[1] == '\0' : argsize == 1))
index e0d4b07a34471e6c300ff6bb6173fe169fd117b8..4b7eb6ad8ba8baaab4d59ebeca20fbb519c37582 100644 (file)
@@ -246,14 +246,11 @@ weak_alias (__srandom, srand)
 char *
 __initstate (unsigned int seed, char *arg_state, size_t n)
 {
-  int32_t *ostate;
-  int ret;
-
   __libc_lock_lock (lock);
 
-  ostate = &unsafe_state.state[-1];
+  int32_t *ostate = &unsafe_state.state[-1];
 
-  ret = __initstate_r (seed, arg_state, n, &unsafe_state);
+  int ret = __initstate_r (seed, arg_state, n, &unsafe_state);
 
   __libc_lock_unlock (lock);
 
@@ -273,11 +270,9 @@ weak_alias (__initstate, initstate)
 char *
 __setstate (char *arg_state)
 {
-  int32_t *ostate;
-
   __libc_lock_lock (lock);
 
-  ostate = &unsafe_state.state[-1];
+  int32_t *ostate = &unsafe_state.state[-1];
 
   if (__setstate_r (arg_state, &unsafe_state) < 0)
     ostate = NULL;
@@ -303,10 +298,9 @@ weak_alias (__setstate, setstate)
 long int
 __random (void)
 {
-  int32_t retval;
-
   __libc_lock_lock (lock);
 
+  int32_t retval;
   (void) __random_r (&unsafe_state, &retval);
 
   __libc_lock_unlock (lock);
index 23bcd449c5cf66f9775c52e7aa0ccbbdb58420e5..ec53c2e303cc6ee8d3f1aa040926f11040434f42 100644 (file)
@@ -187,19 +187,13 @@ set_int32 (void *p, int32_t v)
 int
 __srandom_r (unsigned int seed, struct random_data *buf)
 {
-  int type;
-  int32_t *state;
-  int32_t word;
-  int32_t *dst;
-  int kc;
-
   if (buf == NULL)
     goto fail;
-  type = buf->rand_type;
+  int type = buf->rand_type;
   if ((unsigned int) type >= MAX_TYPES)
     goto fail;
 
-  state = buf->state;
+  int32_t *state = buf->state;
   /* We must make sure the seed is not 0.  Take arbitrarily 1 in this case.  */
   if (seed == 0)
     seed = 1;
@@ -207,9 +201,9 @@ __srandom_r (unsigned int seed, struct random_data *buf)
   if (type == TYPE_0)
     goto done;
 
-  dst = state;
-  word = seed;
-  kc = buf->rand_deg;
+  int32_t *dst = state;
+  int32_t word = seed;
+  int kc = buf->rand_deg;
   for (long int i = 1; i < kc; ++i)
     {
       /* This does:
@@ -320,28 +314,26 @@ int
 __setstate_r (char *arg_state, struct random_data *buf)
 {
   int32_t *new_state = 1 + (int32_t *) arg_state;
-  int type;
-  int old_type;
-  int32_t *old_state;
-  int degree;
-  int separation;
 
   if (arg_state == NULL || buf == NULL)
     goto fail;
 
-  old_type = buf->rand_type;
-  old_state = buf->state;
+  int old_type = buf->rand_type;
+  int32_t *old_state = buf->state;
   set_int32 (&old_state[-1],
              (old_type == TYPE_0
               ? TYPE_0
               : (MAX_TYPES * (buf->rptr - old_state)) + old_type));
 
-  type = get_int32 (&new_state[-1]) % MAX_TYPES;
+  int type = get_int32 (&new_state[-1]) % MAX_TYPES;
   if (type < TYPE_0 || type > TYPE_4)
     goto fail;
 
-  buf->rand_deg = degree = random_poly_info.degrees[type];
-  buf->rand_sep = separation = random_poly_info.seps[type];
+  int degree = random_poly_info.degrees[type];
+  int separation = random_poly_info.seps[type];
+
+  buf->rand_deg = degree;
+  buf->rand_sep = separation;
   buf->rand_type = type;
 
   if (type != TYPE_0)
@@ -377,12 +369,10 @@ weak_alias (__setstate_r, setstate_r)
 int
 __random_r (struct random_data *buf, int32_t *result)
 {
-  int32_t *state;
-
   if (buf == NULL || result == NULL)
     goto fail;
 
-  state = buf->state;
+  int32_t *state = buf->state;
 
   if (buf->rand_type == TYPE_0)
     {
index afdd7672d2944e3ac6f48c7fb6a28536022cbdbc..08ce88c3da64d8188279a53adffc7d191180e863 100644 (file)
@@ -46,89 +46,100 @@ rawmemchr (const void *s, int c_in)
   /* Verify that the longword type lacks padding bits.  */
   static_assert (UINTPTR_WIDTH == UCHAR_WIDTH * sizeof (uintptr_t));
 
-  const unsigned char *char_ptr;
   unsigned char c = c_in;
 
-  /* Handle the first few bytes by reading one byte at a time.
-     Do this until CHAR_PTR is aligned on a natural longword boundary,
-     as using alignof (longword) might be slower.  */
-  for (char_ptr = (const unsigned char *) s;
-       (uintptr_t) char_ptr % sizeof (longword) != 0;
-       ++char_ptr)
-    if (*char_ptr == c)
-      return (void *) char_ptr;
-
-  longword const *longword_ptr = s = char_ptr;
-
-  /* Compute auxiliary longword values:
-     repeated_one is a value which has a 1 in every byte.
-     repeated_c has c in every byte.  */
-  longword repeated_one = (longword) -1 / UCHAR_MAX;
-  longword repeated_c = repeated_one * c;
-  longword repeated_hibit = repeated_one * (UCHAR_MAX / 2 + 1);
-
-  /* Instead of the traditional loop which tests each byte, we will
-     test a longword at a time.  The tricky part is testing if any of
-     the bytes in the longword in question are equal to
-     c.  We first use an xor with repeated_c.  This reduces the task
-     to testing whether any of the bytes in longword1 is zero.
-
-     (The following comments assume 8-bit bytes, as POSIX requires;
-     the code's use of UCHAR_MAX should work even if bytes have more
-     than 8 bits.)
-
-     We compute tmp =
-       ((longword1 - repeated_one) & ~longword1) & (repeated_one * 0x80).
-     That is, we perform the following operations:
-       1. Subtract repeated_one.
-       2. & ~longword1.
-       3. & a mask consisting of 0x80 in every byte.
-     Consider what happens in each byte:
-       - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
-         and step 3 transforms it into 0x80.  A carry can also be propagated
-         to more significant bytes.
-       - If a byte of longword1 is nonzero, let its lowest 1 bit be at
-         position k (0 <= k <= 7); so the lowest k bits are 0.  After step 1,
-         the byte ends in a single bit of value 0 and k bits of value 1.
-         After step 2, the result is just k bits of value 1: 2^k - 1.  After
-         step 3, the result is 0.  And no carry is produced.
-     So, if longword1 has only non-zero bytes, tmp is zero.
-     Whereas if longword1 has a zero byte, call j the position of the least
-     significant zero byte.  Then the result has a zero at positions 0, ...,
-     j-1 and a 0x80 at position j.  We cannot predict the result at the more
-     significant bytes (positions j+1..3), but it does not matter since we
-     already have a non-zero bit at position 8*j+7.
-
-     The test whether any byte in longword1 is zero is equivalent
-     to testing whether tmp is nonzero.
-
-     This test can read beyond the end of a string, depending on where
-     C_IN is encountered.  However, this is considered safe since the
-     initialization phase ensured that the read will be aligned,
-     therefore, the read will not cross page boundaries and will not
-     cause a fault.  */
-
-  while (1)
-    {
-      longword longword1 = *longword_ptr ^ repeated_c;
-
-      if ((((longword1 - repeated_one) & ~longword1) & repeated_hibit) != 0)
-        break;
-      longword_ptr++;
-    }
-
-  char_ptr = s = longword_ptr;
-
-  /* At this point, we know that one of the sizeof (longword) bytes
-     starting at char_ptr is == c.  If we knew endianness, we
-     could determine the first such byte without any further memory
-     accesses, just by looking at the tmp result from the last loop
-     iteration.  However, the following simple and portable code does
-     not attempt this potential optimization.  */
-
-  while (*char_ptr != c)
-    char_ptr++;
-  return (void *) char_ptr;
+  {
+    const unsigned char *char_ptr;
+
+    /* Handle the first few bytes by reading one byte at a time.
+       Do this until CHAR_PTR is aligned on a natural longword boundary,
+       as using alignof (longword) might be slower.  */
+    for (char_ptr = (const unsigned char *) s;
+         (uintptr_t) char_ptr % sizeof (longword) != 0;
+         ++char_ptr)
+      if (*char_ptr == c)
+        return (void *) char_ptr;
+
+    s = char_ptr;
+  }
+
+  {
+    longword const *longword_ptr = s;
+
+    /* Compute auxiliary longword values:
+       repeated_one is a value which has a 1 in every byte.
+       repeated_c has c in every byte.  */
+    longword repeated_one = (longword) -1 / UCHAR_MAX;
+    longword repeated_c = repeated_one * c;
+    longword repeated_hibit = repeated_one * (UCHAR_MAX / 2 + 1);
+
+    /* Instead of the traditional loop which tests each byte, we will
+       test a longword at a time.  The tricky part is testing if any of
+       the bytes in the longword in question are equal to
+       c.  We first use an xor with repeated_c.  This reduces the task
+       to testing whether any of the bytes in longword1 is zero.
+
+       (The following comments assume 8-bit bytes, as POSIX requires;
+       the code's use of UCHAR_MAX should work even if bytes have more
+       than 8 bits.)
+
+       We compute tmp =
+         ((longword1 - repeated_one) & ~longword1) & (repeated_one * 0x80).
+       That is, we perform the following operations:
+         1. Subtract repeated_one.
+         2. & ~longword1.
+         3. & a mask consisting of 0x80 in every byte.
+       Consider what happens in each byte:
+         - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
+           and step 3 transforms it into 0x80.  A carry can also be propagated
+           to more significant bytes.
+         - If a byte of longword1 is nonzero, let its lowest 1 bit be at
+           position k (0 <= k <= 7); so the lowest k bits are 0.  After step 1,
+           the byte ends in a single bit of value 0 and k bits of value 1.
+           After step 2, the result is just k bits of value 1: 2^k - 1.  After
+           step 3, the result is 0.  And no carry is produced.
+       So, if longword1 has only non-zero bytes, tmp is zero.
+       Whereas if longword1 has a zero byte, call j the position of the least
+       significant zero byte.  Then the result has a zero at positions 0, ...,
+       j-1 and a 0x80 at position j.  We cannot predict the result at the more
+       significant bytes (positions j+1..3), but it does not matter since we
+       already have a non-zero bit at position 8*j+7.
+
+       The test whether any byte in longword1 is zero is equivalent
+       to testing whether tmp is nonzero.
+
+       This test can read beyond the end of a string, depending on where
+       C_IN is encountered.  However, this is considered safe since the
+       initialization phase ensured that the read will be aligned,
+       therefore, the read will not cross page boundaries and will not
+       cause a fault.  */
+
+    while (1)
+      {
+        longword longword1 = *longword_ptr ^ repeated_c;
+
+        if ((((longword1 - repeated_one) & ~longword1) & repeated_hibit) != 0)
+          break;
+        longword_ptr++;
+      }
+
+    s = longword_ptr;
+  }
+
+  {
+    const unsigned char *char_ptr = s;
+
+    /* At this point, we know that one of the sizeof (longword) bytes
+       starting at char_ptr is == c.  If we knew endianness, we
+       could determine the first such byte without any further memory
+       accesses, just by looking at the tmp result from the last loop
+       iteration.  However, the following simple and portable code does
+       not attempt this potential optimization.  */
+
+    while (*char_ptr != c)
+      char_ptr++;
+    return (void *) char_ptr;
+  }
 # endif
 }
 
index 1c06dd73ef09634c917fdf80fce5618090ccec06..df750e56750ab6a962327bbfaebc2411179a9fbe 100644 (file)
@@ -51,7 +51,6 @@
 char *
 fread_file (FILE *stream, int flags, size_t *length)
 {
-  char *buf;
   size_t alloc = BUFSIZ;
 
   /* For a regular file, allocate a buffer that has exactly the right
@@ -79,7 +78,8 @@ fread_file (FILE *stream, int flags, size_t *length)
       }
   }
 
-  if (!(buf = malloc (alloc)))
+  char *buf = malloc (alloc);
+  if (!buf)
     return NULL; /* errno is ENOMEM.  */
 
   {
@@ -191,7 +191,6 @@ read_file (const char *filename, int flags, size_t *length)
 {
   const char *mode = (flags & RF_BINARY) ? "rbe" : "re";
   FILE *stream = fopen (filename, mode);
-  char *out;
 
   if (!stream)
     return NULL;
@@ -199,7 +198,7 @@ read_file (const char *filename, int flags, size_t *length)
   if (flags & RF_SENSITIVE)
     setvbuf (stream, NULL, _IONBF, 0);
 
-  out = fread_file (stream, flags, length);
+  char *out = fread_file (stream, flags, length);
 
   if (fclose (stream) != 0)
     {
index 78225ec486d1d54ecd8e0a1d1f2b1f98f6ed1192..e2b67b43e48f220de6f86bf2b97dbf23c306b6c3 100644 (file)
@@ -37,9 +37,6 @@ readdir (DIR *dirp)
 #if HAVE_DIRENT_H                       /* equivalent to HAVE_READDIR */
   return readdir (dirp->real_dirp);
 #else
-  char type;
-  struct dirent *result;
-
   /* There is no need to add code to produce entries for "." and "..".
      According to the POSIX:2008 section "4.12 Pathname Resolution"
      <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html>
@@ -77,6 +74,7 @@ readdir (DIR *dirp)
 
   dirp->status = 0;
 
+  char type;
   if (dirp->entry.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
     type = DT_DIR;
   else if (dirp->entry.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
@@ -99,7 +97,7 @@ readdir (DIR *dirp)
     type = DT_UNKNOWN;
 
   /* Reuse the memory of dirp->entry for the result.  */
-  result =
+  struct dirent *result =
     (struct dirent *)
     ((char *) dirp->entry.cFileName - offsetof (struct dirent, d_name[0]));
   result->d_type = type;
index 3d5ae430f335a9dad45254ec33ffc79b571d027c..ce89d9701668b90a2bf080e0a50efd52f08af300 100644 (file)
 char *
 readline (const char *prompt)
 {
-  char *out = NULL;
-  size_t size = 0;
-
   if (prompt)
     {
       fputs (prompt, stdout);
       fflush (stdout);
     }
 
+  char *out = NULL;
+  size_t size = 0;
   if (getline (&out, &size, stdin) < 0)
     {
       free (out);
index e9c40791e8a9e006c32415a8ddfe3b3f691e96be..83827a7700a6842e4b189b43c17b464deb8061b2 100644 (file)
@@ -81,9 +81,7 @@ readtoken (FILE *stream,
            size_t n_delim,
            token_buffer *tokenbuffer)
 {
-  int c;
   word isdelim[(UCHAR_MAX + bits_per_word) / bits_per_word];
-
   memset (isdelim, 0, sizeof isdelim);
   for (idx_t i = 0; i < n_delim; i++)
     {
@@ -91,6 +89,8 @@ readtoken (FILE *stream,
       set_nth_bit (ch, isdelim);
     }
 
+  int c;
+
   /* skip over any leading delimiters */
   for (c = getc (stream); c >= 0 && get_nth_bit (c, isdelim); c = getc (stream))
     {
@@ -142,25 +142,22 @@ readtokens (FILE *stream,
             char ***tokens_out,
             size_t **token_lengths)
 {
-  token_buffer tb, *token = &tb;
-  char **tokens;
-  size_t *lengths;
-  idx_t sz, n_tokens;
 
   if (projected_n_tokens == 0)
     projected_n_tokens = 64;
   else
     projected_n_tokens++;       /* add one for trailing NULL pointer */
 
-  sz = projected_n_tokens;
-  tokens = xnmalloc (sz, sizeof *tokens);
-  lengths = xnmalloc (sz, sizeof *lengths);
+  idx_t sz = projected_n_tokens;
+  char **tokens = xnmalloc (sz, sizeof *tokens);
+  size_t *lengths = xnmalloc (sz, sizeof *lengths);
 
-  n_tokens = 0;
+  token_buffer tb;
+  token_buffer *token = &tb;
   init_tokenbuffer (token);
+  idx_t n_tokens = 0;
   for (;;)
     {
-      char *tmp;
       size_t token_length = readtoken (stream, delim, n_delim, token);
       if (n_tokens >= sz)
         {
@@ -175,7 +172,7 @@ readtokens (FILE *stream,
           lengths[n_tokens] = 0;
           break;
         }
-      tmp = xnmalloc (token_length + 1, sizeof *tmp);
+      char *tmp = xnmalloc (token_length + 1, sizeof *tmp);
       lengths[n_tokens] = token_length;
       tokens[n_tokens] = memcpy (tmp, token->buffer, token_length + 1);
       n_tokens++;
index 456f8921cd927a67c3daa85f910b00344155c0ac..a31c4db9b9f553efc167fed50b757f16d29120a5 100644 (file)
@@ -62,32 +62,31 @@ struct regex_quote_spec
 regex_quote_spec_gnu (unsigned long /*reg_syntax_t*/ syntax, bool anchored)
 {
   struct regex_quote_spec result;
-  char *p;
-
-  p = result.special;
-  memcpy (p, bre_special, sizeof (bre_special) - 1);
-  p += sizeof (bre_special) - 1;
-  if ((syntax & RE_LIMITED_OPS) == 0 && (syntax & RE_BK_PLUS_QM) == 0)
-    {
-      *p++ = '+';
-      *p++ = '?';
-    }
-  if ((syntax & RE_INTERVALS) != 0 && (syntax & RE_NO_BK_BRACES) != 0)
-    {
-      *p++ = '{';
-      *p++ = '}';
-    }
-  if ((syntax & RE_NO_BK_PARENS) != 0)
-    {
-      *p++ = '(';
-      *p++ = ')';
-    }
-  if ((syntax & RE_LIMITED_OPS) == 0 && (syntax & RE_NO_BK_VBAR) != 0)
-    *p++ = '|';
-  if ((syntax & RE_NEWLINE_ALT) != 0)
-    *p++ = '\n';
-  *p = '\0';
-
+  {
+    char *p = result.special;
+    memcpy (p, bre_special, sizeof (bre_special) - 1);
+    p += sizeof (bre_special) - 1;
+    if ((syntax & RE_LIMITED_OPS) == 0 && (syntax & RE_BK_PLUS_QM) == 0)
+      {
+        *p++ = '+';
+        *p++ = '?';
+      }
+    if ((syntax & RE_INTERVALS) != 0 && (syntax & RE_NO_BK_BRACES) != 0)
+      {
+        *p++ = '{';
+        *p++ = '}';
+      }
+    if ((syntax & RE_NO_BK_PARENS) != 0)
+      {
+        *p++ = '(';
+        *p++ = ')';
+      }
+    if ((syntax & RE_LIMITED_OPS) == 0 && (syntax & RE_NO_BK_VBAR) != 0)
+      *p++ = '|';
+    if ((syntax & RE_NEWLINE_ALT) != 0)
+      *p++ = '\n';
+    *p = '\0';
+  }
   result.multibyte = true;
   result.anchored = anchored;
 
@@ -106,23 +105,22 @@ struct regex_quote_spec
 regex_quote_spec_pcre (int options, bool anchored)
 {
   struct regex_quote_spec result;
-  char *p;
-
-  p = result.special;
-  memcpy (p, pcre_special, sizeof (pcre_special) - 1);
-  p += sizeof (pcre_special) - 1;
-  if (options & PCRE_EXTENDED)
-    {
-      *p++ = ' ';
-      *p++ = '\t';
-      *p++ = '\n';
-      *p++ = '\v';
-      *p++ = '\f';
-      *p++ = '\r';
-      *p++ = '#';
-    }
-  *p = '\0';
-
+  {
+    char *p = result.special;
+    memcpy (p, pcre_special, sizeof (pcre_special) - 1);
+    p += sizeof (pcre_special) - 1;
+    if (options & PCRE_EXTENDED)
+      {
+        *p++ = ' ';
+        *p++ = '\t';
+        *p++ = '\n';
+        *p++ = '\v';
+        *p++ = '\f';
+        *p++ = '\r';
+        *p++ = '#';
+      }
+    *p = '\0';
+  }
   /* PCRE regular expressions consist of UTF-8 characters of options contains
      PCRE_UTF8 and of single bytes otherwise.  */
   result.multibyte = false;
@@ -136,20 +134,20 @@ size_t
 regex_quote_length (const char *string, const struct regex_quote_spec *spec)
 {
   const char *special = spec->special;
-  size_t length;
 
-  length = 0;
+  size_t length = 0;
   if (spec->anchored)
     length += 2; /* for '^' at the beginning and '$' at the end */
   if (spec->multibyte)
     {
 #if GNULIB_MCEL_PREFER
       char const *iter = string;
-      for (mcel_t g; *iter; iter += g.len)
+      for (; *iter; )
         {
-          g = mcel_scanz (iter);
+          mcel_t g = mcel_scanz (iter);
           /* We know that special contains only ASCII characters.  */
           length += g.len == 1 && strchr (special, *iter);
+          iter += g.len;
         }
       length += iter - string;
 #else
@@ -231,10 +229,9 @@ regex_quote (const char *string, const struct regex_quote_spec *spec)
 {
   size_t length = regex_quote_length (string, spec);
   char *result = XNMALLOC (length + 1, char);
-  char *p;
-
-  p = result;
-  p = regex_quote_copy (p, string, spec);
-  *p = '\0';
+  {
+    char *p = regex_quote_copy (result, string, spec);
+    *p = '\0';
+  }
   return result;
 }
index 5eb7e8b716da69a12c945ad15d438378d46a9fad..72fbcb8813613c5166076642abdeaf4ac92c52f1 100644 (file)
@@ -139,11 +139,9 @@ set_this_relocation_prefix (const char *orig_prefix_arg,
       && strcmp (orig_prefix_arg, curr_prefix_arg) != 0)
     {
       /* Duplicate the argument strings.  */
-      char *memory;
-
       orig_prefix_len = strlen (orig_prefix_arg);
       curr_prefix_len = strlen (curr_prefix_arg);
-      memory = (char *) xmalloc (orig_prefix_len + 1 + curr_prefix_len + 1);
+      char *memory = (char *) xmalloc (orig_prefix_len + 1 + curr_prefix_len + 1);
 #ifdef NO_XMALLOC
       if (memory != NULL)
 #endif
@@ -200,9 +198,6 @@ compute_curr_prefix (const char *orig_installprefix,
                      const char *orig_installdir,
                      const char *curr_pathname)
 {
-  char *curr_installdir;
-  const char *rel_installdir;
-
   if (curr_pathname == NULL)
     return NULL;
 
@@ -213,9 +208,10 @@ compute_curr_prefix (const char *orig_installprefix,
       != 0)
     /* Shouldn't happen - nothing should be installed outside $(prefix).  */
     return NULL;
-  rel_installdir = orig_installdir + strlen (orig_installprefix);
+  const char *rel_installdir = orig_installdir + strlen (orig_installprefix);
 
   /* Determine the current installation directory.  */
+  char *curr_installdir;
   {
     const char *p_base = curr_pathname + FILE_SYSTEM_PREFIX_LEN (curr_pathname);
     const char *p = curr_pathname + strlen (curr_pathname);
@@ -419,33 +415,30 @@ find_shared_library_fullname ()
   /* Linux has /proc/self/maps. glibc 2 and uClibc have the getline()
      function.
      But it is costly: ca. 0.3 ms.  */
-  FILE *fp;
 
   /* Open the current process' maps file.  It describes one VMA per line.  */
-  fp = fopen ("/proc/self/maps", "r");
+  FILE *fp = fopen ("/proc/self/maps", "r");
   if (fp)
     {
       unsigned long address = (unsigned long) &find_shared_library_fullname;
       for (;;)
         {
           unsigned long start, end;
-          int c;
 
           if (fscanf (fp, "%lx-%lx", &start, &end) != 2)
             break;
           if (address >= start && address <= end - 1)
             {
               /* Found it.  Now see if this line contains a filename.  */
+              int c;
               while (c = getc (fp), c != EOF && c != '\n' && c != '/')
                 continue;
               if (c == '/')
                 {
-                  size_t size;
-                  int len;
-
                   ungetc (c, fp);
-                  shared_library_fullname = NULL; size = 0;
-                  len = getline (&shared_library_fullname, &size, fp);
+                  shared_library_fullname = NULL;
+                  size_t size = 0;
+                  int len = getline (&shared_library_fullname, &size, fp);
                   if (len >= 0)
                     {
                       /* Success: filled shared_library_fullname.  */
@@ -455,6 +448,7 @@ find_shared_library_fullname ()
                 }
               break;
             }
+          int c;
           while (c = getc (fp), c != EOF && c != '\n')
             continue;
         }
@@ -511,9 +505,7 @@ relocate (const char *pathname)
          orig_prefix.  */
       const char *orig_installprefix = INSTALLPREFIX;
       const char *orig_installdir = INSTALLDIR;
-      char *curr_prefix_better;
-
-      curr_prefix_better =
+      char *curr_prefix_better =
         compute_curr_prefix (orig_installprefix, orig_installdir,
                              get_shared_library_fullname ());
 
index c1524a548005ae2231a57620363c53fa6e39c790..1ab736357253a8b19a9f039904c01e20f9f9ba5f 100644 (file)
@@ -156,39 +156,35 @@ relocate_libdirs ()
 static void
 activate_libdirs ()
 {
-  const char *old_value;
-  size_t total;
-  char *value;
-  char *p;
-
-  old_value = getenv (LIBPATHVAR);
+  const char *old_value = getenv (LIBPATHVAR);
   if (old_value == NULL)
     old_value = "";
 
-  total = 0;
+  size_t total = 0;
   for (size_t i = 0; i < sizeof (libdirs) / sizeof (libdirs[0]) - 1; i++)
     total += strlen (libdirs[i]) + 1;
   total += strlen (old_value) + 1;
 
-  value = (char *) malloc (total);
+  char *value = (char *) malloc (total);
   if (value == NULL)
     {
       fprintf (stderr, "%s: %s\n", program_name, "memory exhausted");
       exit (1);
     }
-  p = value;
-  for (size_t i = 0; i < sizeof (libdirs) / sizeof (libdirs[0]) - 1; i++)
-    {
-      size_t len = strlen (libdirs[i]);
-      memcpy (p, libdirs[i], len);
-      p += len;
-      *p++ = ':';
-    }
-  if (old_value[0] != '\0')
-    strcpy (p, old_value);
-  else
-    p[-1] = '\0';
-
+  {
+    char *p = value;
+    for (size_t i = 0; i < sizeof (libdirs) / sizeof (libdirs[0]) - 1; i++)
+      {
+        size_t len = strlen (libdirs[i]);
+        memcpy (p, libdirs[i], len);
+        p += len;
+        *p++ = ':';
+      }
+    if (old_value[0] != '\0')
+      strcpy (p, old_value);
+    else
+      p[-1] = '\0';
+  }
   if (setenv (LIBPATHVAR, value, 1) < 0)
     {
       fprintf (stderr, "%s: %s\n", program_name, "memory exhausted");
@@ -199,14 +195,12 @@ activate_libdirs ()
 int
 main (int argc, char *argv[])
 {
-  char *full_program_name;
-
   /* Set the program name and perform preparations for
      get_full_program_name() and relocate().  */
   set_program_name_and_installdir (argv[0], INSTALLPREFIX, INSTALLDIR);
 
   /* Get the full program path.  (Important if accessed through a symlink.)  */
-  full_program_name = get_full_program_name ();
+  char *full_program_name = get_full_program_name ();
   if (full_program_name == NULL)
     full_program_name = argv[0];
 
index b365fc9b239119f2408cc92e4ac149615b53f328..fa6d222e6ed063dc7d8a680d014815ae046d5bac 100644 (file)
 int
 rpl_rename (char const *src, char const *dst)
 {
-  int error;
   size_t src_len = strlen (src);
   size_t dst_len = strlen (dst);
-  char *src_base = last_component (src);
-  char *dst_base = last_component (dst);
-  bool src_slash;
-  bool dst_slash;
-  bool dst_exists;
-  struct stat src_st;
-  struct stat dst_st;
 
-  /* Filter out dot as last component.  */
   if (!src_len || !dst_len)
     {
       errno = ENOENT;
       return -1;
     }
-  if (*src_base == '.')
-    {
-      size_t len = base_len (src_base);
-      if (len == 1 || (len == 2 && src_base[1] == '.'))
-        {
-          errno = EINVAL;
-          return -1;
-        }
-    }
-  if (*dst_base == '.')
-    {
-      size_t len = base_len (dst_base);
-      if (len == 1 || (len == 2 && dst_base[1] == '.'))
-        {
-          errno = EINVAL;
-          return -1;
-        }
-    }
+
+  /* Filter out dot as last component.  */
+  {
+    char *src_base = last_component (src);
+    char *dst_base = last_component (dst);
+    if (*src_base == '.')
+      {
+        size_t len = base_len (src_base);
+        if (len == 1 || (len == 2 && src_base[1] == '.'))
+          {
+            errno = EINVAL;
+            return -1;
+          }
+      }
+    if (*dst_base == '.')
+      {
+        size_t len = base_len (dst_base);
+        if (len == 1 || (len == 2 && dst_base[1] == '.'))
+          {
+            errno = EINVAL;
+            return -1;
+          }
+      }
+  }
 
   /* Presence of a trailing slash requires directory semantics.  If
      the source does not exist, or if the destination cannot be turned
      into a directory, give up now.  Otherwise, strip trailing slashes
      before calling rename.  There are no symlinks on mingw, so stat
      works instead of lstat.  */
-  src_slash = ISSLASH (src[src_len - 1]);
-  dst_slash = ISSLASH (dst[dst_len - 1]);
+  bool src_slash = ISSLASH (src[src_len - 1]);
+  bool dst_slash = ISSLASH (dst[dst_len - 1]);
+  struct stat src_st;
   if (stat (src, &src_st))
     return -1;
+  bool dst_exists;
+  struct stat dst_st;
   if (stat (dst, &dst_st))
     {
       if (errno != ENOENT || (!S_ISDIR (src_st.st_mode) && dst_slash))
@@ -123,10 +123,10 @@ rpl_rename (char const *src, char const *dst)
   if (dst_exists && S_ISDIR (dst_st.st_mode))
     {
       char *cwd = getcwd (NULL, 0);
-      char *src_temp;
-      char *dst_temp;
       if (!cwd || chdir (cwd))
         return -1;
+      char *src_temp;
+      char *dst_temp;
       if (IS_ABSOLUTE_FILE_NAME (src))
         {
           dst_temp = chdir (dst) ? NULL : getcwd (NULL, 0);
@@ -153,7 +153,7 @@ rpl_rename (char const *src, char const *dst)
       if (strncmp (src_temp, dst_temp, src_len) == 0
           && (ISSLASH (dst_temp[src_len]) || dst_temp[src_len] == '\0'))
         {
-          error = dst_temp[src_len];
+          int error = dst_temp[src_len];
           free (src_temp);
           free (dst_temp);
           if (error)
@@ -182,7 +182,7 @@ rpl_rename (char const *src, char const *dst)
 
   /* Retry with MOVEFILE_REPLACE_EXISTING if the move failed
      due to the destination already existing.  */
-  error = GetLastError ();
+  int error = GetLastError ();
   if (error == ERROR_FILE_EXISTS || error == ERROR_ALREADY_EXISTS)
     {
       if (MoveFileEx (src, dst, MOVEFILE_REPLACE_EXISTING))
@@ -284,15 +284,6 @@ rpl_rename (char const *src, char const *dst)
 {
   size_t src_len = strlen (src);
   size_t dst_len = strlen (dst);
-  char *src_temp = (char *) src;
-  char *dst_temp = (char *) dst;
-  bool src_slash;
-  bool dst_slash;
-  _GL_UNUSED bool dst_exists;
-  int ret_val = -1;
-  int rename_errno = ENOTDIR;
-  struct stat src_st;
-  struct stat dst_st;
 
   if (!src_len || !dst_len)
     return rename (src, dst); /* Let strace see the ENOENT failure.  */
@@ -322,8 +313,8 @@ rpl_rename (char const *src, char const *dst)
   }
 # endif /* RENAME_DEST_EXISTS_BUG */
 
-  src_slash = src[src_len - 1] == '/';
-  dst_slash = dst[dst_len - 1] == '/';
+  bool src_slash = src[src_len - 1] == '/';
+  bool dst_slash = dst[dst_len - 1] == '/';
 
 # if !RENAME_HARD_LINK_BUG && !RENAME_DEST_EXISTS_BUG
   /* If there are no trailing slashes, then trust the native
@@ -337,8 +328,11 @@ rpl_rename (char const *src, char const *dst)
      the source does not exist, or if the destination cannot be turned
      into a directory, give up now.  Otherwise, strip trailing slashes
      before calling rename.  */
+  struct stat src_st;
   if (lstat (src, &src_st))
     return -1;
+  struct stat dst_st;
+  _GL_UNUSED bool dst_exists;
   if (lstat (dst, &dst_st))
     {
       if (errno != ENOENT || (!S_ISDIR (src_st.st_mode) && dst_slash))
@@ -359,6 +353,11 @@ rpl_rename (char const *src, char const *dst)
       dst_exists = true;
     }
 
+  char *src_temp = (char *) src;
+  char *dst_temp = (char *) dst;
+  int ret_val = -1;
+  int rename_errno = ENOTDIR;
+
 # if (RENAME_TRAILING_SLASH_SOURCE_BUG || RENAME_DEST_EXISTS_BUG        \
       || RENAME_HARD_LINK_BUG)
   /* If the only bug was that a trailing slash was allowed on a
index ef40ad3d173a76e69d6ec9dedbecedbc1b461909..8c7f3317fcc47880bc3d9d77bc18fa155f70b41d 100644 (file)
@@ -133,18 +133,7 @@ renameatu (int fd1, char const *src, int fd2, char const *dst,
     return ret_val;
 
 #if HAVE_RENAMEAT
-  {
-  size_t src_len;
-  size_t dst_len;
-  char *src_temp = (char *) src;
-  char *dst_temp = (char *) dst;
-  bool src_slash;
-  bool dst_slash;
-  int rename_errno = ENOTDIR;
-  struct stat src_st;
-  struct stat dst_st;
   bool dst_found_nonexistent = false;
-
   switch (flags)
     {
     case 0:
@@ -156,12 +145,15 @@ renameatu (int fd1, char const *src, int fd2, char const *dst,
          is defined, because RENAME_EXCL is buggy on macOS 11.2:
          renameatx_np (fd, "X", fd, "X", RENAME_EXCL) incorrectly
          succeeds when X exists.  */
-      if (fstatat (fd2, dst, &dst_st, AT_SYMLINK_NOFOLLOW) == 0
-          || errno == EOVERFLOW)
-        return errno_fail (EEXIST);
-      if (errno != ENOENT)
-        return -1;
-      dst_found_nonexistent = true;
+      {
+        struct stat dst_st;
+        if (fstatat (fd2, dst, &dst_st, AT_SYMLINK_NOFOLLOW) == 0
+            || errno == EOVERFLOW)
+          return errno_fail (EEXIST);
+        if (errno != ENOENT)
+          return -1;
+        dst_found_nonexistent = true;
+      }
       break;
 
     case RENAME_EXCHANGE:
@@ -173,13 +165,13 @@ renameatu (int fd1, char const *src, int fd2, char const *dst,
     }
 
   /* Let strace see any ENOENT failure.  */
-  src_len = strlen (src);
-  dst_len = strlen (dst);
+  size_t src_len = strlen (src);
+  size_t dst_len = strlen (dst);
   if (!src_len || !dst_len)
     return renameat2ish (fd1, src, fd2, dst, flags);
 
-  src_slash = src[src_len - 1] == '/';
-  dst_slash = dst[dst_len - 1] == '/';
+  bool src_slash = src[src_len - 1] == '/';
+  bool dst_slash = dst[dst_len - 1] == '/';
   if (!src_slash && !dst_slash)
     return renameat2ish (fd1, src, fd2, dst, flags);
 
@@ -187,6 +179,8 @@ renameatu (int fd1, char const *src, int fd2, char const *dst,
      the source does not exist, or if the destination cannot be turned
      into a directory, give up now.  Otherwise, strip trailing slashes
      before calling rename.  */
+  struct stat src_st;
+  struct stat dst_st;
   if (fstatat (fd1, src, &src_st, AT_SYMLINK_NOFOLLOW))
     return -1;
   if (dst_found_nonexistent)
@@ -204,6 +198,10 @@ renameatu (int fd1, char const *src, int fd2, char const *dst,
   else if (!S_ISDIR (src_st.st_mode))
     return errno_fail (EISDIR);
 
+  int rename_errno = ENOTDIR;
+
+  char *src_temp = (char *) src;
+  char *dst_temp = (char *) dst;
 # if RENAME_TRAILING_SLASH_SOURCE_BUG
   /* See the lengthy comment in rename.c why Solaris 9 is forced to
      GNU behavior, while Solaris 10 is left with POSIX behavior,
@@ -263,7 +261,6 @@ renameatu (int fd1, char const *src, int fd2, char const *dst,
     free (dst_temp);
   errno = rename_errno;
   return ret_val;
-  }
 #else /* !HAVE_RENAMEAT */
 
   /* RENAME_NOREPLACE is the only flag currently supported.  */
index b91b0fdb3072e486a1dd46fd9b2c66ad2e3c83be..1db7ad90347371ed264b4f3a19a60ad88b643373 100644 (file)
@@ -754,7 +754,6 @@ rijndaelKeySetupEnc (uint32_t rk[ /*4*(Nr + 1) */ ],
                      const char cipherKey[], size_t keyBits)
 {
   size_t i = 0;
-  uint32_t temp;
 
   rk[0] = GETU32 (cipherKey);
   rk[1] = GETU32 (cipherKey + 4);
@@ -764,7 +763,7 @@ rijndaelKeySetupEnc (uint32_t rk[ /*4*(Nr + 1) */ ],
     {
       for (;;)
         {
-          temp = rk[3];
+          uint32_t temp = rk[3];
           rk[4] = rk[0] ^
             (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
             (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
@@ -786,7 +785,7 @@ rijndaelKeySetupEnc (uint32_t rk[ /*4*(Nr + 1) */ ],
     {
       for (;;)
         {
-          temp = rk[5];
+          uint32_t temp = rk[5];
           rk[6] = rk[0] ^
             (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
             (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
@@ -810,28 +809,32 @@ rijndaelKeySetupEnc (uint32_t rk[ /*4*(Nr + 1) */ ],
     {
       for (;;)
         {
-          temp = rk[7];
-          rk[8] = rk[0] ^
-            (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
-            (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
-            (Te4[(temp) & 0xff] & 0x0000ff00) ^
-            (Te4[(temp >> 24)] & 0x000000ff) ^ rcon[i];
-          rk[9] = rk[1] ^ rk[8];
-          rk[10] = rk[2] ^ rk[9];
-          rk[11] = rk[3] ^ rk[10];
-          if (++i == 7)
-            {
-              return 14;
-            }
-          temp = rk[11];
-          rk[12] = rk[4] ^
-            (Te4[(temp >> 24)] & 0xff000000) ^
-            (Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
-            (Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^
-            (Te4[(temp) & 0xff] & 0x000000ff);
-          rk[13] = rk[5] ^ rk[12];
-          rk[14] = rk[6] ^ rk[13];
-          rk[15] = rk[7] ^ rk[14];
+          {
+            uint32_t temp = rk[7];
+            rk[8] = rk[0] ^
+              (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
+              (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
+              (Te4[(temp) & 0xff] & 0x0000ff00) ^
+              (Te4[(temp >> 24)] & 0x000000ff) ^ rcon[i];
+            rk[9] = rk[1] ^ rk[8];
+            rk[10] = rk[2] ^ rk[9];
+            rk[11] = rk[3] ^ rk[10];
+            if (++i == 7)
+              {
+                return 14;
+              }
+          }
+          {
+            uint32_t temp = rk[11];
+            rk[12] = rk[4] ^
+              (Te4[(temp >> 24)] & 0xff000000) ^
+              (Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
+              (Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^
+              (Te4[(temp) & 0xff] & 0x000000ff);
+            rk[13] = rk[5] ^ rk[12];
+            rk[14] = rk[6] ^ rk[13];
+            rk[15] = rk[7] ^ rk[14];
+          }
 
           rk += 8;
         }
@@ -848,30 +851,38 @@ int
 rijndaelKeySetupDec (uint32_t rk[ /*4*(Nr + 1) */ ],
                      const char cipherKey[], size_t keyBits)
 {
-  size_t Nr, i, j;
-  uint32_t temp;
-
   /* expand the cipher key: */
-  Nr = rijndaelKeySetupEnc (rk, cipherKey, keyBits);
+  size_t Nr = rijndaelKeySetupEnc (rk, cipherKey, keyBits);
   /* invert the order of the round keys: */
-  for (i = 0, j = 4 * Nr; i < j; i += 4, j -= 4)
-    {
-      temp = rk[i];
-      rk[i] = rk[j];
-      rk[j] = temp;
-      temp = rk[i + 1];
-      rk[i + 1] = rk[j + 1];
-      rk[j + 1] = temp;
-      temp = rk[i + 2];
-      rk[i + 2] = rk[j + 2];
-      rk[j + 2] = temp;
-      temp = rk[i + 3];
-      rk[i + 3] = rk[j + 3];
-      rk[j + 3] = temp;
-    }
+  {
+    size_t i, j;
+    for (i = 0, j = 4 * Nr; i < j; i += 4, j -= 4)
+      {
+        {
+          uint32_t temp = rk[i];
+          rk[i] = rk[j];
+          rk[j] = temp;
+        }
+        {
+          uint32_t temp = rk[i + 1];
+          rk[i + 1] = rk[j + 1];
+          rk[j + 1] = temp;
+        }
+        {
+          uint32_t temp = rk[i + 2];
+          rk[i + 2] = rk[j + 2];
+          rk[j + 2] = temp;
+        }
+        {
+          uint32_t temp = rk[i + 3];
+          rk[i + 3] = rk[j + 3];
+          rk[j + 3] = temp;
+        }
+      }
+  }
   /* apply the inverse MixColumn transform to all round keys but the
      first and the last: */
-  for (i = 1; i < Nr; i++)
+  for (size_t i = 1; i < Nr; i++)
     {
       rk += 4;
       rk[0] =
@@ -902,86 +913,87 @@ void
 rijndaelEncrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr,
                  const char pt[16], char ct[16])
 {
-  uint32_t s0, s1, s2, s3, t0, t1, t2, t3;
-  size_t r;
+  uint32_t t0, t1, t2, t3;
 
-  /*
-   * map byte array block to cipher state
-   * and add initial round key:
-   */
-  s0 = GETU32 (pt) ^ rk[0];
-  s1 = GETU32 (pt + 4) ^ rk[1];
-  s2 = GETU32 (pt + 8) ^ rk[2];
-  s3 = GETU32 (pt + 12) ^ rk[3];
-  /*
-   * Nr - 1 full rounds:
-   */
-  r = Nr >> 1;
-  for (;;)
-    {
-      t0 =
-        Te0[(s0 >> 24)] ^
-        Te1[(s1 >> 16) & 0xff] ^
-        Te2[(s2 >> 8) & 0xff] ^ Te3[(s3) & 0xff] ^ rk[4];
-      t1 =
-        Te0[(s1 >> 24)] ^
-        Te1[(s2 >> 16) & 0xff] ^
-        Te2[(s3 >> 8) & 0xff] ^ Te3[(s0) & 0xff] ^ rk[5];
-      t2 =
-        Te0[(s2 >> 24)] ^
-        Te1[(s3 >> 16) & 0xff] ^
-        Te2[(s0 >> 8) & 0xff] ^ Te3[(s1) & 0xff] ^ rk[6];
-      t3 =
-        Te0[(s3 >> 24)] ^
-        Te1[(s0 >> 16) & 0xff] ^
-        Te2[(s1 >> 8) & 0xff] ^ Te3[(s2) & 0xff] ^ rk[7];
+  {
+    /*
+     * map byte array block to cipher state
+     * and add initial round key:
+     */
+    uint32_t s0 = GETU32 (pt) ^ rk[0];
+    uint32_t s1 = GETU32 (pt + 4) ^ rk[1];
+    uint32_t s2 = GETU32 (pt + 8) ^ rk[2];
+    uint32_t s3 = GETU32 (pt + 12) ^ rk[3];
+    /*
+     * Nr - 1 full rounds:
+     */
+    size_t r = Nr >> 1;
+    for (;;)
+      {
+        t0 =
+          Te0[(s0 >> 24)] ^
+          Te1[(s1 >> 16) & 0xff] ^
+          Te2[(s2 >> 8) & 0xff] ^ Te3[(s3) & 0xff] ^ rk[4];
+        t1 =
+          Te0[(s1 >> 24)] ^
+          Te1[(s2 >> 16) & 0xff] ^
+          Te2[(s3 >> 8) & 0xff] ^ Te3[(s0) & 0xff] ^ rk[5];
+        t2 =
+          Te0[(s2 >> 24)] ^
+          Te1[(s3 >> 16) & 0xff] ^
+          Te2[(s0 >> 8) & 0xff] ^ Te3[(s1) & 0xff] ^ rk[6];
+        t3 =
+          Te0[(s3 >> 24)] ^
+          Te1[(s0 >> 16) & 0xff] ^
+          Te2[(s1 >> 8) & 0xff] ^ Te3[(s2) & 0xff] ^ rk[7];
 
-      rk += 8;
-      if (--r == 0)
-        {
-          break;
-        }
+        rk += 8;
+        if (--r == 0)
+          {
+            break;
+          }
 
-      s0 =
-        Te0[(t0 >> 24)] ^
-        Te1[(t1 >> 16) & 0xff] ^
-        Te2[(t2 >> 8) & 0xff] ^ Te3[(t3) & 0xff] ^ rk[0];
-      s1 =
-        Te0[(t1 >> 24)] ^
-        Te1[(t2 >> 16) & 0xff] ^
-        Te2[(t3 >> 8) & 0xff] ^ Te3[(t0) & 0xff] ^ rk[1];
-      s2 =
-        Te0[(t2 >> 24)] ^
-        Te1[(t3 >> 16) & 0xff] ^
-        Te2[(t0 >> 8) & 0xff] ^ Te3[(t1) & 0xff] ^ rk[2];
-      s3 =
-        Te0[(t3 >> 24)] ^
-        Te1[(t0 >> 16) & 0xff] ^
-        Te2[(t1 >> 8) & 0xff] ^ Te3[(t2) & 0xff] ^ rk[3];
-    }
+        s0 =
+          Te0[(t0 >> 24)] ^
+          Te1[(t1 >> 16) & 0xff] ^
+          Te2[(t2 >> 8) & 0xff] ^ Te3[(t3) & 0xff] ^ rk[0];
+        s1 =
+          Te0[(t1 >> 24)] ^
+          Te1[(t2 >> 16) & 0xff] ^
+          Te2[(t3 >> 8) & 0xff] ^ Te3[(t0) & 0xff] ^ rk[1];
+        s2 =
+          Te0[(t2 >> 24)] ^
+          Te1[(t3 >> 16) & 0xff] ^
+          Te2[(t0 >> 8) & 0xff] ^ Te3[(t1) & 0xff] ^ rk[2];
+        s3 =
+          Te0[(t3 >> 24)] ^
+          Te1[(t0 >> 16) & 0xff] ^
+          Te2[(t1 >> 8) & 0xff] ^ Te3[(t2) & 0xff] ^ rk[3];
+      }
+  }
   /*
    * apply last round and
    * map cipher state to byte array block:
    */
-  s0 =
+  uint32_t s0 =
     (Te4[(t0 >> 24)] & 0xff000000) ^
     (Te4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
     (Te4[(t2 >> 8) & 0xff] & 0x0000ff00) ^
     (Te4[(t3) & 0xff] & 0x000000ff) ^ rk[0];
   PUTU32 (ct, s0);
-  s1 =
+  uint32_t s1 =
     (Te4[(t1 >> 24)] & 0xff000000) ^
     (Te4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
     (Te4[(t3 >> 8) & 0xff] & 0x0000ff00) ^
     (Te4[(t0) & 0xff] & 0x000000ff) ^ rk[1];
   PUTU32 (ct + 4, s1);
-  s2 =
+  uint32_t s2 =
     (Te4[(t2 >> 24)] & 0xff000000) ^
     (Te4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
     (Te4[(t0 >> 8) & 0xff] & 0x0000ff00) ^
     (Te4[(t1) & 0xff] & 0x000000ff) ^ rk[2];
   PUTU32 (ct + 8, s2);
-  s3 =
+  uint32_t s3 =
     (Te4[(t3 >> 24)] & 0xff000000) ^
     (Te4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
     (Te4[(t1 >> 8) & 0xff] & 0x0000ff00) ^
@@ -993,86 +1005,87 @@ void
 rijndaelDecrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr,
                  const char ct[16], char pt[16])
 {
-  uint32_t s0, s1, s2, s3, t0, t1, t2, t3;
-  size_t r;
+  uint32_t t0, t1, t2, t3;
 
-  /*
-   * map byte array block to cipher state
-   * and add initial round key:
-   */
-  s0 = GETU32 (ct) ^ rk[0];
-  s1 = GETU32 (ct + 4) ^ rk[1];
-  s2 = GETU32 (ct + 8) ^ rk[2];
-  s3 = GETU32 (ct + 12) ^ rk[3];
-  /*
-   * Nr - 1 full rounds:
-   */
-  r = Nr >> 1;
-  for (;;)
-    {
-      t0 =
-        Td0[(s0 >> 24)] ^
-        Td1[(s3 >> 16) & 0xff] ^
-        Td2[(s2 >> 8) & 0xff] ^ Td3[(s1) & 0xff] ^ rk[4];
-      t1 =
-        Td0[(s1 >> 24)] ^
-        Td1[(s0 >> 16) & 0xff] ^
-        Td2[(s3 >> 8) & 0xff] ^ Td3[(s2) & 0xff] ^ rk[5];
-      t2 =
-        Td0[(s2 >> 24)] ^
-        Td1[(s1 >> 16) & 0xff] ^
-        Td2[(s0 >> 8) & 0xff] ^ Td3[(s3) & 0xff] ^ rk[6];
-      t3 =
-        Td0[(s3 >> 24)] ^
-        Td1[(s2 >> 16) & 0xff] ^
-        Td2[(s1 >> 8) & 0xff] ^ Td3[(s0) & 0xff] ^ rk[7];
+  {
+    /*
+     * map byte array block to cipher state
+     * and add initial round key:
+     */
+    uint32_t s0 = GETU32 (ct) ^ rk[0];
+    uint32_t s1 = GETU32 (ct + 4) ^ rk[1];
+    uint32_t s2 = GETU32 (ct + 8) ^ rk[2];
+    uint32_t s3 = GETU32 (ct + 12) ^ rk[3];
+    /*
+     * Nr - 1 full rounds:
+     */
+    size_t r = Nr >> 1;
+    for (;;)
+      {
+        t0 =
+          Td0[(s0 >> 24)] ^
+          Td1[(s3 >> 16) & 0xff] ^
+          Td2[(s2 >> 8) & 0xff] ^ Td3[(s1) & 0xff] ^ rk[4];
+        t1 =
+          Td0[(s1 >> 24)] ^
+          Td1[(s0 >> 16) & 0xff] ^
+          Td2[(s3 >> 8) & 0xff] ^ Td3[(s2) & 0xff] ^ rk[5];
+        t2 =
+          Td0[(s2 >> 24)] ^
+          Td1[(s1 >> 16) & 0xff] ^
+          Td2[(s0 >> 8) & 0xff] ^ Td3[(s3) & 0xff] ^ rk[6];
+        t3 =
+          Td0[(s3 >> 24)] ^
+          Td1[(s2 >> 16) & 0xff] ^
+          Td2[(s1 >> 8) & 0xff] ^ Td3[(s0) & 0xff] ^ rk[7];
 
-      rk += 8;
-      if (--r == 0)
-        {
-          break;
-        }
+        rk += 8;
+        if (--r == 0)
+          {
+            break;
+          }
 
-      s0 =
-        Td0[(t0 >> 24)] ^
-        Td1[(t3 >> 16) & 0xff] ^
-        Td2[(t2 >> 8) & 0xff] ^ Td3[(t1) & 0xff] ^ rk[0];
-      s1 =
-        Td0[(t1 >> 24)] ^
-        Td1[(t0 >> 16) & 0xff] ^
-        Td2[(t3 >> 8) & 0xff] ^ Td3[(t2) & 0xff] ^ rk[1];
-      s2 =
-        Td0[(t2 >> 24)] ^
-        Td1[(t1 >> 16) & 0xff] ^
-        Td2[(t0 >> 8) & 0xff] ^ Td3[(t3) & 0xff] ^ rk[2];
-      s3 =
-        Td0[(t3 >> 24)] ^
-        Td1[(t2 >> 16) & 0xff] ^
-        Td2[(t1 >> 8) & 0xff] ^ Td3[(t0) & 0xff] ^ rk[3];
-    }
+        s0 =
+          Td0[(t0 >> 24)] ^
+          Td1[(t3 >> 16) & 0xff] ^
+          Td2[(t2 >> 8) & 0xff] ^ Td3[(t1) & 0xff] ^ rk[0];
+        s1 =
+          Td0[(t1 >> 24)] ^
+          Td1[(t0 >> 16) & 0xff] ^
+          Td2[(t3 >> 8) & 0xff] ^ Td3[(t2) & 0xff] ^ rk[1];
+        s2 =
+          Td0[(t2 >> 24)] ^
+          Td1[(t1 >> 16) & 0xff] ^
+          Td2[(t0 >> 8) & 0xff] ^ Td3[(t3) & 0xff] ^ rk[2];
+        s3 =
+          Td0[(t3 >> 24)] ^
+          Td1[(t2 >> 16) & 0xff] ^
+          Td2[(t1 >> 8) & 0xff] ^ Td3[(t0) & 0xff] ^ rk[3];
+      }
+  }
   /*
    * apply last round and
    * map cipher state to byte array block:
    */
-  s0 =
+  uint32_t s0 =
     (Td4[(t0 >> 24)] & 0xff000000) ^
     (Td4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
     (Td4[(t2 >> 8) & 0xff] & 0x0000ff00) ^
     (Td4[(t1) & 0xff] & 0x000000ff) ^ rk[0];
   PUTU32 (pt, s0);
-  s1 =
+  uint32_t s1 =
     (Td4[(t1 >> 24)] & 0xff000000) ^
     (Td4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
     (Td4[(t3 >> 8) & 0xff] & 0x0000ff00) ^
     (Td4[(t2) & 0xff] & 0x000000ff) ^ rk[1];
   PUTU32 (pt + 4, s1);
-  s2 =
+  uint32_t s2 =
     (Td4[(t2 >> 24)] & 0xff000000) ^
     (Td4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
     (Td4[(t0 >> 8) & 0xff] & 0x0000ff00) ^
     (Td4[(t3) & 0xff] & 0x000000ff) ^ rk[2];
   PUTU32 (pt + 8, s2);
-  s3 =
+  uint32_t s3 =
     (Td4[(t3 >> 24)] & 0xff000000) ^
     (Td4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
     (Td4[(t1 >> 8) & 0xff] & 0x0000ff00) ^
index 0952e2d3ca7f7bb339b6656373ea1c332a62b6f3..ed379fc1df0aab1166cb9ad773a2881256dc6746 100644 (file)
@@ -73,10 +73,6 @@ rijndael_rc
 rijndaelMakeKey (rijndaelKeyInstance *key, rijndael_direction direction,
                  size_t keyLen, const char *keyMaterial)
 {
-  size_t i;
-  char *keyMat;
-  char cipherKey[RIJNDAEL_MAXKB];
-
   if (key == NULL)
     {
       return RIJNDAEL_BAD_KEY_INSTANCE;
@@ -107,30 +103,35 @@ rijndaelMakeKey (rijndaelKeyInstance *key, rijndael_direction direction,
     }
 
   /* initialize key schedule: */
-  keyMat = key->keyMaterial;
-  for (i = 0; i < key->keyLen / 8; i++)
+  char *keyMat = key->keyMaterial;
+  char cipherKey[RIJNDAEL_MAXKB];
+  for (size_t i = 0; i < key->keyLen / 8; i++)
     {
-      char t, v;
-
-      t = *keyMat++;
-      if ((t >= '0') && (t <= '9'))
-        v = (t - '0') << 4;
-      else if ((t >= 'a') && (t <= 'f'))
-        v = (t - 'a' + 10) << 4;
-      else if ((t >= 'A') && (t <= 'F'))
-        v = (t - 'A' + 10) << 4;
-      else
-        return RIJNDAEL_BAD_KEY_MAT;
-
-      t = *keyMat++;
-      if ((t >= '0') && (t <= '9'))
-        v ^= (t - '0');
-      else if ((t >= 'a') && (t <= 'f'))
-        v ^= (t - 'a' + 10);
-      else if ((t >= 'A') && (t <= 'F'))
-        v ^= (t - 'A' + 10);
-      else
-        return RIJNDAEL_BAD_KEY_MAT;
+      char v;
+
+      {
+        char t = *keyMat++;
+        if ((t >= '0') && (t <= '9'))
+          v = (t - '0') << 4;
+        else if ((t >= 'a') && (t <= 'f'))
+          v = (t - 'a' + 10) << 4;
+        else if ((t >= 'A') && (t <= 'F'))
+          v = (t - 'A' + 10) << 4;
+        else
+          return RIJNDAEL_BAD_KEY_MAT;
+      }
+
+      {
+        char t = *keyMat++;
+        if ((t >= '0') && (t <= '9'))
+          v ^= (t - '0');
+        else if ((t >= 'a') && (t <= 'f'))
+          v ^= (t - 'a' + 10);
+        else if ((t >= 'A') && (t <= 'F'))
+          v ^= (t - 'A' + 10);
+        else
+          return RIJNDAEL_BAD_KEY_MAT;
+      }
 
       cipherKey[i] = v;
     }
@@ -161,30 +162,33 @@ rijndaelCipherInit (rijndaelCipherInstance *cipher, rijndael_mode mode,
     }
   if (IV != NULL)
     {
-      int i;
-      for (i = 0; i < RIJNDAEL_MAX_IV_SIZE; i++)
+      for (int i = 0; i < RIJNDAEL_MAX_IV_SIZE; i++)
         {
-          int t, j;
-
-          t = IV[2 * i];
-          if ((t >= '0') && (t <= '9'))
-            j = (t - '0') << 4;
-          else if ((t >= 'a') && (t <= 'f'))
-            j = (t - 'a' + 10) << 4;
-          else if ((t >= 'A') && (t <= 'F'))
-            j = (t - 'A' + 10) << 4;
-          else
-            return RIJNDAEL_BAD_CIPHER_INSTANCE;
-
-          t = IV[2 * i + 1];
-          if ((t >= '0') && (t <= '9'))
-            j ^= (t - '0');
-          else if ((t >= 'a') && (t <= 'f'))
-            j ^= (t - 'a' + 10);
-          else if ((t >= 'A') && (t <= 'F'))
-            j ^= (t - 'A' + 10);
-          else
-            return RIJNDAEL_BAD_CIPHER_INSTANCE;
+          int j;
+
+          {
+            int t = IV[2 * i];
+            if ((t >= '0') && (t <= '9'))
+              j = (t - '0') << 4;
+            else if ((t >= 'a') && (t <= 'f'))
+              j = (t - 'a' + 10) << 4;
+            else if ((t >= 'A') && (t <= 'F'))
+              j = (t - 'A' + 10) << 4;
+            else
+              return RIJNDAEL_BAD_CIPHER_INSTANCE;
+          }
+
+          {
+            int t = IV[2 * i + 1];
+            if ((t >= '0') && (t <= '9'))
+              j ^= (t - '0');
+            else if ((t >= 'a') && (t <= 'f'))
+              j ^= (t - 'a' + 10);
+            else if ((t >= 'A') && (t <= 'F'))
+              j ^= (t - 'A' + 10);
+            else
+              return RIJNDAEL_BAD_CIPHER_INSTANCE;
+          }
 
           cipher->IV[i] = (uint8_t) j;
         }
@@ -202,10 +206,6 @@ rijndaelBlockEncrypt (rijndaelCipherInstance *cipher,
                       const char *input,
                       size_t inputLen, char *outBuffer)
 {
-  size_t i, k, t, numBlocks;
-  union { char bytes[16]; uint32_t words[4]; } block;
-  char *iv;
-
   if (cipher == NULL || key == NULL || key->direction == RIJNDAEL_DIR_DECRYPT)
     {
       return RIJNDAEL_BAD_CIPHER_STATE;
@@ -215,12 +215,13 @@ rijndaelBlockEncrypt (rijndaelCipherInstance *cipher,
       return 0;                 /* nothing to do */
     }
 
-  numBlocks = inputLen / 128;
+  size_t numBlocks = inputLen / 128;
+  union { char bytes[16]; uint32_t words[4]; } block;
 
   switch (cipher->mode)
     {
     case RIJNDAEL_MODE_ECB:
-      for (i = numBlocks; i > 0; i--)
+      for (size_t i = numBlocks; i > 0; i--)
         {
           rijndaelEncrypt (key->rk, key->Nr, input, outBuffer);
           input += 16;
@@ -229,39 +230,43 @@ rijndaelBlockEncrypt (rijndaelCipherInstance *cipher,
       break;
 
     case RIJNDAEL_MODE_CBC:
-      iv = cipher->IV;
-      for (i = numBlocks; i > 0; i--)
-        {
-          block.words[0] = ((uint32_t *) input)[0] ^ ((uint32_t *) iv)[0];
-          block.words[1] = ((uint32_t *) input)[1] ^ ((uint32_t *) iv)[1];
-          block.words[2] = ((uint32_t *) input)[2] ^ ((uint32_t *) iv)[2];
-          block.words[3] = ((uint32_t *) input)[3] ^ ((uint32_t *) iv)[3];
-          rijndaelEncrypt (key->rk, key->Nr, block.bytes, outBuffer);
-          memcpy (cipher->IV, outBuffer, 16);
-          input += 16;
-          outBuffer += 16;
-        }
+      {
+        char *iv = cipher->IV;
+        for (size_t i = numBlocks; i > 0; i--)
+          {
+            block.words[0] = ((uint32_t *) input)[0] ^ ((uint32_t *) iv)[0];
+            block.words[1] = ((uint32_t *) input)[1] ^ ((uint32_t *) iv)[1];
+            block.words[2] = ((uint32_t *) input)[2] ^ ((uint32_t *) iv)[2];
+            block.words[3] = ((uint32_t *) input)[3] ^ ((uint32_t *) iv)[3];
+            rijndaelEncrypt (key->rk, key->Nr, block.bytes, outBuffer);
+            memcpy (cipher->IV, outBuffer, 16);
+            input += 16;
+            outBuffer += 16;
+          }
+      }
       break;
 
     case RIJNDAEL_MODE_CFB1:
-      iv = cipher->IV;
-      for (i = numBlocks; i > 0; i--)
-        {
-          memcpy (outBuffer, input, 16);
-          for (k = 0; k < 128; k++)
-            {
-              rijndaelEncrypt (key->ek, key->Nr, iv, block.bytes);
-              outBuffer[k >> 3] ^= (block.bytes[0] & 0x80U) >> (k & 7);
-              for (t = 0; t < 15; t++)
-                {
-                  iv[t] = (iv[t] << 1) | (iv[t + 1] >> 7);
-                }
-              iv[15] = (iv[15] << 1) |
-                ((outBuffer[k >> 3] >> (7 - (k & 7))) & 1);
-            }
-          outBuffer += 16;
-          input += 16;
-        }
+      {
+        char *iv = cipher->IV;
+        for (size_t i = numBlocks; i > 0; i--)
+          {
+            memcpy (outBuffer, input, 16);
+            for (size_t k = 0; k < 128; k++)
+              {
+                rijndaelEncrypt (key->ek, key->Nr, iv, block.bytes);
+                outBuffer[k >> 3] ^= (block.bytes[0] & 0x80U) >> (k & 7);
+                for (size_t t = 0; t < 15; t++)
+                  {
+                    iv[t] = (iv[t] << 1) | (iv[t + 1] >> 7);
+                  }
+                iv[15] = (iv[15] << 1) |
+                  ((outBuffer[k >> 3] >> (7 - (k & 7))) & 1);
+              }
+            outBuffer += 16;
+            input += 16;
+          }
+      }
       break;
 
     default:
@@ -277,10 +282,6 @@ rijndaelPadEncrypt (rijndaelCipherInstance *cipher,
                     const char *input,
                     size_t inputOctets, char *outBuffer)
 {
-  size_t i, numBlocks, padLen;
-  union { char bytes[16]; uint32_t words[4]; } block;
-  char *iv;
-
   if (cipher == NULL || key == NULL || key->direction == RIJNDAEL_DIR_DECRYPT)
     {
       return RIJNDAEL_BAD_CIPHER_STATE;
@@ -290,49 +291,54 @@ rijndaelPadEncrypt (rijndaelCipherInstance *cipher,
       return 0;                 /* nothing to do */
     }
 
-  numBlocks = inputOctets / 16;
+  size_t numBlocks = inputOctets / 16;
+  union { char bytes[16]; uint32_t words[4]; } block;
 
   switch (cipher->mode)
     {
     case RIJNDAEL_MODE_ECB:
-      for (i = numBlocks; i > 0; i--)
-        {
-          rijndaelEncrypt (key->rk, key->Nr, input, outBuffer);
-          input += 16;
-          outBuffer += 16;
-        }
-      padLen = 16 - (inputOctets - 16 * numBlocks);
-      assert (padLen > 0 && padLen <= 16);
-      memcpy (block.bytes, input, 16 - padLen);
-      memset (block.bytes + 16 - padLen, padLen, padLen);
-      rijndaelEncrypt (key->rk, key->Nr, block.bytes, outBuffer);
+      {
+        for (size_t i = numBlocks; i > 0; i--)
+          {
+            rijndaelEncrypt (key->rk, key->Nr, input, outBuffer);
+            input += 16;
+            outBuffer += 16;
+          }
+        size_t padLen = 16 - (inputOctets - 16 * numBlocks);
+        assert (padLen > 0 && padLen <= 16);
+        memcpy (block.bytes, input, 16 - padLen);
+        memset (block.bytes + 16 - padLen, padLen, padLen);
+        rijndaelEncrypt (key->rk, key->Nr, block.bytes, outBuffer);
+      }
       break;
 
     case RIJNDAEL_MODE_CBC:
-      iv = cipher->IV;
-      for (i = numBlocks; i > 0; i--)
-        {
-          block.words[0] = ((uint32_t *) input)[0] ^ ((uint32_t *) iv)[0];
-          block.words[1] = ((uint32_t *) input)[1] ^ ((uint32_t *) iv)[1];
-          block.words[2] = ((uint32_t *) input)[2] ^ ((uint32_t *) iv)[2];
-          block.words[3] = ((uint32_t *) input)[3] ^ ((uint32_t *) iv)[3];
-          rijndaelEncrypt (key->rk, key->Nr, block.bytes, outBuffer);
-          memcpy (cipher->IV, outBuffer, 16);
-          input += 16;
-          outBuffer += 16;
-        }
-      padLen = 16 - (inputOctets - 16 * numBlocks);
-      assert (padLen > 0 && padLen <= 16);
-      for (i = 0; i < 16 - padLen; i++)
-        {
-          block.bytes[i] = input[i] ^ iv[i];
-        }
-      for (i = 16 - padLen; i < 16; i++)
-        {
-          block.bytes[i] = (char) padLen ^ iv[i];
-        }
-      rijndaelEncrypt (key->rk, key->Nr, block.bytes, outBuffer);
-      memcpy (cipher->IV, outBuffer, 16);
+      {
+        char *iv = cipher->IV;
+        for (size_t i = numBlocks; i > 0; i--)
+          {
+            block.words[0] = ((uint32_t *) input)[0] ^ ((uint32_t *) iv)[0];
+            block.words[1] = ((uint32_t *) input)[1] ^ ((uint32_t *) iv)[1];
+            block.words[2] = ((uint32_t *) input)[2] ^ ((uint32_t *) iv)[2];
+            block.words[3] = ((uint32_t *) input)[3] ^ ((uint32_t *) iv)[3];
+            rijndaelEncrypt (key->rk, key->Nr, block.bytes, outBuffer);
+            memcpy (cipher->IV, outBuffer, 16);
+            input += 16;
+            outBuffer += 16;
+          }
+        size_t padLen = 16 - (inputOctets - 16 * numBlocks);
+        assert (padLen > 0 && padLen <= 16);
+        for (size_t i = 0; i < 16 - padLen; i++)
+          {
+            block.bytes[i] = input[i] ^ iv[i];
+          }
+        for (size_t i = 16 - padLen; i < 16; i++)
+          {
+            block.bytes[i] = (char) padLen ^ iv[i];
+          }
+        rijndaelEncrypt (key->rk, key->Nr, block.bytes, outBuffer);
+        memcpy (cipher->IV, outBuffer, 16);
+      }
       break;
 
     default:
@@ -348,10 +354,6 @@ rijndaelBlockDecrypt (rijndaelCipherInstance *cipher,
                       const char *input,
                       size_t inputLen, char *outBuffer)
 {
-  size_t i, k, t, numBlocks;
-  union { char bytes[16]; uint32_t words[4]; } block;
-  char *iv;
-
   if (cipher == NULL
       || key == NULL
       || (cipher->mode != RIJNDAEL_MODE_CFB1
@@ -364,12 +366,13 @@ rijndaelBlockDecrypt (rijndaelCipherInstance *cipher,
       return 0;                 /* nothing to do */
     }
 
-  numBlocks = inputLen / 128;
+  size_t numBlocks = inputLen / 128;
+  union { char bytes[16]; uint32_t words[4]; } block;
 
   switch (cipher->mode)
     {
     case RIJNDAEL_MODE_ECB:
-      for (i = numBlocks; i > 0; i--)
+      for (size_t i = numBlocks; i > 0; i--)
         {
           rijndaelDecrypt (key->rk, key->Nr, input, outBuffer);
           input += 16;
@@ -378,39 +381,43 @@ rijndaelBlockDecrypt (rijndaelCipherInstance *cipher,
       break;
 
     case RIJNDAEL_MODE_CBC:
-      iv = cipher->IV;
-      for (i = numBlocks; i > 0; i--)
-        {
-          rijndaelDecrypt (key->rk, key->Nr, input, block.bytes);
-          block.words[0] ^= ((uint32_t *) iv)[0];
-          block.words[1] ^= ((uint32_t *) iv)[1];
-          block.words[2] ^= ((uint32_t *) iv)[2];
-          block.words[3] ^= ((uint32_t *) iv)[3];
-          memcpy (cipher->IV, input, 16);
-          memcpy (outBuffer, block.bytes, 16);
-          input += 16;
-          outBuffer += 16;
-        }
+      {
+        char *iv = cipher->IV;
+        for (size_t i = numBlocks; i > 0; i--)
+          {
+            rijndaelDecrypt (key->rk, key->Nr, input, block.bytes);
+            block.words[0] ^= ((uint32_t *) iv)[0];
+            block.words[1] ^= ((uint32_t *) iv)[1];
+            block.words[2] ^= ((uint32_t *) iv)[2];
+            block.words[3] ^= ((uint32_t *) iv)[3];
+            memcpy (cipher->IV, input, 16);
+            memcpy (outBuffer, block.bytes, 16);
+            input += 16;
+            outBuffer += 16;
+          }
+      }
       break;
 
     case RIJNDAEL_MODE_CFB1:
-      iv = cipher->IV;
-      for (i = numBlocks; i > 0; i--)
-        {
-          memcpy (outBuffer, input, 16);
-          for (k = 0; k < 128; k++)
-            {
-              rijndaelEncrypt (key->ek, key->Nr, iv, block.bytes);
-              for (t = 0; t < 15; t++)
-                {
-                  iv[t] = (iv[t] << 1) | (iv[t + 1] >> 7);
-                }
-              iv[15] = (iv[15] << 1) | ((input[k >> 3] >> (7 - (k & 7))) & 1);
-              outBuffer[k >> 3] ^= (block.bytes[0] & 0x80U) >> (k & 7);
-            }
-          outBuffer += 16;
-          input += 16;
-        }
+      {
+        char *iv = cipher->IV;
+        for (size_t i = numBlocks; i > 0; i--)
+          {
+            memcpy (outBuffer, input, 16);
+            for (size_t k = 0; k < 128; k++)
+              {
+                rijndaelEncrypt (key->ek, key->Nr, iv, block.bytes);
+                for (size_t t = 0; t < 15; t++)
+                  {
+                    iv[t] = (iv[t] << 1) | (iv[t + 1] >> 7);
+                  }
+                iv[15] = (iv[15] << 1) | ((input[k >> 3] >> (7 - (k & 7))) & 1);
+                outBuffer[k >> 3] ^= (block.bytes[0] & 0x80U) >> (k & 7);
+              }
+            outBuffer += 16;
+            input += 16;
+          }
+      }
       break;
 
     default:
@@ -426,10 +433,6 @@ rijndaelPadDecrypt (rijndaelCipherInstance *cipher,
                     const char *input,
                     size_t inputOctets, char *outBuffer)
 {
-  size_t i, numBlocks, padLen;
-  union { char bytes[16]; uint32_t words[4]; } block;
-  char *iv;
-
   if (cipher == NULL || key == NULL || key->direction == RIJNDAEL_DIR_ENCRYPT)
     {
       return RIJNDAEL_BAD_CIPHER_STATE;
@@ -443,69 +446,75 @@ rijndaelPadDecrypt (rijndaelCipherInstance *cipher,
       return RIJNDAEL_BAD_DATA;
     }
 
-  numBlocks = inputOctets / 16;
+  size_t numBlocks = inputOctets / 16;
+  union { char bytes[16]; uint32_t words[4]; } block;
+  size_t padLen;
 
   switch (cipher->mode)
     {
     case RIJNDAEL_MODE_ECB:
-      /* all blocks but last */
-      for (i = numBlocks - 1; i > 0; i--)
-        {
-          rijndaelDecrypt (key->rk, key->Nr, input, outBuffer);
-          input += 16;
-          outBuffer += 16;
-        }
-      /* last block */
-      rijndaelDecrypt (key->rk, key->Nr, input, block.bytes);
-      padLen = block.bytes[15];
-      if (padLen >= 16)
-        {
-          return RIJNDAEL_BAD_DATA;
-        }
-      for (i = 16 - padLen; i < 16; i++)
-        {
-          if (block.bytes[i] != padLen)
-            {
-              return RIJNDAEL_BAD_DATA;
-            }
-        }
-      memcpy (outBuffer, block.bytes, 16 - padLen);
+      {
+        /* all blocks but last */
+        for (size_t i = numBlocks - 1; i > 0; i--)
+          {
+            rijndaelDecrypt (key->rk, key->Nr, input, outBuffer);
+            input += 16;
+            outBuffer += 16;
+          }
+        /* last block */
+        rijndaelDecrypt (key->rk, key->Nr, input, block.bytes);
+        padLen = block.bytes[15];
+        if (padLen >= 16)
+          {
+            return RIJNDAEL_BAD_DATA;
+          }
+        for (size_t i = 16 - padLen; i < 16; i++)
+          {
+            if (block.bytes[i] != padLen)
+              {
+                return RIJNDAEL_BAD_DATA;
+              }
+          }
+        memcpy (outBuffer, block.bytes, 16 - padLen);
+      }
       break;
 
     case RIJNDAEL_MODE_CBC:
-      iv = cipher->IV;
-      /* all blocks but last */
-      for (i = numBlocks - 1; i > 0; i--)
-        {
-          rijndaelDecrypt (key->rk, key->Nr, input, block.bytes);
-          block.words[0] ^= ((uint32_t *) iv)[0];
-          block.words[1] ^= ((uint32_t *) iv)[1];
-          block.words[2] ^= ((uint32_t *) iv)[2];
-          block.words[3] ^= ((uint32_t *) iv)[3];
-          memcpy (iv, input, 16);
-          memcpy (outBuffer, block.bytes, 16);
-          input += 16;
-          outBuffer += 16;
-        }
-      /* last block */
-      rijndaelDecrypt (key->rk, key->Nr, input, block.bytes);
-      block.words[0] ^= ((uint32_t *) iv)[0];
-      block.words[1] ^= ((uint32_t *) iv)[1];
-      block.words[2] ^= ((uint32_t *) iv)[2];
-      block.words[3] ^= ((uint32_t *) iv)[3];
-      padLen = block.bytes[15];
-      if (padLen <= 0 || padLen > 16)
-        {
-          return RIJNDAEL_BAD_DATA;
-        }
-      for (i = 16 - padLen; i < 16; i++)
-        {
-          if (block.bytes[i] != padLen)
-            {
-              return RIJNDAEL_BAD_DATA;
-            }
-        }
-      memcpy (outBuffer, block.bytes, 16 - padLen);
+      {
+        char *iv = cipher->IV;
+        /* all blocks but last */
+        for (size_t i = numBlocks - 1; i > 0; i--)
+          {
+            rijndaelDecrypt (key->rk, key->Nr, input, block.bytes);
+            block.words[0] ^= ((uint32_t *) iv)[0];
+            block.words[1] ^= ((uint32_t *) iv)[1];
+            block.words[2] ^= ((uint32_t *) iv)[2];
+            block.words[3] ^= ((uint32_t *) iv)[3];
+            memcpy (iv, input, 16);
+            memcpy (outBuffer, block.bytes, 16);
+            input += 16;
+            outBuffer += 16;
+          }
+        /* last block */
+        rijndaelDecrypt (key->rk, key->Nr, input, block.bytes);
+        block.words[0] ^= ((uint32_t *) iv)[0];
+        block.words[1] ^= ((uint32_t *) iv)[1];
+        block.words[2] ^= ((uint32_t *) iv)[2];
+        block.words[3] ^= ((uint32_t *) iv)[3];
+        padLen = block.bytes[15];
+        if (padLen <= 0 || padLen > 16)
+          {
+            return RIJNDAEL_BAD_DATA;
+          }
+        for (size_t i = 16 - padLen; i < 16; i++)
+          {
+            if (block.bytes[i] != padLen)
+              {
+                return RIJNDAEL_BAD_DATA;
+              }
+          }
+        memcpy (outBuffer, block.bytes, 16 - padLen);
+      }
       break;
 
     default:
index fb4f089e5d4353643445e617632e38759a89ef07..cd216e0beb599ad2e88b0100d29d5178c2e3c828 100644 (file)
@@ -38,7 +38,6 @@ rpl_rmdir (char const *dir)
 {
   /* Work around cygwin 1.5.x bug where rmdir("dir/./") succeeds.  */
   size_t len = strlen (dir);
-  int result;
   while (len && ISSLASH (dir[len - 1]))
     len--;
   if (len && dir[len - 1] == '.' && (1 == len || ISSLASH (dir[len - 2])))
@@ -46,7 +45,7 @@ rpl_rmdir (char const *dir)
       errno = EINVAL;
       return -1;
     }
-  result = rmdir (dir);
+  int result = rmdir (dir);
   /* Work around mingw bug, where rmdir("file/") fails with EINVAL
      instead of ENOTDIR.  We've already filtered out trailing ., the
      only reason allowed by POSIX for EINVAL.  */
index 507707345ec55eae464b6eb9c449cec2ba60d8f0..a01a7a1a4923fbb7ba4993e1518715205e030b19 100644 (file)
@@ -44,8 +44,6 @@ static const char *
 localized_pattern (const char *english_pattern, nl_item nl_index,
                    bool posixly_correct)
 {
-  const char *translated_pattern;
-
   /* We prefer to get the patterns from a PO file.  It would be possible to
      always use nl_langinfo (YESEXPR) instead of _("^[yY]"), and
      nl_langinfo (NOEXPR) instead of _("^[nN]"), if we could assume that the
@@ -61,14 +59,14 @@ localized_pattern (const char *english_pattern, nl_item nl_index,
   /* If the user wants strict POSIX compliance, use nl_langinfo.  */
   if (posixly_correct)
     {
-      translated_pattern = nl_langinfo (nl_index);
+      const char *translated_pattern = nl_langinfo (nl_index);
       /* Check against a broken system return value.  */
       if (translated_pattern != NULL && translated_pattern[0] != '\0')
         return translated_pattern;
    }
 
   /* Look in the gnulib message catalog.  */
-  translated_pattern = _(english_pattern);
+  const char *translated_pattern = _(english_pattern);
   if (translated_pattern == english_pattern)
     {
       /* The gnulib message catalog provides no translation.
@@ -92,8 +90,6 @@ try (const char *response, const char *pattern, char **lastp, regex_t *re)
 {
   if (*lastp == NULL || !streq (pattern, *lastp))
     {
-      char *safe_pattern;
-
       /* The pattern has changed.  */
       if (*lastp != NULL)
         {
@@ -104,7 +100,7 @@ try (const char *response, const char *pattern, char **lastp, regex_t *re)
         }
       /* Put the PATTERN into safe memory before calling regcomp.
          (regcomp may call nl_langinfo, overwriting PATTERN's storage.  */
-      safe_pattern = strdup (pattern);
+      char *safe_pattern = strdup (pattern);
       if (safe_pattern == NULL)
         return -1;
       /* Compile the pattern and cache it for future runs.  */
@@ -137,34 +133,37 @@ rpmatch (const char *response)
   bool posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
 # endif
 
-  const char *yesexpr, *noexpr;
-  int result;
-
-  /* TRANSLATORS: A regular expression testing for an affirmative answer
-     (english: "yes").  Testing the first character may be sufficient.
-     Take care to consider upper and lower case.
-     To enquire the regular expression that your system uses for this
-     purpose, you can use the command
-       locale -k LC_MESSAGES | grep '^yesexpr='  */
-  yesexpr = localized_pattern (N_("^[yY]"), YESEXPR, posixly_correct);
-  result = try (response, yesexpr, &last_yesexpr, &cached_yesre);
-  if (result < 0)
-    return -1;
-  if (result)
-    return 1;
-
-  /* TRANSLATORS: A regular expression testing for a negative answer
-     (english: "no").  Testing the first character may be sufficient.
-     Take care to consider upper and lower case.
-     To enquire the regular expression that your system uses for this
-     purpose, you can use the command
-       locale -k LC_MESSAGES | grep '^noexpr='  */
-  noexpr = localized_pattern (N_("^[nN]"), NOEXPR, posixly_correct);
-  result = try (response, noexpr, &last_noexpr, &cached_nore);
-  if (result < 0)
-    return -1;
-  if (result)
-    return 0;
+  {
+    /* TRANSLATORS: A regular expression testing for an affirmative answer
+       (english: "yes").  Testing the first character may be sufficient.
+       Take care to consider upper and lower case.
+       To enquire the regular expression that your system uses for this
+       purpose, you can use the command
+         locale -k LC_MESSAGES | grep '^yesexpr='  */
+    const char *yesexpr = localized_pattern (N_("^[yY]"), YESEXPR,
+                                             posixly_correct);
+    int result = try (response, yesexpr, &last_yesexpr, &cached_yesre);
+    if (result < 0)
+      return -1;
+    if (result)
+      return 1;
+  }
+
+  {
+    /* TRANSLATORS: A regular expression testing for a negative answer
+       (english: "no").  Testing the first character may be sufficient.
+       Take care to consider upper and lower case.
+       To enquire the regular expression that your system uses for this
+       purpose, you can use the command
+         locale -k LC_MESSAGES | grep '^noexpr='  */
+    const char *noexpr = localized_pattern (N_("^[nN]"), NOEXPR,
+                                            posixly_correct);
+    int result = try (response, noexpr, &last_noexpr, &cached_nore);
+    if (result < 0)
+      return -1;
+    if (result)
+      return 0;
+  }
 
   return -1;
 #else
index da6147cf3aa59cd04ca010e081e2f4f6ee1e49a9..3485e0f1b7e0464f4c213c2d8791690987192022 100644 (file)
@@ -90,13 +90,12 @@ same_nameat (int source_dfd, char const *source,
 
   if (compare_dirs)
     {
-      struct stat source_dir_stats;
-      struct stat dest_dir_stats;
 
       /* Compare the parent directories (via the device and inode numbers).  */
       char *source_dirname = dir_name (source);
-      int flags = AT_SYMLINK_NOFOLLOW;
-      if (fstatat (source_dfd, source_dirname, &source_dir_stats, flags) != 0)
+      struct stat source_dir_stats;
+      if (fstatat (source_dfd, source_dirname, &source_dir_stats,
+                   AT_SYMLINK_NOFOLLOW) != 0)
         {
           /* Shouldn't happen.  */
           error (1, errno, "%s", source_dirname);
@@ -104,6 +103,7 @@ same_nameat (int source_dfd, char const *source,
       free (source_dirname);
 
       char *dest_dirname = dir_name (dest);
+      struct stat dest_dir_stats;
 
 #if CHECK_TRUNCATION
       int destdir_errno = 0;
@@ -132,7 +132,8 @@ same_nameat (int source_dfd, char const *source,
           error (1, destdir_errno, "%s", dest_dirname);
         }
 #else
-      if (fstatat (dest_dfd, dest_dirname, &dest_dir_stats, flags) != 0)
+      if (fstatat (dest_dfd, dest_dirname, &dest_dir_stats,
+                   AT_SYMLINK_NOFOLLOW) != 0)
         {
           /* Shouldn't happen.  */
           error (1, errno, "%s", dest_dirname);
index 2e4f6f9a7c17b93fb2775327a0d3d63515fc4bec..670346f0eb1daff2ccdbf1a2e4b203a1423f6b98 100644 (file)
@@ -104,24 +104,22 @@ static comparison_function const comparison_function_table[] =
 char *
 streamsavedir (DIR *dirp, enum savedir_option option)
 {
+  if (dirp == NULL)
+    return NULL;
+
+  comparison_function cmp = comparison_function_table[option];
+
   char *name_space = NULL;
   idx_t allocated = 0;
   direntry_t *entries = NULL;
   idx_t entries_allocated = 0;
   idx_t entries_used = 0;
   idx_t used = 0;
-  comparison_function cmp = comparison_function_table[option];
-
-  if (dirp == NULL)
-    return NULL;
 
   for (;;)
     {
-      struct dirent const *dp;
-      char const *entry;
-
       errno = 0;
-      dp = readdir (dirp);
+      struct dirent const *dp = readdir (dirp);
       if (! dp)
         {
           /* Some readdir()s do not absorb ENOENT (dir deleted but open).
@@ -135,7 +133,7 @@ streamsavedir (DIR *dirp, enum savedir_option option)
 
       /* Skip "", ".", and "..".  "" is returned by at least one buggy
          implementation: Solaris 2.4 readdir on NFS file systems.  */
-      entry = dp->d_name;
+      char const *entry = dp->d_name;
       if (entry[entry[0] != '.' ? 0 : entry[1] != '.' ? 1 : 2] != '\0')
         {
           idx_t entry_size = _D_EXACT_NAMLEN (dp) + 1;
@@ -169,10 +167,12 @@ streamsavedir (DIR *dirp, enum savedir_option option)
       if (entries_used)
         qsort_r (entries, entries_used, sizeof *entries, cmp, name_space);
       char *sorted_name_space = ximalloc (used + 1);
-      char *p = sorted_name_space;
-      for (idx_t i = 0; i < entries_used; i++)
-        p = stpcpy (p, name_space + entries[i].name) + 1;
-      *p = '\0';
+      {
+        char *p = sorted_name_space;
+        for (idx_t i = 0; i < entries_used; i++)
+          p = stpcpy (p, name_space + entries[i].name) + 1;
+        *p = '\0';
+      }
       free (name_space);
       name_space = sorted_name_space;
     }
index f06ab490d8b4d1aa0359e892c54efbc434fbf537..e80c4dd4b2f89d84ad604589c9f2289e0a177cda 100644 (file)
@@ -118,18 +118,14 @@ SCANDIR (const char *dir,
 #endif
 {
   DIR *dp = __opendir (dir);
-  DIRENT_TYPE **v = NULL;
-  size_t vsize = 0;
-  struct scandir_cancel_struct c;
-  DIRENT_TYPE *d;
-  int saved_errno;
 
   if (dp == NULL)
     return -1;
 
-  saved_errno = errno;
+  int saved_errno = errno;
   __set_errno (0);
 
+  struct scandir_cancel_struct c;
   c.dp = dp;
   c.v = NULL;
   c.cnt = 0;
@@ -137,6 +133,10 @@ SCANDIR (const char *dir,
   __libc_cleanup_push (cancel_handler, &c);
 #endif
 
+  DIRENT_TYPE **v = NULL;
+  size_t vsize = 0;
+
+  DIRENT_TYPE *d;
   while ((d = READDIR (dp)) != NULL)
     {
       int use_it = select == NULL;
@@ -152,9 +152,6 @@ SCANDIR (const char *dir,
 
       if (use_it)
         {
-          DIRENT_TYPE *vnew;
-          size_t dsize;
-
           /* Ignore errors from select or readdir */
           __set_errno (0);
 
@@ -172,8 +169,8 @@ SCANDIR (const char *dir,
               c.v = (void *) v;
             }
 
-          dsize = &d->d_name[_D_ALLOC_NAMLEN (d)] - (char *) d;
-          vnew = (DIRENT_TYPE *) malloc (dsize);
+          size_t dsize = &d->d_name[_D_ALLOC_NAMLEN (d)] - (char *) d;
+          DIRENT_TYPE *vnew = (DIRENT_TYPE *) malloc (dsize);
           if (vnew == NULL)
             break;
 
index 2baba5a4b123a53926c96b70850334dae4ddab9f..993d5dae3e2cd0e8476d4b6780e3ec2b4dcd15c0 100644 (file)
@@ -114,13 +114,12 @@ static BOOL IsConsoleHandle (HANDLE h)
 static BOOL
 IsSocketHandle (HANDLE h)
 {
-  WSANETWORKEVENTS ev;
-
   if (IsConsoleHandle (h))
     return FALSE;
 
   /* Under Wine, it seems that getsockopt returns 0 for pipes too.
      WSAEnumNetworkEvents instead distinguishes the two correctly.  */
+  WSANETWORKEVENTS ev;
   ev.lNetworkEvents = 0xDEADBEEF;
   WSAEnumNetworkEvents ((SOCKET) h, NULL, &ev);
   return ev.lNetworkEvents != 0xDEADBEEF;
@@ -135,17 +134,12 @@ windows_poll_handle (HANDLE h, int fd,
                      struct bitset *wbits,
                      struct bitset *xbits)
 {
-  BOOL read, write, except;
-  int ret;
-  INPUT_RECORD *irbuffer;
-  DWORD avail, nbuffer;
-  BOOL bRet;
-  IO_STATUS_BLOCK iosb;
-  FILE_PIPE_LOCAL_INFORMATION fpli;
   static PNtQueryInformationFile NtQueryInformationFile;
   static BOOL once_only;
 
-  read = write = except = FALSE;
+  BOOL read = FALSE;
+  BOOL write = FALSE;
+  BOOL except = FALSE;
   switch (GetFileType (h))
     {
     case FILE_TYPE_DISK:
@@ -162,6 +156,7 @@ windows_poll_handle (HANDLE h, int fd,
           once_only = TRUE;
         }
 
+      DWORD avail;
       if (PeekNamedPipe (h, NULL, 0, NULL, &avail, NULL) != 0)
         {
           if (avail)
@@ -169,7 +164,6 @@ windows_poll_handle (HANDLE h, int fd,
         }
       else if (GetLastError () == ERROR_BROKEN_PIPE)
         ;
-
       else
         {
           /* It was the write-end of the pipe.  Check if it is writable.
@@ -180,7 +174,9 @@ windows_poll_handle (HANDLE h, int fd,
              (I think this should not happen since Windows XP SP2; WINE seems
              fine too).  Otherwise, ensure that enough space is available for
              atomic writes.  */
+          IO_STATUS_BLOCK iosb;
           memset (&iosb, 0, sizeof (iosb));
+          FILE_PIPE_LOCAL_INFORMATION fpli;
           memset (&fpli, 0, sizeof (fpli));
 
           if (!NtQueryInformationFile
@@ -198,8 +194,7 @@ windows_poll_handle (HANDLE h, int fd,
       if (!(rbits->in[fd / CHAR_BIT] & (1 << (fd & (CHAR_BIT - 1)))))
         break;
 
-      ret = WaitForSingleObject (h, 0);
-      if (ret == WAIT_OBJECT_0)
+      if (WaitForSingleObject (h, 0) == WAIT_OBJECT_0)
         {
           if (!IsConsoleHandle (h))
             {
@@ -207,9 +202,8 @@ windows_poll_handle (HANDLE h, int fd,
               break;
             }
 
-          nbuffer = avail = 0;
-          bRet = GetNumberOfConsoleInputEvents (h, &nbuffer);
-
+          DWORD nbuffer = 0;
+          BOOL bRet = GetNumberOfConsoleInputEvents (h, &nbuffer);
           /* Screen buffers handles are filtered earlier.  */
           assert (bRet);
           if (nbuffer == 0)
@@ -218,9 +212,10 @@ windows_poll_handle (HANDLE h, int fd,
               break;
             }
 
-          irbuffer = (INPUT_RECORD *) alloca (nbuffer * sizeof (INPUT_RECORD));
-          bRet = PeekConsoleInput (h, irbuffer, nbuffer, &avail);
-          if (!bRet || avail == 0)
+          INPUT_RECORD *irbuffer =
+            (INPUT_RECORD *) alloca (nbuffer * sizeof (INPUT_RECORD));
+          DWORD avail = 0;
+          if (! PeekConsoleInput (h, irbuffer, nbuffer, &avail) || avail == 0)
             {
               except = TRUE;
               break;
@@ -233,15 +228,16 @@ windows_poll_handle (HANDLE h, int fd,
       break;
 
     default:
-      ret = WaitForSingleObject (h, 0);
-      write = TRUE;
-      if (ret == WAIT_OBJECT_0)
-        read = TRUE;
-
+      {
+        int ret = WaitForSingleObject (h, 0);
+        write = TRUE;
+        if (ret == WAIT_OBJECT_0)
+          read = TRUE;
+      }
       break;
     }
 
-  ret = 0;
+  int ret = 0;
   if (read && (rbits->in[fd / CHAR_BIT] & (1 << (fd & (CHAR_BIT - 1)))))
     {
       rbits->out[fd / CHAR_BIT] |= (1 << (fd & (CHAR_BIT - 1)));
@@ -270,14 +266,6 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
 {
   static struct timeval tv0;
   static HANDLE hEvent;
-  HANDLE h, handle_array[FD_SETSIZE + 2];
-  fd_set handle_rfds, handle_wfds, handle_xfds;
-  struct bitset rbits, wbits, xbits;
-  unsigned char anyfds_in[FD_SETSIZE / CHAR_BIT];
-  DWORD ret, wait_timeout, nhandles, nsock, nbuffer;
-  MSG msg;
-  int fd, rc;
-  clock_t tend;
 
   if (nfds < 0 || nfds > FD_SETSIZE)
     {
@@ -285,6 +273,7 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
       return -1;
     }
 
+  DWORD wait_timeout;
   if (!timeout)
     wait_timeout = INFINITE;
   else
@@ -302,23 +291,24 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
   if (!hEvent)
     hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
 
-  handle_array[0] = hEvent;
-  nhandles = 1;
-  nsock = 0;
-
   /* Copy descriptors to bitsets.  At the same time, eliminate
      bits in the "wrong" direction for console input buffers
      and screen buffers, because screen buffers are waitable
      and they will block until a character is available.  */
+  struct bitset rbits;
   memset (&rbits, 0, sizeof (rbits));
+  struct bitset wbits;
   memset (&wbits, 0, sizeof (wbits));
+  struct bitset xbits;
   memset (&xbits, 0, sizeof (xbits));
+  unsigned char anyfds_in[FD_SETSIZE / CHAR_BIT];
   memset (anyfds_in, 0, sizeof (anyfds_in));
   if (rfds)
     for (int i = 0; i < rfds->fd_count; i++)
       {
-        fd = rfds->fd_array[i];
-        h = (HANDLE) _get_osfhandle (fd);
+        int fd = rfds->fd_array[i];
+        HANDLE h = (HANDLE) _get_osfhandle (fd);
+        DWORD nbuffer;
         if (!IsConsoleHandle (h)
             || GetNumberOfConsoleInputEvents (h, &nbuffer))
           {
@@ -332,8 +322,9 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
   if (wfds)
     for (int i = 0; i < wfds->fd_count; i++)
       {
-        fd = wfds->fd_array[i];
-        h = (HANDLE) _get_osfhandle (fd);
+        int fd = wfds->fd_array[i];
+        HANDLE h = (HANDLE) _get_osfhandle (fd);
+        DWORD nbuffer;
         if (!IsConsoleHandle (h)
             || !GetNumberOfConsoleInputEvents (h, &nbuffer))
           {
@@ -347,7 +338,7 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
   if (xfds)
     for (int i = 0; i < xfds->fd_count; i++)
       {
-        fd = xfds->fd_array[i];
+        int fd = xfds->fd_array[i];
         xbits.in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
         anyfds_in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
       }
@@ -358,16 +349,24 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
   FD_ZERO (rfds);
   FD_ZERO (wfds);
   FD_ZERO (xfds);
+  fd_set handle_rfds;
   FD_ZERO (&handle_rfds);
+  fd_set handle_wfds;
   FD_ZERO (&handle_wfds);
+  fd_set handle_xfds;
   FD_ZERO (&handle_xfds);
 
+  HANDLE handle_array[FD_SETSIZE + 2];
+  handle_array[0] = hEvent;
+  DWORD nhandles = 1;
+  DWORD nsock = 0;
+
   /* Classify handles.  Create fd sets for sockets, poll the others. */
   for (int i = 0; i < nfds; i++)
     {
       if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) != 0)
         {
-          h = (HANDLE) _get_osfhandle (i);
+          HANDLE h = (HANDLE) _get_osfhandle (i);
           if (!h)
             {
               errno = EBADF;
@@ -418,10 +417,12 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
   handle_array[nhandles] = NULL;
 
   /* When will the waiting period expire?  */
+  clock_t tend;
   if (wait_timeout != INFINITE)
     tend = clock () + wait_timeout;
 
-restart:
+restart: ;
+  int rc;
   if (wait_timeout == 0 || nsock == 0)
     rc = 0;
   else
@@ -453,14 +454,14 @@ restart:
 
   for (;;)
     {
-      ret = MsgWaitForMultipleObjects (nhandles, handle_array, FALSE,
-                                       wait_timeout, QS_ALLINPUT);
+      DWORD ret = MsgWaitForMultipleObjects (nhandles, handle_array, FALSE,
+                                             wait_timeout, QS_ALLINPUT);
 
       if (ret == WAIT_OBJECT_0 + nhandles)
         {
           /* new input of some other kind */
-          BOOL bRet;
-          while ((bRet = PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) != 0)
+          MSG msg;
+          while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE) != 0)
             {
               TranslateMessage (&msg);
               DispatchMessage (&msg);
@@ -482,7 +483,7 @@ restart:
         {
           if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) != 0)
             {
-              h = (HANDLE) _get_osfhandle (i);
+              HANDLE h = (HANDLE) _get_osfhandle (i);
               if (h == handle_array[nhandles])
                 {
                   /* Not a socket.  */
@@ -528,7 +529,7 @@ restart:
     {
       if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) != 0)
         {
-          h = (HANDLE) _get_osfhandle (i);
+          HANDLE h = (HANDLE) _get_osfhandle (i);
           if (h != handle_array[nhandles])
             {
               /* Perform handle->descriptor mapping.  */
index 27f41fde51419c93d40a2ee1ae7b4ee9ce647565..5f3402cd702da23911772ac24b142b1955ea8822 100644 (file)
@@ -123,7 +123,6 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod)
     {
       ace_t entries[6];
       int count;
-      int ret;
 
       if (convention)
         {
@@ -217,6 +216,8 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod)
             entries[4].a_access_mask |= NEW_ACE_EXECUTE;
           count = 6;
         }
+
+      int ret;
       if (desc != -1)
         ret = facl (desc, ACE_SETACL, count, entries);
       else
@@ -237,7 +238,6 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod)
 
   {
     aclent_t entries[3];
-    int ret;
 
     entries[0].a_type = USER_OBJ;
     entries[0].a_id = 0; /* irrelevant */
@@ -249,6 +249,7 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod)
     entries[2].a_id = 0;
     entries[2].a_perm = mode & 7;
 
+    int ret;
     if (desc != -1)
       ret = facl (desc, SETACL,
                   sizeof (entries) / sizeof (aclent_t), entries);
@@ -273,8 +274,8 @@ static int
 context_acl_from_mode (struct permission_context *ctx, const char *name, int desc)
 {
   struct stat statbuf;
-  int ret;
 
+  int ret;
   if (desc != -1)
     ret = fstat (desc, &statbuf);
   else
@@ -299,8 +300,6 @@ context_acl_from_mode (struct permission_context *ctx, const char *name, int des
 static int
 context_aclv_from_mode (struct permission_context *ctx)
 {
-  int ret;
-
   ctx->aclv_entries[0].a_type = USER_OBJ;
   ctx->aclv_entries[0].a_id = 0; /* irrelevant */
   ctx->aclv_entries[0].a_perm = (ctx->mode >> 6) & 7;
@@ -315,7 +314,7 @@ context_aclv_from_mode (struct permission_context *ctx)
   ctx->aclv_entries[3].a_perm = ctx->mode & 7;
   ctx->aclv_count = 4;
 
-  ret = aclsort (ctx->aclv_count, 1, ctx->aclv_entries);
+  int ret = aclsort (ctx->aclv_count, 1, ctx->aclv_entries);
   if (ret > 0)
     abort ();
   return ret;
@@ -328,7 +327,6 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod)
 {
   acl_type_list_t types;
   size_t types_size = sizeof (types);
-  acl_type_t type;
 
   if (aclx_gettypes (name, &types, &types_size) < 0
       || types.num_entries == 0)
@@ -339,11 +337,10 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod)
 
   /* XXX Do we need to clear all types of ACLs for the given file, or is it
      sufficient to clear the first one?  */
-  type = types.entries[0];
+  acl_type_t type = types.entries[0];
   if (type.u64 == ACL_AIXC)
     {
       union { struct acl a; char room[128]; } u;
-      int ret;
 
       u.a.acl_len = (char *) &u.a.acl_ext[0] - (char *) &u.a; /* no entries */
       u.a.acl_mode = mode & ~(S_IXACL | 0777);
@@ -351,6 +348,7 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod)
       u.a.g_access = (mode >> 3) & 7;
       u.a.o_access = mode & 7;
 
+      int ret;
       if (desc != -1)
         ret = aclx_fput (desc, SET_ACL | SET_MODE_S_BITS,
                          type, &u.a, u.a.acl_len, mode);
@@ -363,12 +361,10 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod)
   else if (type.u64 == ACL_NFS4)
     {
       union { nfs4_acl_int_t a; char room[128]; } u;
-      nfs4_ace_int_t *ace;
-      int ret;
-
       u.a.aclVersion = NFS4_ACL_INT_STRUCT_VERSION;
       u.a.aclEntryN = 0;
-      ace = &u.a.aclEntry[0];
+
+      nfs4_ace_int_t *ace = &u.a.aclEntry[0];
       {
         ace->flags = ACE4_ID_SPECIAL;
         ace->aceWho.special_whoid = ACE4_WHO_OWNER;
@@ -422,6 +418,7 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod)
       }
       u.a.aclLength = (char *) ace - (char *) &u.a;
 
+      int ret;
       if (desc != -1)
         ret = aclx_fput (desc, SET_ACL | SET_MODE_S_BITS,
                          type, &u.a, u.a.aclLength, mode);
@@ -453,8 +450,6 @@ context_acl_from_mode (struct permission_context *ctx)
 static int
 context_acl_from_mode (struct permission_context *ctx)
 {
-  int ret;
-
   ctx->entries[0].a_type = USER_OBJ;
   ctx->entries[0].a_id = 0; /* irrelevant */
   ctx->entries[0].a_perm = (ctx->mode >> 6) & 7;
@@ -469,7 +464,7 @@ context_acl_from_mode (struct permission_context *ctx)
   ctx->entries[3].a_perm = ctx->mode & 7;
   ctx->count = 4;
 
-  ret = aclsort (ctx->count, 1, entries);
+  int ret = aclsort (ctx->count, 1, entries);
   if (ret > 0)
     abort ();
   return ret;
@@ -564,9 +559,8 @@ set_acls (struct permission_context *ctx, const char *name, int desc,
 
   if (ctx->acl == NULL)
     {
-      acl_t acl;
-
       /* Remove ACLs if the file has ACLs.  */
+      acl_t acl;
       if (HAVE_ACL_GET_FD && desc != -1)
         acl = acl_get_fd (desc);
       else
@@ -773,7 +767,6 @@ set_permissions (struct permission_context *ctx, const char *name, int desc)
   _GL_UNUSED bool acls_set = false;
   bool early_chmod;
   bool must_chmod = false;
-  int ret = 0;
 
 #if USE_ACL
 # if HAVE_STATACL
@@ -798,11 +791,12 @@ set_permissions (struct permission_context *ctx, const char *name, int desc)
 
   if (early_chmod)
     {
-      ret = chmod_or_fchmod (name, desc, ctx->mode);
+      int ret = chmod_or_fchmod (name, desc, ctx->mode);
       if (ret != 0)
         return -1;
     }
 
+  int ret = 0;
 #if USE_ACL
   ret = set_acls (ctx, name, desc, false, &must_chmod, &acls_set);
   if (! acls_set)
index ef301d4128a8a7eb123fffff9df52aac063f37cc..49321a7518421a666d1b9969e008ebbcdebe219e 100644 (file)
@@ -126,8 +126,6 @@ int
 __add_to_environ (const char *name, const char *value, const char *combined,
                   int replace)
 {
-  char **ep;
-  size_t size;
   const size_t namelen = strlen (name);
   const size_t vallen = value != NULL ? strlen (value) + 1 : 0;
 
@@ -135,9 +133,9 @@ __add_to_environ (const char *name, const char *value, const char *combined,
 
   /* We have to get the pointer now that we have the lock and not earlier
      since another thread might have created a new environment.  */
-  ep = __environ;
+  char **ep = __environ;
 
-  size = 0;
+  size_t size = 0;
   if (ep != NULL)
     {
       for (; *ep != NULL; ++ep)
@@ -149,13 +147,8 @@ __add_to_environ (const char *name, const char *value, const char *combined,
 
   if (ep == NULL || *ep == NULL)
     {
-      char **new_environ;
-#ifdef USE_TSEARCH
-      char *new_value;
-#endif
-
       /* We allocated this space; we can extend it.  */
-      new_environ =
+      char **new_environ =
         (char **) (last_environ == NULL
                    ? malloc ((size + 2) * sizeof (char *))
                    : realloc (last_environ, (size + 2) * sizeof (char *)));
@@ -177,6 +170,7 @@ __add_to_environ (const char *name, const char *value, const char *combined,
         {
           /* See whether the value is already known.  */
 #ifdef USE_TSEARCH
+          char *new_value;
 # ifdef _LIBC
           new_value = (char *) alloca (namelen + 1 + vallen);
           __mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1),
@@ -448,7 +442,6 @@ extern int setenv (const char *, const char *, int);
 int
 rpl_setenv (const char *name, const char *value, int replace)
 {
-  int result;
   if (name == NULL || *name == '\0' || strchr (name, '=') != NULL)
     {
       errno = EINVAL;
@@ -456,13 +449,12 @@ rpl_setenv (const char *name, const char *value, int replace)
     }
   /* Call the real setenv even if replace is 0, in case implementation
      has underlying data to update, such as when environ changes.  */
-  result = setenv (name, value, replace);
+  int result = setenv (name, value, replace);
   if (result == 0 && replace && *value == '=')
     {
       char *tmp = getenv (name);
       if (!STREQ (tmp, value))
         {
-          int saved_errno;
           size_t len = strlen (value);
           tmp = malloca (len + 2);
           if (tmp == NULL)
@@ -474,7 +466,7 @@ rpl_setenv (const char *name, const char *value, int replace)
           *tmp = '=';
           memcpy (tmp + 1, value, len + 1);
           result = setenv (name, tmp, replace);
-          saved_errno = errno;
+          int saved_errno = errno;
           freea (tmp);
           errno = saved_errno;
         }
index ae5cd00be8c1e41f14f944d176799bf461637be6..af3dc9ab4f364e7f0ccf71605896d8f43c04af36 100644 (file)
@@ -45,14 +45,12 @@ sethostname (const char *name, size_t len)
 
 # ifdef __minix /* Minix */
   {
-    FILE *hostf;
-    int r = 0;
-
     /* glibc returns EFAULT, EINVAL, and EPERM on error.  None of
        these are appropriate for us to set, even if they may match the
        situation, during failed open/write/close operations, so we
        leave errno alone and rely on what the system sets up. */
-    hostf = fopen ("/etc/hostname.file", "we");
+    FILE *hostf = fopen ("/etc/hostname.file", "we");
+    int r = 0;
     if (hostf == NULL)
       r = -1;
     else
@@ -116,10 +114,6 @@ sethostname (const char *name, size_t len)
 int
 sethostname (const char *name, size_t len)
 {
-  char name_asciz[HOST_NAME_MAX + 1];
-  char old_name[HOST_NAME_MAX + 1];
-  DWORD old_name_len;
-
   /* Ensure the string isn't too long.  glibc does allow setting an
      empty hostname so no point in enforcing a lower bound. */
   if (len > HOST_NAME_MAX)
@@ -129,11 +123,13 @@ sethostname (const char *name, size_t len)
     }
 
   /* Prepare a NUL-terminated copy of name.  */
+  char name_asciz[HOST_NAME_MAX + 1];
   memcpy (name_asciz, name, len);
   name_asciz[len] = '\0';
 
   /* Save the old NetBIOS name.  */
-  old_name_len = sizeof (old_name) - 1;
+  char old_name[HOST_NAME_MAX + 1];
+  DWORD old_name_len = sizeof (old_name) - 1;
   if (! GetComputerNameEx (ComputerNamePhysicalNetBIOS,
                            old_name, &old_name_len))
     old_name_len = 0;
index 205e5c4db27a2b45b76a06935ec6bdf1cfabd1bb..11648cd9d81337dd730770b9380dcaf8f62eca1f 100644 (file)
@@ -671,10 +671,6 @@ static char *
 setlocale_unixlike (int category, const char *locale)
 {
   int is_utf8 = (GetACP () == 65001);
-  char *result;
-  char llCC_buf[64];
-  char ll_buf[64];
-  char CC_buf[64];
 
   /* The native Windows implementation of setlocale understands the special
      locale name "C", but not "POSIX".  Therefore map "POSIX" to "C".  */
@@ -691,13 +687,14 @@ setlocale_unixlike (int category, const char *locale)
     locale = "English_United States.65001";
 
   /* First, try setlocale with the original argument unchanged.  */
-  result = setlocale_mtsafe (category, locale);
+  char *result = setlocale_mtsafe (category, locale);
   if (result != NULL)
     return result;
 
   /* Otherwise, assume the argument is in the form
        language[_territory][.codeset][@modifier]
      and try to map it using the tables.  */
+  char llCC_buf[64];
   if (strlen (locale) < sizeof (llCC_buf))
     {
       /* Second try: Remove the codeset part.  */
@@ -772,9 +769,11 @@ setlocale_unixlike (int category, const char *locale)
             if (territory_end == NULL)
               territory_end = territory_start + strlen (territory_start);
 
+            char ll_buf[64];
             memcpy (ll_buf, llCC_buf, underscore - llCC_buf);
             strcpy (ll_buf + (underscore - llCC_buf), territory_end);
 
+            char CC_buf[64];
             memcpy (CC_buf, territory_start, territory_end - territory_start);
             CC_buf[territory_end - territory_start] = '\0';
 
@@ -1122,9 +1121,6 @@ static int
 langcmp (const char *locale1, const char *locale2)
 {
   size_t locale1_len;
-  size_t locale2_len;
-  int cmp;
-
   {
     const char *locale1_end = strchr (locale1, '_');
     if (locale1_end != NULL)
@@ -1132,6 +1128,7 @@ langcmp (const char *locale1, const char *locale2)
     else
       locale1_len = strlen (locale1);
   }
+  size_t locale2_len;
   {
     const char *locale2_end = strchr (locale2, '_');
     if (locale2_end != NULL)
@@ -1140,6 +1137,7 @@ langcmp (const char *locale1, const char *locale2)
       locale2_len = strlen (locale2);
   }
 
+  int cmp;
   if (locale1_len < locale2_len)
     {
       cmp = memcmp (locale1, locale2, locale1_len);
@@ -1443,12 +1441,9 @@ setlocale_improved (int category, const char *locale)
               LC_MONETARY,
               LC_MESSAGES
             };
-          char *saved_locale;
-          const char *base_name;
-          unsigned int i;
 
           /* Back up the old locale, in case one of the steps fails.  */
-          saved_locale = setlocale (LC_ALL, NULL);
+          char *saved_locale = setlocale (LC_ALL, NULL);
           if (saved_locale == NULL)
             return NULL;
           saved_locale = strdup (saved_locale);
@@ -1458,11 +1453,12 @@ setlocale_improved (int category, const char *locale)
           /* Set LC_CTYPE category.  Set all other categories (except possibly
              LC_MESSAGES) to the same value in the same call; this is likely to
              save calls.  */
-          base_name =
+          const char *base_name =
             gl_locale_name_environ (LC_CTYPE, category_to_name (LC_CTYPE));
           if (base_name == NULL)
             base_name = gl_locale_name_default ();
 
+          unsigned int i;
           if (setlocale_unixlike (LC_ALL, base_name) != NULL)
             {
               /* LC_CTYPE category already set.  */
@@ -1490,9 +1486,8 @@ setlocale_improved (int category, const char *locale)
           for (; i < sizeof (categories) / sizeof (categories[0]); i++)
             {
               int cat = categories[i];
-              const char *name;
-
-              name = gl_locale_name_environ (cat, category_to_name (cat));
+              const char *name =
+                gl_locale_name_environ (cat, category_to_name (cat));
               if (name == NULL)
                 name = gl_locale_name_default ();
 
index 2988964256b1bfad41fe789a2db1877c6eb39f9d..58ebf6086856371d49eaff06ed1d7d8f9da758f9 100644 (file)
@@ -77,10 +77,9 @@ static int
 setlocale_null_r_with_lock (int category, char *buf, size_t bufsize)
 {
   CRITICAL_SECTION *lock = gl_get_setlocale_null_lock ();
-  int ret;
 
   EnterCriticalSection (lock);
-  ret = setlocale_null_r_unlocked (category, buf, bufsize);
+  int ret = setlocale_null_r_unlocked (category, buf, bufsize);
   LeaveCriticalSection (lock);
 
   return ret;
@@ -116,11 +115,10 @@ setlocale_null_r_with_lock (int category, char *buf, size_t bufsize)
   if (pthread_in_use())
     {
       pthread_mutex_t *lock = gl_get_setlocale_null_lock ();
-      int ret;
 
       if (pthread_mutex_lock (lock))
         abort ();
-      ret = setlocale_null_r_unlocked (category, buf, bufsize);
+      int ret = setlocale_null_r_unlocked (category, buf, bufsize);
       if (pthread_mutex_unlock (lock))
         abort ();
 
@@ -138,11 +136,10 @@ static int
 setlocale_null_r_with_lock (int category, char *buf, size_t bufsize)
 {
   mtx_t *lock = gl_get_setlocale_null_lock ();
-  int ret;
 
   if (mtx_lock (lock) != thrd_success)
     abort ();
-  ret = setlocale_null_r_unlocked (category, buf, bufsize);
+  int ret = setlocale_null_r_unlocked (category, buf, bufsize);
   if (mtx_unlock (lock) != thrd_success)
     abort ();
 
@@ -252,9 +249,7 @@ setlocale_null (int category)
         i;
       char buf[SETLOCALE_NULL_MAX];
       static char resultbuf[LC_INDICES_COUNT][SETLOCALE_NULL_MAX];
-      int err;
-
-      err = setlocale_null_r (category, buf, sizeof (buf));
+      int err = setlocale_null_r (category, buf, sizeof (buf));
       if (err == EINVAL)
         return NULL;
       if (err)
index 18a5c33cea1422f0d682b36489b5a385b6354a7f..85eff199eb524b91603267837fc9cb3245480ee6 100644 (file)
@@ -35,8 +35,6 @@ int
 rpl_setsockopt (int fd, int level, int optname, const void *optval, socklen_t optlen)
 {
   SOCKET sock = FD_TO_SOCKET (fd);
-  int r;
-
   if (sock == INVALID_SOCKET)
     {
       errno = EBADF;
@@ -44,6 +42,8 @@ rpl_setsockopt (int fd, int level, int optname, const void *optval, socklen_t op
     }
   else
     {
+      int r;
+
       if (level == SOL_SOCKET
           && (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO))
         {
index 169802f8a368e2fd3ae9db081b6da3103be59a0b..d897ae48369b145df757202afcb015068ff2370b 100644 (file)
@@ -73,11 +73,7 @@ shell_quote_argv (const char * const *argv)
 {
   if (*argv != NULL)
     {
-      size_t length;
-      char *command;
-      char *p;
-
-      length = 0;
+      size_t length = 0;
       for (const char * const *argp = argv; ; )
         {
           length += shell_quote_length (*argp) + 1;
@@ -86,18 +82,20 @@ shell_quote_argv (const char * const *argv)
             break;
         }
 
-      command = XNMALLOC (length, char);
-
-      p = command;
-      for (const char * const *argp = argv; ; )
-        {
-          p = shell_quote_copy (p, *argp);
-          argp++;
-          if (*argp == NULL)
-            break;
-          *p++ = ' ';
-        }
-      *p = '\0';
+      char *command = XNMALLOC (length, char);
+
+      {
+        char *p = command;
+        for (const char * const *argp = argv; ; )
+          {
+            p = shell_quote_copy (p, *argp);
+            argp++;
+            if (*argp == NULL)
+              break;
+            *p++ = ' ';
+          }
+        *p = '\0';
+      }
 
       return command;
     }
index 8e70dc10b277b3437edb5f2afda3746ab8da9bd5..334c813aaea60e1a59b2dd3f40e47249ec761627 100644 (file)
@@ -65,7 +65,6 @@ sha1_stream (FILE *stream, void *resblock)
       /* We read the file in blocks of BLOCKSIZE bytes.  One call of the
          computation function processes the whole buffer so that with the
          next round of the loop another block can be read.  */
-      size_t n;
       sum = 0;
 
       /* Read block.  Take care for partial reads.  */
@@ -79,7 +78,7 @@ sha1_stream (FILE *stream, void *resblock)
           if (feof (stream))
             goto process_partial_block;
 
-          n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
+          size_t n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
 
           sum += n;
 
index fd72199d2fcdbcb42dd883dba60348b04e1b425d..14fca37b61cee9a83a7e08f29038326277702b5d 100644 (file)
@@ -253,13 +253,14 @@ sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
 
   while (words < endp)
     {
-      uint32_t tm;
       for (int t = 0; t < 16; t++)
         {
           x[t] = SWAP (*words);
           words++;
         }
 
+      uint32_t tm;
+
       R( a, b, c, d, e, F1, K1, x[ 0] );
       R( e, a, b, c, d, F1, K1, x[ 1] );
       R( d, e, a, b, c, F1, K1, x[ 2] );
index 0a587e881d2af2348c2024f03cf9ce7a8df5009c..253cab0591e0ed964ec1c79e1d64fee8eaa0144d 100644 (file)
@@ -67,7 +67,6 @@ shaxxx_stream (FILE *stream, char const *alg, void *resblock,
       /* We read the file in blocks of BLOCKSIZE bytes.  One call of the
          computation function processes the whole buffer so that with the
          next round of the loop another block can be read.  */
-      size_t n;
       sum = 0;
 
       /* Read block.  Take care for partial reads.  */
@@ -81,7 +80,7 @@ shaxxx_stream (FILE *stream, char const *alg, void *resblock,
           if (feof (stream))
             goto process_partial_block;
 
-          n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
+          size_t n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
 
           sum += n;
 
index 27c4f0c76f38173904023ec43f22db47d4be77db..c57bfddf875e015faf081264f5d21a4ac0ebd399 100644 (file)
@@ -324,8 +324,8 @@ sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx)
                     + S0(x[(I-15)&0x0f]) + x[I&0x0f]    \
                , x[I&0x0f] = tm )
 
-#define R(A,B,C,D,E,F,G,H,K,M)  do { t0 = SS0(A) + F2(A,B,C); \
-                                     t1 = H + SS1(E)  \
+#define R(A,B,C,D,E,F,G,H,K,M)  do { uint32_t t0 = SS0(A) + F2(A,B,C); \
+                                     uint32_t t1 = H + SS1(E)  \
                                       + F1(E,F,G)     \
                                       + K             \
                                       + M;            \
@@ -334,8 +334,6 @@ sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx)
 
   while (words < endp)
     {
-      uint32_t tm;
-      uint32_t t0, t1;
       /* FIXME: see sha1.c for a better implementation.  */
       for (int t = 0; t < 16; t++)
         {
@@ -343,6 +341,8 @@ sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx)
           words++;
         }
 
+      uint32_t tm;
+
       R( a, b, c, d, e, f, g, h, K( 0), x[ 0] );
       R( h, a, b, c, d, e, f, g, K( 1), x[ 1] );
       R( g, h, a, b, c, d, e, f, K( 2), x[ 2] );
index adf55457c458c4b8dfd6a9b186c9949abeeda1e8..933bdd3b93a362cd3f3900ebcfcde09b07e28453 100644 (file)
@@ -68,7 +68,6 @@ sha3_xxx_stream (FILE *stream, char const *alg, void *resblock,
       /* We read the file in blocks of BLOCKSIZE bytes.  One call of the
          computation function processes the whole buffer so that with the
          next round of the loop another block can be read.  */
-      size_t n;
       sum = 0;
 
       /* Read block.  Take care for partial reads.  */
@@ -82,7 +81,7 @@ sha3_xxx_stream (FILE *stream, char const *alg, void *resblock,
           if (feof (stream))
             goto process_partial_block;
 
-          n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
+          size_t n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
 
           sum += n;
 
index 551b4822ff1f3ba1e057df4a15a899a834dd5e7d..9bd1034070afc440c4cb257bd5c39e94e2e09228 100644 (file)
@@ -84,10 +84,10 @@ void *
 sha3_read_ctx (const struct sha3_ctx *ctx, void *resbuf)
 {
   char *r = resbuf;
-  int i;
   size_t words = ctx->digestlen / sizeof *ctx->state;
   size_t bytes = ctx->digestlen % sizeof *ctx->state;
 
+  int i;
   for (i = 0; i < words; ++i, r += sizeof *ctx->state)
     set_uint64 (r, SWAP (ctx->state[i]));
   if (bytes)
@@ -173,10 +173,6 @@ sha3_process_block (const void *buffer, size_t len, struct sha3_ctx *ctx)
   const u64 *words = buffer;
   size_t nwords = len / sizeof *words;
   const u64 *endp = words + nwords;
-  u64 c[5];
-  u64 d[5];
-  u64 t1;
-  u64 t2;
 
   while (words < endp)
     {
@@ -184,6 +180,11 @@ sha3_process_block (const void *buffer, size_t len, struct sha3_ctx *ctx)
         ctx->state[i] = u64xor (ctx->state[i], SWAP (*words));
       for (int i = 0; i < 24; ++i)
         {
+          u64 c[5];
+          u64 d[5];
+          u64 t1;
+          u64 t2;
+
           /* Theta step 1.  */
           c[0] = u64xor (u64xor (u64xor (u64xor (a[0], a[5]), a[10]),
                                  a[15]), a[20]);
index 791ee6e8ac30518f9864e1465ea667e9ff35305d..6ec3243776f19e3a2654cb824b3e384163e1a315 100644 (file)
@@ -67,7 +67,6 @@ shaxxx_stream (FILE *stream, char const *alg, void *resblock,
       /* We read the file in blocks of BLOCKSIZE bytes.  One call of the
          computation function processes the whole buffer so that with the
          next round of the loop another block can be read.  */
-      size_t n;
       sum = 0;
 
       /* Read block.  Take care for partial reads.  */
@@ -81,7 +80,7 @@ shaxxx_stream (FILE *stream, char const *alg, void *resblock,
           if (feof (stream))
             goto process_partial_block;
 
-          n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
+          size_t n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
 
           sum += n;
 
index d21aac1c643a9660c076c2b182e18c992a5b4105..5fb3b216e9133ef641a841a158347fad1df163f1 100644 (file)
@@ -291,18 +291,19 @@ str2signum (char const *signame)
           return numname_table[i].num;
 
       {
-        char *endp;
         int rtmin = SIGRTMIN;
         int rtmax = SIGRTMAX;
 
         if (0 < rtmin && strncmp (signame, "RTMIN", 5) == 0)
           {
+            char *endp;
             long int n = strtol (signame + 5, &endp, 10);
             if (! *endp && 0 <= n && n <= rtmax - rtmin)
               return rtmin + n;
           }
         else if (0 < rtmax && strncmp (signame, "RTMAX", 5) == 0)
           {
+            char *endp;
             long int n = strtol (signame + 5, &endp, 10);
             if (! *endp && rtmin - rtmax <= n && n <= 0)
               return rtmax + n;
@@ -340,11 +341,11 @@ sig2str (int signum, char *signame)
   {
     int rtmin = SIGRTMIN;
     int rtmax = SIGRTMAX;
-    int base, delta;
 
     if (! (rtmin <= signum && signum <= rtmax))
       return -1;
 
+    int base;
     if (signum <= rtmin + (rtmax - rtmin) / 2)
       {
         strcpy (signame, "RTMIN");
@@ -356,7 +357,7 @@ sig2str (int signum, char *signame)
         base = rtmax;
       }
 
-    delta = signum - base;
+    int delta = signum - base;
     if (delta != 0)
       sprintf (signame + 5, "%+d", delta);
     return 0;
index 284bfd7e8e4c48f9bef715f2e991753a0d71594d..5d53fe253f7542fbfa4f9a952eb294ce77de907f 100644 (file)
@@ -83,9 +83,6 @@ static struct sigaction volatile action_array[NSIG] /* = 0 */;
 static void
 sigaction_handler (int sig)
 {
-  handler_t handler;
-  sigset_t mask;
-  sigset_t oldmask;
   int saved_errno = errno;
   if (sig < 0 || NSIG <= sig || !action_array[sig].sa_handler)
     {
@@ -103,16 +100,17 @@ sigaction_handler (int sig)
      asynchronous instance of the same signal occurring before we
      reinstall the handler will trigger the default handler; oh
      well.  */
-  handler = action_array[sig].sa_handler;
+  handler_t handler = action_array[sig].sa_handler;
   if ((action_array[sig].sa_flags & SA_RESETHAND) == 0)
     signal (sig, sigaction_handler);
   else
     action_array[sig].sa_handler = NULL;
 
   /* Block appropriate signals.  */
-  mask = action_array[sig].sa_mask;
+  sigset_t mask = action_array[sig].sa_mask;
   if ((action_array[sig].sa_flags & SA_NODEFER) == 0)
     sigaddset (&mask, sig);
+  sigset_t oldmask;
   sigprocmask (SIG_BLOCK, &mask, &oldmask);
 
   /* Invoke the user's handler, then restore prior mask.  */
@@ -131,10 +129,6 @@ int
 sigaction (int sig, const struct sigaction *restrict act,
            struct sigaction *restrict oact)
 {
-  sigset_t mask;
-  sigset_t oldmask;
-  int saved_errno;
-
   if (sig < 0 || NSIG <= sig || sig == SIGKILL || sig == SIGSTOP
       || (act && act->sa_handler == SIG_ERR))
     {
@@ -157,7 +151,9 @@ sigaction (int sig, const struct sigaction *restrict act,
      replacement does not try to use sigaction() from its handler.  */
   if (!act && !oact)
     return 0;
+  sigset_t mask;
   sigfillset (&mask);
+  sigset_t oldmask;
   sigprocmask (SIG_BLOCK, &mask, &oldmask);
   if (oact)
     {
@@ -197,8 +193,10 @@ sigaction (int sig, const struct sigaction *restrict act,
   return 0;
 
  failure:
-  saved_errno = errno;
-  sigprocmask (SIG_SETMASK, &oldmask, NULL);
-  errno = saved_errno;
-  return -1;
+  {
+    int saved_errno = errno;
+    sigprocmask (SIG_SETMASK, &oldmask, NULL);
+    errno = saved_errno;
+    return -1;
+  }
 }
index 5c3899efbaf50243451876da9b34d9d1f633ed35..3018b47c8c951f859ee5383c5c8ad3c51ea74cce 100644 (file)
@@ -211,10 +211,10 @@ int
 sigpending (sigset_t *set)
 {
   sigset_t pending = 0;
-
   for (int sig = 0; sig < NSIG; sig++)
     if (pending_array[sig])
       pending |= 1U << sig;
+
   *set = pending;
   return 0;
 }
@@ -234,9 +234,6 @@ sigprocmask (int operation, const sigset_t *set, sigset_t *old_set)
   if (set != NULL)
     {
       sigset_t new_blocked_set;
-      sigset_t to_unblock;
-      sigset_t to_block;
-
       switch (operation)
         {
         case SIG_BLOCK:
@@ -253,8 +250,9 @@ sigprocmask (int operation, const sigset_t *set, sigset_t *old_set)
           errno = EINVAL;
           return -1;
         }
-      to_unblock = blocked_set & ~new_blocked_set;
-      to_block = new_blocked_set & ~blocked_set;
+
+      sigset_t to_unblock = blocked_set & ~new_blocked_set;
+      sigset_t to_block = new_blocked_set & ~blocked_set;
 
       if (to_block != 0)
         for (int sig = 0; sig < NSIG; sig++)
index 6cec1c5af07ff8de44081da80f3887a8e9bed8d6..bbf6d64a5180d475bbb6ab59405bf5bb91c2f163 100644 (file)
@@ -1049,12 +1049,9 @@ sigsegv_handler (SIGSEGV_FAULT_HANDLER_ARGLIST)
           if (stack_top)
             {
               /* Determine stack bounds.  */
-              int saved_errno;
+              int saved_errno = errno;
               struct vma_struct vma;
-              int ret;
-
-              saved_errno = errno;
-              ret = sigsegv_get_vma (stack_top, &vma);
+              int ret = sigsegv_get_vma (stack_top, &vma);
               errno = saved_errno;
               if (ret >= 0)
                 {
@@ -1086,9 +1083,8 @@ sigsegv_handler (SIGSEGV_FAULT_HANDLER_ARGLIST)
                   /* Heuristic BC: If the stack size has reached its maximal size,
                      and old_sp is near the low end, we consider it a stack
                      overflow.  */
-                  struct rlimit rl;
-
                   saved_errno = errno;
+                  struct rlimit rl;
                   ret = getrlimit (RLIMIT_STACK, &rl);
                   errno = saved_errno;
                   if (ret >= 0)
@@ -1192,12 +1188,9 @@ sigsegv_handler (int sig)
       if (stack_top)
         {
           /* Determine stack bounds.  */
-          int saved_errno;
+          int saved_errno = errno;
           struct vma_struct vma;
-          int ret;
-
-          saved_errno = errno;
-          ret = sigsegv_get_vma (stack_top, &vma);
+          int ret = sigsegv_get_vma (stack_top, &vma);
           errno = saved_errno;
           if (ret >= 0)
             {
@@ -1205,9 +1198,8 @@ sigsegv_handler (int sig)
               /* Heuristic BC: If the stack size has reached its maximal size,
                  and old_sp is near the low end, we consider it a stack
                  overflow.  */
-              struct rlimit rl;
-
               saved_errno = errno;
+              struct rlimit rl;
               ret = getrlimit (RLIMIT_STACK, &rl);
               errno = saved_errno;
               if (ret >= 0)
index fa2c973f2843d629b93bbb160f1f2d8f1c15536a..d1b1967c0bec94f7fb6ff4a1d350cb72d3884ec1 100644 (file)
@@ -109,10 +109,7 @@ static const long double sincosl_table[];
 long double
 kernel_sinl (long double x, long double y, int iy)
 {
-  long double h, l, z, sin_l, cos_l_m1;
-  int index, sign;
-
-  sign = 1;
+  int sign = 1;
   if (x < 0)
     {
       x = -x;
@@ -127,7 +124,7 @@ kernel_sinl (long double x, long double y, int iy)
         if (!((int) x))
           return x * sign;             /* generate inexact */
 
-      z = x * x;
+      long double z = x * x;
       return (x + x * (z * (SIN1 + z *
                            (SIN2 + z *
                            (SIN3 + z *
@@ -147,19 +144,20 @@ kernel_sinl (long double x, long double y, int iy)
          sinl(k+l) = sinl(k)cosl(l) + cosl(k)sinl(l).
          Furthermore write k = 0.1484375 + h.  */
       x -= 0.1484375L;
-      index = (int) (x * 128L + 0.5L);
-      h = index / 128.0L;
+      int index = (int) (x * 128L + 0.5L);
+      long double h = index / 128.0L;
+      long double l;
       if (iy)
         l = y - (h - x);
       else
         l = x - h;
 
-      z = l * l;
-      sin_l =
+      long double z = l * l;
+      long double sin_l =
         l * (ONE +
              z * (SSIN1 +
                   z * (SSIN2 + z * (SSIN3 + z * (SSIN4 + z * SSIN5)))));
-      cos_l_m1 =
+      long double cos_l_m1 =
         z * (SCOS1 + z * (SCOS2 + z * (SCOS3 + z * (SCOS4 + z * SCOS5))));
 
       index *= 4;
@@ -178,9 +176,6 @@ kernel_sinl (long double x, long double y, int iy)
 long double
 kernel_cosl (long double x, long double y)
 {
-  long double h, l, z, sin_l, cos_l_m1;
-  int index;
-
   if (x < 0)
     x = -x;
 
@@ -191,7 +186,7 @@ kernel_cosl (long double x, long double y)
       if (x < 0.000000000000000006938893903907228377647697925567626953125L)     /* |x| < 2^-57 */
         if (!((int) x))
           return ONE;           /* generate inexact */
-      z = x * x;
+      long double z = x * x;
       return ONE + (z * (COS1 + z * (COS2 + z * (COS3 + z * (COS4 +
                                                              z * (COS5 +
                                                                   z * (COS6 +
@@ -210,15 +205,15 @@ kernel_cosl (long double x, long double y)
          cosl(k+l) = cosl(k)cosl(l) - sinl(k)sinl(l).
          Furthermore write k = 0.1484375 + h.  */
       x -= 0.1484375L;
-      index = (int) (x * 128L + 0.5L);
-      h = index / 128.0L;
-      l = y - (h - x);
-      z = l * l;
-      sin_l =
+      int index = (int) (x * 128L + 0.5L);
+      long double h = index / 128.0L;
+      long double l = y - (h - x);
+      long double z = l * l;
+      long double sin_l =
         l * (ONE +
              z * (SSIN1 +
                   z * (SSIN2 + z * (SSIN3 + z * (SSIN4 + z * SSIN5)))));
-      cos_l_m1 =
+      long double cos_l_m1 =
         z * (SCOS1 + z * (SCOS2 + z * (SCOS3 + z * (SCOS4 + z * SCOS5))));
 
       index *= 4;
index 1dd5bf8d52459701fa9e95c1959d97cd7656d50e..e1c3ec635f20e28db726d3187cdcea35384add21 100644 (file)
@@ -83,9 +83,6 @@ sinl (long double x)
 long double
 sinl (long double x)
 {
-  long double y[2], z = 0.0L;
-  int n;
-
   /* sinl(NaN) is NaN */
   if (isnanl (x))
     return x;
@@ -93,7 +90,10 @@ sinl (long double x)
   /* |x| ~< pi/4 */
   if (x >= -0.7853981633974483096156608458198757210492
       && x <= 0.7853981633974483096156608458198757210492)
-    return kernel_sinl (x, z, 0);
+    {
+      long double z = 0.0L;
+      return kernel_sinl (x, z, 0);
+    }
 
     /* sinl(Inf) is NaN, sinl(0) is 0 */
   else if (x + x == x)
@@ -102,7 +102,8 @@ sinl (long double x)
   /* argument reduction needed */
   else
     {
-      n = ieee754_rem_pio2l (x, y);
+      long double y[2];
+      int n = ieee754_rem_pio2l (x, y);
       switch (n & 3)
         {
         case 0:
index d7c0b38e97fb2c192afdcd240498c115e3d135af..a82ac4ef82596e56c5f3c4de7a12e8f719b52d95 100644 (file)
@@ -58,9 +58,8 @@ rpl_sleep (unsigned int seconds)
   const unsigned int limit = 24 * 24 * 60 * 60;
   while (limit < seconds)
     {
-      unsigned int result;
       seconds -= limit;
-      result = sleep (limit);
+      unsigned int result = sleep (limit);
       if (result)
         return seconds + result;
     }
index b755b42110b7d25e34c441b1d702a8f1618c8339..f0dc736a8ceb797d6f2636eca55f47b95dbee581 100644 (file)
 int
 sm3_stream (FILE *stream, void *resblock)
 {
-  struct sm3_ctx ctx;
-  size_t sum;
-
   char *buffer = malloc (BLOCKSIZE + 72);
   if (!buffer)
     return 1;
 
   /* Initialize the computation context.  */
+  struct sm3_ctx ctx;
   sm3_init_ctx (&ctx);
 
+  size_t sum;
+
   /* Iterate over full file contents.  */
   while (1)
     {
       /* We read the file in blocks of BLOCKSIZE bytes.  One call of the
          computation function processes the whole buffer so that with the
          next round of the loop another block can be read.  */
-      size_t n;
       sum = 0;
 
       /* Read block.  Take care for partial reads.  */
       while (1)
         {
-          n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
+          size_t n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
 
           sum += n;
 
index 4941de56844eff1e3c579aed4c016c5b72f4e6a5..47c0ab23f32f6b12b4b74bc75b3f9d0486b41dfd 100644 (file)
--- a/lib/sm3.c
+++ b/lib/sm3.c
@@ -294,8 +294,8 @@ sm3_process_block (const void *buffer, size_t len, struct sm3_ctx *ctx)
        if (++j) \
          dbg_printf("%2d %08x %08x %08x %08x %08x %08x %08x %08x\n", \
                     j-1, A, B, C, D, E, F, G, H); \
-       ss1 = rol(rol(A,12) + E + T,7); \
-       ss2 = ss1 ^ rol(A,12); \
+       uint32_t ss1 = rol(rol(A,12) + E + T,7); \
+       uint32_t ss2 = ss1 ^ rol(A,12); \
        D += FF##i(A,B,C) + ss2 + (W1 ^ W2); \
        H += GG##i(E,F,G) + ss1 + W1; \
        B = rol(B,9); \
@@ -308,9 +308,6 @@ sm3_process_block (const void *buffer, size_t len, struct sm3_ctx *ctx)
 
   while (words < endp)
     {
-      uint32_t tw;
-      uint32_t ss1, ss2;
-
       for (int j = 0; j < 16; j++)
         {
           x[j] = SWAP (*words);
@@ -324,6 +321,8 @@ sm3_process_block (const void *buffer, size_t len, struct sm3_ctx *ctx)
                   "   %08x %08x %08x %08x %08x %08x %08x %08x\n",
                   a, b, c, d, e, f, g, h);
 
+      uint32_t tw;
+
       R1( a, b, c, d, e, f, g, h, T( 0), W1( 0), W1( 4) );
       R1( d, a, b, c, h, e, f, g, T( 1), W1( 1), W1( 5) );
       R1( c, d, a, b, g, h, e, f, T( 2), W1( 2), W1( 6) );
index edeee083a344ef4d5d1f8aeaeb2c37dfb8ce006a..1c83e3a24fea96526685b78ca168209fa8fb87ca 100644 (file)
@@ -28,10 +28,8 @@ int
 snprintf (char *str, size_t size, const char *format, ...)
 {
   va_list args;
-  ptrdiff_t ret;
-
   va_start (args, format);
-  ret = vsnzprintf (str, size, format, args);
+  ptrdiff_t ret = vsnzprintf (str, size, format, args);
   va_end (args);
 
 #if PTRDIFF_MAX > INT_MAX
index 63ffa90323f403f290f32869945dfbdb2427afc5..de425843fcc990e965fb89126b083607cd81aec6 100644 (file)
 ptrdiff_t
 snzprintf (char *str, size_t size, const char *format, ...)
 {
-  char *output;
-  size_t len;
-  size_t lenbuf = size;
   va_list args;
-
   va_start (args, format);
-  output = vasnprintf (str, &lenbuf, format, args);
-  len = lenbuf;
+
+  size_t lenbuf = size;
+  char *output = vasnprintf (str, &lenbuf, format, args);
+  size_t len = lenbuf;
+
   va_end (args);
 
   if (!output)
index 5b25240951994fac4c744041666fc5c4cec001cf..ededc3132430b6a76b81307045050626d50e7b15 100644 (file)
 int
 rpl_socket (int domain, int type, int protocol)
 {
-  SOCKET fh;
-
   gl_sockets_startup (SOCKETS_1_1);
 
   /* We have to use WSASocket() to create non-overlapped IO sockets.
      Overlapped IO sockets cannot be used with read/write.  */
-  fh = WSASocket (domain, type, protocol, NULL, 0, 0);
+  SOCKET fh = WSASocket (domain, type, protocol, NULL, 0, 0);
 
   if (fh == INVALID_SOCKET)
     {
index 7accfdd3b7a1a923530a46afa4dbd472122b9af2..3188c8c4d3de5258f913066c967acd677f524d68 100644 (file)
@@ -46,11 +46,10 @@ close_fd_maybe_socket (const struct fd_hook *remaining_list,
      our calls to closesocket() and the primary close(), some other thread
      could make system calls that allocate precisely the same HANDLE value
      as sock; then the primary close() would call CloseHandle() on it.  */
-  SOCKET sock;
-  WSANETWORKEVENTS ev;
 
   /* Test whether fd refers to a socket.  */
-  sock = FD_TO_SOCKET (fd);
+  SOCKET sock = FD_TO_SOCKET (fd);
+  WSANETWORKEVENTS ev;
   ev.lNetworkEvents = 0xDEADBEEF;
   WSAEnumNetworkEvents (sock, NULL, &ev);
   if (ev.lNetworkEvents != 0xDEADBEEF)
@@ -83,11 +82,9 @@ ioctl_fd_maybe_socket (const struct fd_hook *remaining_list,
                        gl_ioctl_fn primary,
                        int fd, int request, void *arg)
 {
-  SOCKET sock;
-  WSANETWORKEVENTS ev;
-
   /* Test whether fd refers to a socket.  */
-  sock = FD_TO_SOCKET (fd);
+  SOCKET sock = FD_TO_SOCKET (fd);
+  WSANETWORKEVENTS ev;
   ev.lNetworkEvents = 0xDEADBEEF;
   WSAEnumNetworkEvents (sock, NULL, &ev);
   if (ev.lNetworkEvents != 0xDEADBEEF)
@@ -119,9 +116,7 @@ gl_sockets_startup (_GL_UNUSED int version)
   if (version > initialized_sockets_version)
     {
       WSADATA data;
-      int err;
-
-      err = WSAStartup (version, &data);
+      int err = WSAStartup (version, &data);
       if (err != 0)
         return 1;
 
@@ -146,13 +141,11 @@ int
 gl_sockets_cleanup (void)
 {
 #if WINDOWS_SOCKETS
-  int err;
-
   initialized_sockets_version = 0;
 
   unregister_fd_hook (&fd_sockets_hook);
 
-  err = WSACleanup ();
+  int err = WSACleanup ();
   if (err != 0)
     return 1;
 #endif
index cd27addd4bb480dd4ef3bfd8bd013695bfd9033e..47b869bb2c43bcd1098bed28c99741570d3480af 100644 (file)
@@ -437,18 +437,9 @@ create_pipe (const char *progname,
 #else
 
   /* Unix API.  */
-  char **child_environ;
-  char **malloced_environ;
-  sigset_t blocked_signals;
-  posix_spawn_file_actions_t actions;
-  bool actions_allocated;
-  posix_spawnattr_t attrs;
-  bool attrs_allocated;
-  int err;
-  pid_t child;
 
-  child_environ = environ;
-  malloced_environ = NULL;
+  char **child_environ = environ;
+  char **malloced_environ = NULL;
 # if defined _WIN32 || defined __CYGWIN__
   if (dll_dirs != NULL && dll_dirs[0] != NULL)
     {
@@ -459,13 +450,20 @@ create_pipe (const char *progname,
     }
 # endif
 
+  sigset_t blocked_signals;
   if (slave_process)
     {
       sigprocmask (SIG_SETMASK, NULL, &blocked_signals);
       block_fatal_signals ();
     }
-  actions_allocated = false;
-  attrs_allocated = false;
+
+  posix_spawn_file_actions_t actions;
+  bool actions_allocated = false;
+  posix_spawnattr_t attrs;
+  bool attrs_allocated = false;
+
+  int err;
+  pid_t child;
   if ((err = posix_spawn_file_actions_init (&actions)) != 0
       || (actions_allocated = true,
           (pipe_stdin
index a4cf875d68f0f1f72ffc2f11a36928f211cdf204..237e21d54cea5087d50f31a80fa8fb6f36f83803 100644 (file)
@@ -879,7 +879,8 @@ __spawni (pid_t *pid, const char *file,
      Linux/ppc64, Linux/ppc64le, and Solaris/SPARC, it causes a SIGBUS or
      SIGSEGV when done in the child process after vfork() and when $PATH is long
      (ca. 4 KB or so).  */
-  char *path, *name;
+  char *path;
+  char *name;
   if (use_path)
     {
       /* We have to search for FILE on the path.  */
index 093bc5ae069cde7a7e978f981355e87b14808c7d..f6db277cbafb991e171d4b0e5d66974435ae64e7 100644 (file)
@@ -30,10 +30,8 @@ int
 sprintf (char *str, const char *format, ...)
 {
   va_list args;
-  ptrdiff_t ret;
-
   va_start (args, format);
-  ret = vszprintf (str, format, args);
+  ptrdiff_t ret = vszprintf (str, format, args);
   va_end (args);
 
 #if PTRDIFF_MAX > INT_MAX
index a648eb12bf42c674d1cfc90c95de7f05a36c71a1..50224137af8404dedba7dff6c3b890b816c60792 100644 (file)
@@ -39,9 +39,6 @@ sqrtl (long double x)
 long double
 sqrtl (long double x)
 {
-  long double delta, y;
-  int exponent;
-
   /* Check for NaN */
   if (isnanl (x))
     return x;
@@ -54,9 +51,11 @@ sqrtl (long double x)
   if (x + x == x)
     return x;
 
+  int exponent;
   frexpl (x, &exponent);
-  y = ldexpl (x, -exponent / 2);
+  long double y = ldexpl (x, -exponent / 2);
 
+  long double delta;
   do
     {
       delta = y;
index 0d7277cc6c540b6eb029eee2a5840fc75f315679..a9035a2475c06140982df3fae813fd05760844e1 100644 (file)
@@ -683,19 +683,19 @@ static struct page_pool medium_block_pages =
 static inline uintptr_t
 allocate_block_from_pool (size_t size, struct page_pool *pool)
 {
-  uintptr_t page;
-
   /* Try in the last used page first.  */
-  page = pool->last_page;
-  if (likely (page != 0))
-    {
-      uintptr_t block = pool->allocate_block_in_page (size, page);
-      if (likely (block != 0))
-        {
-          add_update (page, pool);
-          return block;
-        }
-    }
+  {
+    uintptr_t page = pool->last_page;
+    if (likely (page != 0))
+      {
+        uintptr_t block = pool->allocate_block_in_page (size, page);
+        if (likely (block != 0))
+          {
+            add_update (page, pool);
+            return block;
+          }
+      }
+  }
 
   /* Ensure that the pool and its managed_pages is initialized.  */
   if (unlikely (pool->managed_pages == NULL))
@@ -721,7 +721,7 @@ allocate_block_from_pool (size_t size, struct page_pool *pool)
     while (gl_oset_iterator_next (&iter, &elt))
       {
         struct page_tree_element *element = (struct page_tree_element *) elt;
-        page = element->page;
+        uintptr_t page = element->page;
         /* No need to try the last used page again.  */
         if (likely (page != pool->last_page))
           {
@@ -738,6 +738,8 @@ allocate_block_from_pool (size_t size, struct page_pool *pool)
     gl_oset_iterator_free (&iter);
   }
 
+  uintptr_t page;
+
   /* If we have a freeable page ready for reuse, use it.  */
   if (pool->freeable_page != 0)
     {
index 95bb80db7c14c467d5aa0740a120068994a86ad7..66bdf3295633581f97510429f17fabb5e536009b 100644 (file)
@@ -155,19 +155,15 @@ struct rofile
 static int
 rof_open (struct rofile *rof, const char *filename)
 {
-  int fd;
-  uintptr_t pagesize;
-  size_t size;
-
-  fd = open (filename, O_RDONLY);
+  int fd = open (filename, O_RDONLY);
   if (fd < 0)
     return -1;
   rof->position = 0;
   rof->eof_seen = 0;
   /* Try the static buffer first.  */
-  pagesize = 0;
+  uintptr_t pagesize = 0;
   rof->buffer = rof->stack_allocated_buffer;
-  size = sizeof (rof->stack_allocated_buffer);
+  size_t size = sizeof (rof->stack_allocated_buffer);
   rof->auxmap = NULL;
   rof->auxmap_start = 0;
   rof->auxmap_end = 0;
@@ -364,16 +360,18 @@ vma_iterate_proc (struct callback_locals *locals)
 
       for (;;)
         {
-          uintptr_t start, end;
-          int c;
-
           /* Parse one line.  First start and end.  */
+          uintptr_t start, end;
           if (!(rof_scanf_lx (&rof, &start) >= 0
                 && rof_getchar (&rof) == '-'
                 && rof_scanf_lx (&rof, &end) >= 0))
             break;
-          while (c = rof_getchar (&rof), c != -1 && c != '\n')
-            ;
+
+          {
+            int c;
+            while (c = rof_getchar (&rof), c != -1 && c != '\n')
+              ;
+          }
 
           if (start <= auxmap_start && auxmap_end - 1 <= end - 1)
             {
@@ -420,23 +418,28 @@ vma_iterate_proc (struct callback_locals *locals)
 
       for (;;)
         {
-          uintptr_t start, end;
-          int c;
-
           /* Parse one line.  First start.  */
+          uintptr_t start;
           if (!(rof_getchar (&rof) == '0'
                 && rof_getchar (&rof) == 'x'
                 && rof_scanf_lx (&rof, &start) >= 0))
             break;
-          while (c = rof_peekchar (&rof), c == ' ' || c == '\t')
-            rof_getchar (&rof);
+          {
+            int c;
+            while (c = rof_peekchar (&rof), c == ' ' || c == '\t')
+              rof_getchar (&rof);
+          }
           /* Then end.  */
+          uintptr_t end;
           if (!(rof_getchar (&rof) == '0'
                 && rof_getchar (&rof) == 'x'
                 && rof_scanf_lx (&rof, &end) >= 0))
             break;
-          while (c = rof_getchar (&rof), c != -1 && c != '\n')
-            ;
+          {
+            int c;
+            while (c = rof_getchar (&rof), c != -1 && c != '\n')
+              ;
+          }
 
           if (start <= auxmap_start && auxmap_end - 1 <= end - 1)
             {
@@ -474,17 +477,7 @@ vma_iterate_bsd (struct callback_locals *locals)
 {
   /* Documentation: https://www.freebsd.org/cgi/man.cgi?sysctl(3)  */
   int info_path[] = { CTL_KERN, KERN_PROC, KERN_PROC_VMMAP, getpid () };
-  size_t len;
-  size_t pagesize;
-  size_t memneed;
-  void *auxmap;
-  unsigned long auxmap_start;
-  unsigned long auxmap_end;
-  char *mem;
-  char *p;
-  char *p_end;
-
-  len = 0;
+  size_t len = 0;
   if (sysctl (info_path, 4, NULL, &len, NULL, 0) < 0)
     return -1;
   /* Allow for small variations over time.  In a multithreaded program
@@ -495,46 +488,48 @@ vma_iterate_bsd (struct callback_locals *locals)
      We also cannot use malloc here, because a malloc() call may call mmap()
      and thus pre-allocate available memory.
      So use mmap(), and ignore the resulting VMA.  */
-  pagesize = getpagesize ();
-  memneed = len;
+  size_t pagesize = getpagesize ();
+  size_t memneed = len;
   memneed = ((memneed - 1) / pagesize + 1) * pagesize;
-  auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
-                          MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+  void *auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
+                                MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
   if (auxmap == (void *) -1)
     return -1;
-  auxmap_start = (unsigned long) auxmap;
-  auxmap_end = auxmap_start + memneed;
-  mem = (char *) auxmap;
+  unsigned long auxmap_start = (unsigned long) auxmap;
+  unsigned long auxmap_end = auxmap_start + memneed;
+  char *mem = (char *) auxmap;
   if (sysctl (info_path, 4, mem, &len, NULL, 0) < 0)
     {
       munmap (auxmap, memneed);
       return -1;
     }
-  p = mem;
-  p_end = mem + len;
-  while (p < p_end)
-    {
-      struct kinfo_vmentry *kve = (struct kinfo_vmentry *) p;
-      unsigned long start = kve->kve_start;
-      unsigned long end = kve->kve_end;
-      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)
-            if (callback (locals, start, auxmap_start))
-              break;
-          if (auxmap_end - 1 < end - 1)
-            if (callback (locals, auxmap_end, end))
+  {
+    char *p = mem;
+    char *p_end = mem + len;
+    while (p < p_end)
+      {
+        struct kinfo_vmentry *kve = (struct kinfo_vmentry *) p;
+        unsigned long start = kve->kve_start;
+        unsigned long end = kve->kve_end;
+        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)
+              if (callback (locals, start, auxmap_start))
+                break;
+            if (auxmap_end - 1 < end - 1)
+              if (callback (locals, auxmap_end, end))
+                break;
+          }
+        else
+          {
+            if (callback (locals, start, end))
               break;
-        }
-      else
-        {
-          if (callback (locals, start, end))
-            break;
-        }
-      p += kve->kve_structsize;
-    }
+          }
+        p += kve->kve_structsize;
+      }
+  }
   munmap (auxmap, memneed);
   return 0;
 }
@@ -750,15 +745,12 @@ mapped_range_start (uintptr_t addr)
     }
   for (;;)
     {
-      uintptr_t halfstepsize1;
-      uintptr_t halfstepsize2;
-
       if (stepsize == 1)
         return addr;
 
       /* Here we know that less than stepsize pages exist starting at addr.  */
-      halfstepsize1 = (stepsize + 1) / 2;
-      halfstepsize2 = stepsize / 2;
+      uintptr_t halfstepsize1 = (stepsize + 1) / 2;
+      uintptr_t halfstepsize2 = stepsize / 2;
       /* halfstepsize1 + halfstepsize2 = stepsize.  */
 
       if (mincore ((MINCORE_ADDR_T) (addr - halfstepsize1 * pagesize),
@@ -786,12 +778,10 @@ mapped_range_end (uintptr_t addr)
   addr += pagesize;
   for (;;)
     {
-      uintptr_t max_remaining;
-
       if (addr == 0) /* wrapped around? */
         return addr;
 
-      max_remaining = (- addr) / pagesize;
+      uintptr_t max_remaining = (- addr) / pagesize;
       if (stepsize > max_remaining)
         stepsize = max_remaining;
       if (mincore ((MINCORE_ADDR_T) addr, stepsize * pagesize, vec) < 0)
@@ -802,15 +792,12 @@ mapped_range_end (uintptr_t addr)
     }
   for (;;)
     {
-      uintptr_t halfstepsize1;
-      uintptr_t halfstepsize2;
-
       if (stepsize == 1)
         return addr;
 
       /* Here we know that less than stepsize pages exist starting at addr.  */
-      halfstepsize1 = (stepsize + 1) / 2;
-      halfstepsize2 = stepsize / 2;
+      uintptr_t halfstepsize1 = (stepsize + 1) / 2;
+      uintptr_t halfstepsize2 = stepsize / 2;
       /* halfstepsize1 + halfstepsize2 = stepsize.  */
 
       if (mincore ((MINCORE_ADDR_T) addr, halfstepsize1 * pagesize, vec) < 0)
@@ -828,9 +815,6 @@ mapped_range_end (uintptr_t addr)
 static int
 is_unmapped (uintptr_t addr1, uintptr_t addr2)
 {
-  uintptr_t count;
-  uintptr_t stepsize;
-
   /* Round addr1 down.  */
   addr1 = (addr1 / pagesize) * pagesize;
   /* Round addr2 up and turn it into an exclusive bound.  */
@@ -846,20 +830,19 @@ is_unmapped (uintptr_t addr1, uintptr_t addr2)
      average, therefore we have good chances of hitting a mapped area if we
      traverse only every second, or only fourth page, etc.  This doesn't
      decrease the worst-case runtime, only the average runtime.  */
-  count = (addr2 - addr1) / pagesize;
+  uintptr_t count = (addr2 - addr1) / pagesize;
   /* We have to test is_mapped (addr1 + i * pagesize) for 0 <= i < count.  */
+  uintptr_t stepsize;
   for (stepsize = 1; stepsize < count; )
     stepsize = 2 * stepsize;
   for (;;)
     {
-      uintptr_t addr_stepsize;
-      uintptr_t i;
-      uintptr_t addr;
-
       stepsize = stepsize / 2;
       if (stepsize == 0)
         break;
-      addr_stepsize = stepsize * pagesize;
+      uintptr_t addr_stepsize = stepsize * pagesize;
+      uintptr_t i;
+      uintptr_t addr;
       for (i = stepsize, addr = addr1 + addr_stepsize;
            i < count;
            i += 2 * stepsize, addr += 2 * addr_stepsize)
@@ -1272,16 +1255,12 @@ is_mapped (uintptr_t addr)
 static uintptr_t
 mapped_range_start (uintptr_t addr)
 {
-  uintptr_t stepsize;
-  uintptr_t known_unmapped_page;
-
   /* Look at smaller addresses, in larger and larger steps, to minimize the
      number of mquery() calls.  */
-  stepsize = pagesize;
+  uintptr_t known_unmapped_page;
+  uintptr_t stepsize = pagesize;
   for (;;)
     {
-      uintptr_t hole;
-
       if (addr == 0)
         abort ();
 
@@ -1291,8 +1270,8 @@ mapped_range_start (uintptr_t addr)
           break;
         }
 
-      hole = (uintptr_t) mquery ((void *) (addr - stepsize), pagesize,
-                                     0, 0, -1, 0);
+      uintptr_t hole = (uintptr_t) mquery ((void *) (addr - stepsize), pagesize,
+                                           0, 0, -1, 0);
       if (!(hole == (uintptr_t) (void *) -1 || hole >= addr))
         {
           /* Some part of [addr - stepsize, addr - 1] is unmapped.  */
@@ -1315,11 +1294,9 @@ mapped_range_start (uintptr_t addr)
   /* Still 0 < addr - known_unmapped_page <= stepsize.  */
   while (stepsize > pagesize)
     {
-      uintptr_t hole;
-
       stepsize = stepsize / 2;
-      hole = (uintptr_t) mquery ((void *) (addr - stepsize), pagesize,
-                                     0, 0, -1, 0);
+      uintptr_t hole = (uintptr_t) mquery ((void *) (addr - stepsize), pagesize,
+                                           0, 0, -1, 0);
       if (!(hole == (uintptr_t) (void *) -1 || hole >= addr))
         /* Some part of [addr - stepsize, addr - 1] is unmapped.  */
         known_unmapped_page = hole;
@@ -1338,12 +1315,10 @@ mapped_range_start (uintptr_t addr)
 static uintptr_t
 mapped_range_end (uintptr_t addr)
 {
-  uintptr_t end;
-
   if (addr == 0)
     abort ();
 
-  end = (uintptr_t) mquery ((void *) addr, pagesize, 0, 0, -1, 0);
+  uintptr_t end = (uintptr_t) mquery ((void *) addr, pagesize, 0, 0, -1, 0);
   if (end == (uintptr_t) (void *) -1)
     end = 0; /* wrap around */
   return end;
@@ -1625,16 +1600,12 @@ vma_iterate (struct callback_locals *locals)
      only the virtual memory areas that are connected to a file, not the
      anonymous ones.  But at least since AIX 7.1, it is well usable.  */
 
-  char fnamebuf[6+10+4+1];
-  char *fname;
-  int fd;
-  size_t memneed;
-
   if (pagesize == 0)
     init_pagesize ();
 
+  char fnamebuf[6+10+4+1];
   /* Construct fname = sprintf (fnamebuf+i, "/proc/%u/map", getpid ()).  */
-  fname = fnamebuf + sizeof (fnamebuf) - (4+1);
+  char *fname = fnamebuf + sizeof (fnamebuf) - (4+1);
   memcpy (fname, "/map", 4+1);
   {
     unsigned int value = getpid ();
@@ -1645,7 +1616,7 @@ vma_iterate (struct callback_locals *locals)
   fname -= 6;
   memcpy (fname, "/proc/", 6);
 
-  fd = open (fname, O_RDONLY | O_CLOEXEC);
+  int fd = open (fname, O_RDONLY | O_CLOEXEC);
   if (fd < 0)
     return -1;
 
@@ -1656,7 +1627,7 @@ vma_iterate (struct callback_locals *locals)
      We read the entire contents, but look only at the prmap_t entries and
      ignore the tail part.  */
 
-  for (memneed = 2 * pagesize; ; memneed = 2 * memneed)
+  for (size_t memneed = 2 * pagesize; ; memneed = 2 * memneed)
     {
       /* Allocate memneed bytes of memory.
          We cannot use alloca here, because not much stack space is guaranteed.
@@ -1665,25 +1636,21 @@ vma_iterate (struct callback_locals *locals)
          So use mmap(), and ignore the resulting VMA if it occurs among the
          resulting VMAs.  (Normally it doesn't, because it was allocated after
          the open() call.)  */
-      void *auxmap;
-      unsigned long auxmap_start;
-      unsigned long auxmap_end;
-      ssize_t nbytes;
-
-      auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
-                              MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+      void *auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
+                                    MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
       if (auxmap == (void *) -1)
         {
           close (fd);
           return -1;
         }
-      auxmap_start = (unsigned long) auxmap;
-      auxmap_end = auxmap_start + memneed;
+      unsigned long auxmap_start = (unsigned long) auxmap;
+      unsigned long auxmap_end = auxmap_start + memneed;
 
       /* Read the contents of /proc/<pid>/map in a single system call.
          This guarantees a consistent result (no duplicated or omitted
          entries).  */
-     retry:
+     retry: ;
+      ssize_t nbytes;
       do
         nbytes = read (fd, auxmap, memneed);
       while (nbytes < 0 && errno == EINTR);
@@ -1718,7 +1685,7 @@ vma_iterate (struct callback_locals *locals)
             }
 
           /* We now have the entire contents of /proc/<pid>/map in memory.  */
-          prmap_tmaps = (prmap_t *) auxmap;
+          prmap_t *maps = (prmap_t *) auxmap;
 
           /* The entries are not sorted by address.  Therefore
              1. Extract the relevant information into an array.
@@ -1735,46 +1702,41 @@ vma_iterate (struct callback_locals *locals)
           vma_t *vmas = (vma_t *) auxmap;
 
           vma_t *vp = vmas;
-          {
-            prmap_t* mp;
-            for (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)
-                  {
-                    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++;
-                          }
-                        if (auxmap_end - 1 < end - 1)
-                          {
-                            vp->start = auxmap_end;
-                            vp->end = end;
-                            vp++;
-                          }
-                      }
-                    else
-                      {
-                        vp->start = start;
-                        vp->end = end;
-                        vp++;
-                      }
-                  }
-                mp++;
-              }
-          }
+          for (prmap_t *mp = maps;;)
+            {
+              unsigned long start = (unsigned long) mp->pr_vaddr;
+              unsigned long 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)
+                {
+                  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++;
+                        }
+                      if (auxmap_end - 1 < end - 1)
+                        {
+                          vp->start = auxmap_end;
+                          vp->end = end;
+                          vp++;
+                        }
+                    }
+                  else
+                    {
+                      vp->start = start;
+                      vp->end = end;
+                      vp++;
+                    }
+                }
+              mp++;
+            }
 
           size_t nvmas = vp - vmas;
           /* Sort the array in ascending order.
@@ -1782,32 +1744,25 @@ vma_iterate (struct callback_locals *locals)
              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 (locals, vpi->start, vpi->end))
-                  break;
-              }
-          }
+          for (size_t i = 0; i < nvmas; i++)
+            {
+              vma_t *vpi = &vmas[i];
+              if (callback (locals, vpi->start, vpi->end))
+                break;
+            }
 
           munmap (auxmap, memneed);
           break;
@@ -1956,22 +1911,12 @@ vma_iterate (struct callback_locals *locals)
 # if defined PIOCNMAP && defined PIOCMAP
   /* We must use the older /proc interface.  */
 
-  char fnamebuf[6+10+1];
-  char *fname;
-  int fd;
-  int nmaps;
-  size_t memneed;
-  void *auxmap;
-  uintptr_t auxmap_start;
-  uintptr_t auxmap_end;
-  prmap_t* maps;
-  prmap_t* mp;
-
   if (pagesize == 0)
     init_pagesize ();
 
+  char fnamebuf[6+10+1];
   /* Construct fname = sprintf (fnamebuf+i, "/proc/%u", getpid ()).  */
-  fname = fnamebuf + sizeof (fnamebuf) - 1;
+  char *fname = fnamebuf + sizeof (fnamebuf) - 1;
   *fname = '\0';
   {
     unsigned int value = getpid ();
@@ -1982,37 +1927,36 @@ vma_iterate (struct callback_locals *locals)
   fname -= 6;
   memcpy (fname, "/proc/", 6);
 
-  fd = open (fname, O_RDONLY);
+  int fd = open (fname, O_RDONLY);
   if (fd < 0)
     return -1;
 
+  int nmaps;
   if (ioctl (fd, PIOCNMAP, &nmaps) < 0)
     goto fail2;
 
-  memneed = (nmaps + 10) * sizeof (prmap_t);
+  size_t memneed = (nmaps + 10) * sizeof (prmap_t);
   /* Allocate memneed bytes of memory.
      We cannot use alloca here, because not much stack space is guaranteed.
      We also cannot use malloc here, because a malloc() call may call mmap()
      and thus pre-allocate available memory.
      So use mmap(), and ignore the resulting VMA.  */
   memneed = ((memneed - 1) / pagesize + 1) * pagesize;
-  auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
-                          MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+  void *auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
+                                MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
   if (auxmap == (void *) -1)
     goto fail2;
-  auxmap_start = (uintptr_t) auxmap;
-  auxmap_end = auxmap_start + memneed;
-  maps = (prmap_t *) auxmap;
+  uintptr_t auxmap_start = (uintptr_t) auxmap;
+  uintptr_t auxmap_end = auxmap_start + memneed;
+  prmap_t *maps = (prmap_t *) auxmap;
 
   if (ioctl (fd, PIOCMAP, maps) < 0)
     goto fail1;
 
-  for (mp = maps;;)
+  for (prmap_t *mp = maps;;)
     {
-      uintptr_t start, end;
-
-      start = (uintptr_t) mp->pr_vaddr;
-      end = start + mp->pr_size;
+      uintptr_t start = (uintptr_t) mp->pr_vaddr;
+      uintptr_t end = start + mp->pr_size;
       if (start == 0 && end == 0)
         break;
       mp++;
@@ -2051,23 +1995,12 @@ vma_iterate (struct callback_locals *locals)
      prmap_t.  These are different in 32-bit and 64-bit processes,
      but here we are fortunately accessing only the current process.  */
 
-  char fnamebuf[6+10+4+1];
-  char *fname;
-  int fd;
-  int nmaps;
-  size_t memneed;
-  void *auxmap;
-  uintptr_t auxmap_start;
-  uintptr_t auxmap_end;
-  prmap_t* maps;
-  prmap_t* maps_end;
-  prmap_t* mp;
-
   if (pagesize == 0)
     init_pagesize ();
 
+  char fnamebuf[6+10+4+1];
   /* Construct fname = sprintf (fnamebuf+i, "/proc/%u/map", getpid ()).  */
-  fname = fnamebuf + sizeof (fnamebuf) - 1 - 4;
+  char *fname = fnamebuf + sizeof (fnamebuf) - 1 - 4;
   memcpy (fname, "/map", 4 + 1);
   {
     unsigned int value = getpid ();
@@ -2078,10 +2011,11 @@ vma_iterate (struct callback_locals *locals)
   fname -= 6;
   memcpy (fname, "/proc/", 6);
 
-  fd = open (fname, O_RDONLY);
+  int fd = open (fname, O_RDONLY);
   if (fd < 0)
     return -1;
 
+  int nmaps;
   {
     struct stat statbuf;
     if (fstat (fd, &statbuf) < 0)
@@ -2089,22 +2023,23 @@ vma_iterate (struct callback_locals *locals)
     nmaps = statbuf.st_size / sizeof (prmap_t);
   }
 
-  memneed = (nmaps + 10) * sizeof (prmap_t);
+  size_t memneed = (nmaps + 10) * sizeof (prmap_t);
   /* Allocate memneed bytes of memory.
      We cannot use alloca here, because not much stack space is guaranteed.
      We also cannot use malloc here, because a malloc() call may call mmap()
      and thus pre-allocate available memory.
      So use mmap(), and ignore the resulting VMA.  */
   memneed = ((memneed - 1) / pagesize + 1) * pagesize;
-  auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
-                          MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+  void *auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
+                                MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
   if (auxmap == (void *) -1)
     goto fail2;
-  auxmap_start = (uintptr_t) auxmap;
-  auxmap_end = auxmap_start + memneed;
-  maps = (prmap_t *) auxmap;
+  uintptr_t auxmap_start = (uintptr_t) auxmap;
+  uintptr_t auxmap_end = auxmap_start + memneed;
+  prmap_t *maps = (prmap_t *) auxmap;
 
   /* Read up to memneed bytes from fd into maps.  */
+  prmap_t *maps_end;
   {
     size_t remaining = memneed;
     size_t total_read = 0;
@@ -2132,7 +2067,7 @@ vma_iterate (struct callback_locals *locals)
     maps_end = maps + nmaps;
   }
 
-  for (mp = maps; mp < maps_end; mp++)
+  for (prmap_t *mp = maps; mp < maps_end; mp++)
     {
       uintptr_t start, end;
 
@@ -2371,16 +2306,12 @@ callback (struct callback_locals *locals, uintptr_t start, uintptr_t end)
 static int
 vma_iterate (struct callback_locals *locals)
 {
+  ssize_t cookie = 0;
   area_info info;
-  ssize_t cookie;
-
-  cookie = 0;
   while (get_next_area_info (0, &cookie, &info) == B_OK)
     {
-      uintptr_t start, end;
-
-      start = (uintptr_t) info.address;
-      end = start + info.size;
+      uintptr_t start = (uintptr_t) info.address;
+      uintptr_t end = start + info.size;
 
       if (callback (locals, start, end))
         break;
index 097ff96903eaa23a6b6e33d0a3e9f2c64e682f4c..c8b924159bdf1438858d00f26804c88d65bb676e 100644 (file)
@@ -112,11 +112,11 @@ initialize (void)
 struct timespec
 _gl_convert_FILETIME_to_timespec (const FILETIME *ft)
 {
-  struct timespec result;
   /* FILETIME: <https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-filetime> */
   unsigned long long since_1601 =
     ((unsigned long long) ft->dwHighDateTime << 32)
     | (unsigned long long) ft->dwLowDateTime;
+  struct timespec result;
   if (since_1601 == 0)
     {
       result.tv_sec = 0;
index 80561a6da4ee4112f8b196ff9adb55bd0d3271fa..488ed8434b082eb389aa9c3332b448db201f35bc 100644 (file)
@@ -133,8 +133,8 @@ int
 gl_consolesafe_fprintf (FILE *restrict fp, const char *restrict format, ...)
 {
   va_list args;
-  char *tmpstring;
   va_start (args, format);
+  char *tmpstring;
   int result = vasprintf (&tmpstring, format, args);
   va_end (args);
   if (result >= 0)
@@ -151,8 +151,8 @@ int
 gl_consolesafe_printf (const char *restrict format, ...)
 {
   va_list args;
-  char *tmpstring;
   va_start (args, format);
+  char *tmpstring;
   int result = vasprintf (&tmpstring, format, args);
   va_end (args);
   if (result >= 0)
index 70452b485b0a04d8c3122c6d3542f5d5c6ba6727..12a4b98feaef739591c8b775eaa982cf0f2f9a50 100644 (file)
@@ -52,9 +52,8 @@
     return (EXPRESSION);                                                      \
   else                                                                        \
     {                                                                         \
-      RETTYPE ret;                                                            \
       SetLastError (0);                                                       \
-      ret = (EXPRESSION);                                                     \
+      RETTYPE ret = (EXPRESSION);                                             \
       if (FAILED)                                                             \
         {                                                                     \
           if (GetLastError () == ERROR_NO_DATA && ferror (stream))            \
 int
 scanf (const char *format, ...)
 {
-  int retval;
   va_list args;
-
   va_start (args, format);
-  retval = vfscanf (stdin, format, args);
+  int retval = vfscanf (stdin, format, args);
   va_end (args);
 
   return retval;
@@ -103,11 +100,9 @@ scanf (const char *format, ...)
 int
 fscanf (FILE *stream, const char *format, ...)
 {
-  int retval;
   va_list args;
-
   va_start (args, format);
-  retval = vfscanf (stream, format, args);
+  int retval = vfscanf (stream, format, args);
   va_end (args);
 
   return retval;
index 59ba8fc4c348835e54ede7b363ef58ad7e674d24..bcdc08504167f85154c0f2a660619b8d5b714c17 100644 (file)
     return (EXPRESSION);                                                      \
   else                                                                        \
     {                                                                         \
-      RETTYPE ret;                                                            \
       CLEAR_ERRNO                                                             \
       CLEAR_LastError                                                         \
-      ret = (EXPRESSION);                                                     \
+      RETTYPE ret = (EXPRESSION);                                             \
       if (FAILED)                                                             \
         {                                                                     \
           HANDLE_ENOSPC                                                       \
 int
 printf (const char *format, ...)
 {
-  int retval;
   va_list args;
-
   va_start (args, format);
-  retval = vfprintf (stdout, format, args);
+  int retval = vfprintf (stdout, format, args);
   va_end (args);
 
   return retval;
@@ -139,11 +136,9 @@ printf (const char *format, ...)
 int
 fprintf (FILE *stream, const char *format, ...)
 {
-  int retval;
   va_list args;
-
   va_start (args, format);
-  retval = vfprintf (stream, format, args);
+  int retval = vfprintf (stream, format, args);
   va_end (args);
 
   return retval;
index 8bcc305d8b6023d4d95e5f5189b957a7194841d6..025023c5029da96d9cb62508388121482b418f58 100644 (file)
@@ -33,7 +33,6 @@
 char *
 (__stpncpy) (char *dest, const char *src, size_t n)
 {
-  char c;
   char *s = dest;
 
   if (n >= 4)
@@ -42,22 +41,30 @@ char *
 
       for (;;)
         {
-          c = *src++;
-          *dest++ = c;
-          if (c == '\0')
-            break;
-          c = *src++;
-          *dest++ = c;
-          if (c == '\0')
-            break;
-          c = *src++;
-          *dest++ = c;
-          if (c == '\0')
-            break;
-          c = *src++;
-          *dest++ = c;
-          if (c == '\0')
-            break;
+          {
+            char c = *src++;
+            *dest++ = c;
+            if (c == '\0')
+              break;
+          }
+          {
+            char c = *src++;
+            *dest++ = c;
+            if (c == '\0')
+              break;
+          }
+          {
+            char c = *src++;
+            *dest++ = c;
+            if (c == '\0')
+              break;
+          }
+          {
+            char c = *src++;
+            *dest++ = c;
+            if (c == '\0')
+              break;
+          }
           if (--n4 == 0)
             goto last_chars;
         }
@@ -72,7 +79,7 @@ char *
 
   for (;;)
     {
-      c = *src++;
+      char c = *src++;
       --n;
       *dest++ = c;
       if (c == '\0')
index 352ea72aa603a3fea06b78e94b2ea90261b3c560..c7c2e2d47bb51e261285ccd0b809e6d40a190ae5 100644 (file)
@@ -119,14 +119,10 @@ knuth_morris_pratt (const UNIT *haystack,
 
   /* Search, using the table to accelerate the processing.  */
   {
-    size_t j;
-    const UNIT *rhaystack;
-    const UNIT *phaystack;
-
     *resultp = NULL;
-    j = 0;
-    rhaystack = haystack;
-    phaystack = haystack;
+    size_t j = 0;
+    const UNIT *rhaystack = haystack;
+    const UNIT *phaystack = haystack;
     /* Invariant: phaystack = rhaystack + j.  */
     while (*phaystack != 0)
       if (CANON_ELEMENT (needle[j]) == CANON_ELEMENT (*phaystack))
index 1da773eb70e017542762f96eed0636009eb93503..deb62a0971e5092b111c4aff3d7d2a0f5ac4451b 100644 (file)
@@ -108,13 +108,6 @@ static size_t
 critical_factorization (const unsigned char *needle, size_t needle_len,
                         size_t *period)
 {
-  /* Index of last byte of left half, or SIZE_MAX.  */
-  size_t max_suffix, max_suffix_rev;
-  size_t j; /* Index into NEEDLE for current candidate suffix.  */
-  size_t k; /* Offset into current period.  */
-  size_t p; /* Intermediate period.  */
-  unsigned char a, b; /* Current comparison bytes.  */
-
   /* Special case NEEDLE_LEN of 1 or 2 (all callers already filtered
      out 0-length needles.  */
   if (needle_len < 3)
@@ -133,73 +126,83 @@ critical_factorization (const unsigned char *needle, size_t needle_len,
   */
 
   /* Perform lexicographic search.  */
-  max_suffix = SIZE_MAX;
-  j = 0;
-  k = p = 1;
-  while (j + k < needle_len)
-    {
-      a = CANON_ELEMENT (needle[j + k]);
-      b = CANON_ELEMENT (needle[max_suffix + k]);
-      if (a < b)
-        {
-          /* Suffix is smaller, period is entire prefix so far.  */
-          j += k;
-          k = 1;
-          p = j - max_suffix;
-        }
-      else if (a == b)
-        {
-          /* Advance through repetition of the current period.  */
-          if (k != p)
-            ++k;
-          else
-            {
-              j += p;
-              k = 1;
-            }
-        }
-      else /* b < a */
-        {
-          /* Suffix is larger, start over from current location.  */
-          max_suffix = j++;
-          k = p = 1;
-        }
-    }
-  *period = p;
+  size_t max_suffix = /* Index of last byte of left half, or SIZE_MAX.  */
+    SIZE_MAX;
+  {
+    size_t j = 0; /* Index into NEEDLE for current candidate suffix.  */
+    size_t k = 1; /* Offset into current period.  */
+    size_t p = 1; /* Intermediate period.  */
+    while (j + k < needle_len)
+      {
+        unsigned char a = CANON_ELEMENT (needle[j + k]);
+        unsigned char b = CANON_ELEMENT (needle[max_suffix + k]);
+        if (a < b)
+          {
+            /* Suffix is smaller, period is entire prefix so far.  */
+            j += k;
+            k = 1;
+            p = j - max_suffix;
+          }
+        else if (a == b)
+          {
+            /* Advance through repetition of the current period.  */
+            if (k != p)
+              ++k;
+            else
+              {
+                j += p;
+                k = 1;
+              }
+          }
+        else /* b < a */
+          {
+            /* Suffix is larger, start over from current location.  */
+            max_suffix = j++;
+            k = p = 1;
+          }
+      }
+    *period = p;
+  }
 
   /* Perform reverse lexicographic search.  */
-  max_suffix_rev = SIZE_MAX;
-  j = 0;
-  k = p = 1;
-  while (j + k < needle_len)
-    {
-      a = CANON_ELEMENT (needle[j + k]);
-      b = CANON_ELEMENT (needle[max_suffix_rev + k]);
-      if (b < a)
-        {
-          /* Suffix is smaller, period is entire prefix so far.  */
-          j += k;
-          k = 1;
-          p = j - max_suffix_rev;
-        }
-      else if (a == b)
-        {
-          /* Advance through repetition of the current period.  */
-          if (k != p)
-            ++k;
-          else
-            {
-              j += p;
-              k = 1;
-            }
-        }
-      else /* a < b */
-        {
-          /* Suffix is larger, start over from current location.  */
-          max_suffix_rev = j++;
-          k = p = 1;
-        }
-    }
+  size_t max_suffix_rev = /* Index of last byte of left half, or SIZE_MAX.  */
+    SIZE_MAX;
+  size_t p_rev;
+  {
+    size_t j = 0; /* Index into NEEDLE for current candidate suffix.  */
+    size_t k = 1; /* Offset into current period.  */
+    size_t p = 1; /* Intermediate period.  */
+    while (j + k < needle_len)
+      {
+        unsigned char a = CANON_ELEMENT (needle[j + k]);
+        unsigned char b = CANON_ELEMENT (needle[max_suffix_rev + k]);
+        if (b < a)
+          {
+            /* Suffix is smaller, period is entire prefix so far.  */
+            j += k;
+            k = 1;
+            p = j - max_suffix_rev;
+          }
+        else if (a == b)
+          {
+            /* Advance through repetition of the current period.  */
+            if (k != p)
+              ++k;
+            else
+               {
+                j += p;
+                k = 1;
+              }
+          }
+        else /* a < b */
+          {
+            /* Suffix is larger, start over from current location.  */
+            max_suffix_rev = j++;
+            k = p = 1;
+          }
+      }
+    p_rev = p;
+  }
 
   /* Choose the shorter suffix.  Return the index of the first byte of
      the right half, rather than the last byte of the left half.
@@ -217,7 +220,7 @@ critical_factorization (const unsigned char *needle, size_t needle_len,
      factorization.  */
   if (max_suffix_rev + 1 < max_suffix + 1)
     return max_suffix + 1;
-  *period = p;
+  *period = p_rev;
   return max_suffix_rev + 1;
 }
 
@@ -235,15 +238,12 @@ static RETURN_TYPE _GL_ATTRIBUTE_PURE
 two_way_short_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.  */
-
   /* Factor the needle into two halves, such that the left half is
      smaller than the global period, and the right half is
      periodic (with a period as large as NEEDLE_LEN - suffix).  */
-  suffix = critical_factorization (needle, needle_len, &period);
+  size_t period; /* The period of the right half of needle.  */
+  size_t suffix = /* The index of the right half of needle.  */
+    critical_factorization (needle, needle_len, &period);
 
   /* Perform the search.  Each iteration compares the right half
      first.  */
@@ -253,11 +253,12 @@ two_way_short_needle (const unsigned char *haystack, size_t haystack_len,
          only advance by the period, so use memory to avoid rescanning
          known occurrences of the period in the right half.  */
       size_t memory = 0;
-      j = 0;
+      size_t j = 0; /* Index into current window of HAYSTACK.  */
       while (AVAILABLE (haystack, haystack_len, j, needle_len))
         {
           /* Scan for matches in right half.  */
-          i = MAX (suffix, memory);
+          size_t i = /* Index into current byte of NEEDLE.  */
+            MAX (suffix, memory);
           while (i < needle_len && (CANON_ELEMENT (needle[i])
                                     == CANON_ELEMENT (haystack[i + j])))
             ++i;
@@ -287,11 +288,12 @@ two_way_short_needle (const unsigned char *haystack, size_t haystack_len,
       /* The two halves of needle are distinct; no extra memory is
          required, and any mismatch results in a maximal shift.  */
       period = MAX (suffix, needle_len - suffix) + 1;
-      j = 0;
+      size_t j = 0; /* Index into current window of HAYSTACK.  */
       while (AVAILABLE (haystack, haystack_len, j, needle_len))
         {
           /* Scan for matches in right half.  */
-          i = suffix;
+          size_t i = /* Index into current byte of NEEDLE.  */
+            suffix;
           while (i < needle_len && (CANON_ELEMENT (needle[i])
                                     == CANON_ELEMENT (haystack[i + j])))
             ++i;
@@ -329,20 +331,18 @@ 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 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.  */
-  size_t shift_table[1U << CHAR_BIT]; /* See below.  */
-
   /* Factor the needle into two halves, such that the left half is
      smaller than the global period, and the right half is
      periodic (with a period as large as NEEDLE_LEN - suffix).  */
-  suffix = critical_factorization (needle, needle_len, &period);
+  size_t period; /* The period of the right half of needle.  */
+  size_t suffix = /* The index of the right half of needle.  */
+    critical_factorization (needle, needle_len, &period);
 
   /* Populate shift_table.  For each possible byte value c,
      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.  */
+  size_t shift_table[1U << CHAR_BIT];
   for (size_t i = 0; i < 1U << CHAR_BIT; i++)
     shift_table[i] = needle_len;
   for (size_t i = 0; i < needle_len; i++)
@@ -356,13 +356,13 @@ two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
          only advance by the period, so use memory to avoid rescanning
          known occurrences of the period in the right half.  */
       size_t memory = 0;
-      size_t shift;
-      j = 0;
+      size_t j = 0; /* Index into current window of HAYSTACK.  */
       while (AVAILABLE (haystack, haystack_len, j, needle_len))
         {
           /* Check the last byte first; if it does not match, then
              shift to the next possible match location.  */
-          shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
+          size_t shift =
+            shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
           if (0 < shift)
             {
               if (memory && shift < period)
@@ -409,14 +409,14 @@ two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
     {
       /* The two halves of needle are distinct; no extra memory is
          required, and any mismatch results in a maximal shift.  */
-      size_t shift;
       period = MAX (suffix, needle_len - suffix) + 1;
-      j = 0;
+      size_t j = 0; /* Index into current window of HAYSTACK.  */
       while (AVAILABLE (haystack, haystack_len, j, needle_len))
         {
           /* Check the last byte first; if it does not match, then
              shift to the next possible match location.  */
-          shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
+          size_t shift =
+            shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
           if (0 < shift)
             {
               j += shift;
index 16626d4d092350b87c169689722cc745eb170a22..e186f3a94bdf2b39bb6644071f0935e56daacfbe 100644 (file)
@@ -32,29 +32,24 @@ strcasecmp (const char *s1, const char *s2)
 {
   const unsigned char *p1 = (const unsigned char *) s1;
   const unsigned char *p2 = (const unsigned char *) s2;
-  unsigned char c1, c2;
 
   if (p1 == p2)
     return 0;
 
-  do
+  for (;; p1++, p2++)
     {
-      c1 = tolower (*p1);
-      c2 = tolower (*p2);
-
-      if (c1 == '\0')
-        break;
-
-      ++p1;
-      ++p2;
+      unsigned char c1 = tolower (*p1);
+      unsigned char c2 = tolower (*p2);
+
+      if (c1 == '\0' || c1 != c2)
+        {
+          if (UCHAR_MAX <= INT_MAX)
+            return c1 - c2;
+          else
+            /* On machines where 'char' and 'int' are types of the same size,
+               the difference of two 'unsigned char' values - including the
+               sign bit - doesn't fit in an 'int'.  */
+            return _GL_CMP (c1, c2);
+        }
     }
-  while (c1 == c2);
-
-  if (UCHAR_MAX <= INT_MAX)
-    return c1 - c2;
-  else
-    /* On machines where 'char' and 'int' are types of the same size, the
-       difference of two 'unsigned char' values - including the sign bit -
-       doesn't fit in an 'int'.  */
-    return _GL_CMP (c1, c2);
 }
index 151182244b8bb8831f33cbd60bad9da42dc77083..2c6fcf7616b78fa18a2bd217a4bf7661c05e864b 100644 (file)
@@ -42,11 +42,10 @@ strcasecmp_l (const char *s1, const char *s2, locale_t locale)
 # else
   /* Implementation for the global locale.  */
   {
-    int ret;
 #  if HAVE_WORKING_USELOCALE
     locale_t saved_locale = uselocale (LC_GLOBAL_LOCALE);
 #  endif
-    ret = strcasecmp (s1, s2);
+    int ret = strcasecmp (s1, s2);
 #  if HAVE_WORKING_USELOCALE
     uselocale (saved_locale);
 #  endif
@@ -56,31 +55,25 @@ strcasecmp_l (const char *s1, const char *s2, locale_t locale)
 
 #else
 
-  unsigned char c1, c2;
-
   if (s1 == s2)
     return 0;
 
-  do
+  for (;; s1++, s2++)
     {
-      c1 = tolower_l ((unsigned char) *s1, locale);
-      c2 = tolower_l ((unsigned char) *s2, locale);
-
-      if (c1 == '\0')
-        break;
-
-      ++s1;
-      ++s2;
+      unsigned char c1 = tolower_l ((unsigned char) *s1, locale);
+      unsigned char c2 = tolower_l ((unsigned char) *s2, locale);
+
+      if (c1 == '\0' || c1 != c2)
+        {
+          if (UCHAR_MAX <= INT_MAX)
+            return c1 - c2;
+          else
+            /* On machines where 'char' and 'int' are types of the same size,
+               the difference of two 'unsigned char' values - including the
+               sign bit - doesn't fit in an 'int'.  */
+            return _GL_CMP (c1, c2);
+        }
     }
-  while (c1 == c2);
-
-  if (UCHAR_MAX <= INT_MAX)
-    return c1 - c2;
-  else
-    /* On machines where 'char' and 'int' are types of the same size, the
-       difference of two 'unsigned char' values - including the sign bit -
-       doesn't fit in an 'int'.  */
-    return _GL_CMP (c1, c2);
 
 #endif
 }
index fd0e2c3e7ee077a8fde24e038769d96171f0ad4a..f803dac805c2f5cbdb995782d68367e8d588ddb7 100644 (file)
 char *
 strcasestr (const char *haystack_start, const char *needle_start)
 {
-  const char *haystack = haystack_start;
   const char *needle = needle_start;
-  size_t needle_len; /* Length of NEEDLE.  */
-  size_t haystack_len; /* Known minimum length of HAYSTACK.  */
-  bool ok = true; /* True if NEEDLE is prefix of HAYSTACK.  */
 
   /* Determine length of NEEDLE, and in the process, make sure
      HAYSTACK is at least as long (no point processing all of a long
      NEEDLE if HAYSTACK is too short).  */
-  while (*haystack && *needle)
-    {
-      ok &= (tolower ((unsigned char) *haystack)
-             == tolower ((unsigned char) *needle));
-      haystack++;
-      needle++;
-    }
-  if (*needle)
-    return NULL;
-  if (ok)
-    return (char *) haystack_start;
-  needle_len = needle - needle_start;
-  haystack = haystack_start + 1;
-  haystack_len = needle_len - 1;
+  {
+    const char *haystack = haystack_start;
+    bool ok = true; /* True if NEEDLE is prefix of HAYSTACK.  */
+    while (*haystack && *needle)
+      {
+        ok &= (tolower ((unsigned char) *haystack)
+               == tolower ((unsigned char) *needle));
+        haystack++;
+        needle++;
+      }
+    if (*needle)
+      return NULL;
+    if (ok)
+      return (char *) haystack_start;
+  }
+
+  size_t needle_len = /* Length of NEEDLE.  */
+    needle - needle_start;
+  const char *haystack = haystack_start + 1;
+  size_t haystack_len = /* Known minimum length of HAYSTACK.  */
+    needle_len - 1;
 
   /* Perform the search.  Abstract memory is considered to be an array
      of 'unsigned char' values, not an array of 'char' values.  See
index e6d9c7f8c80ae70e9a42061250950d71cc8a2f87..74ddfe8bec1074b8300734f88e19524b7e527956 100644 (file)
@@ -30,109 +30,111 @@ strchrnul (const char *s, int c_in)
      performance.  */
   typedef unsigned long int longword;
 
-  const unsigned char *char_ptr;
-  const longword *longword_ptr;
-  longword repeated_one;
-  longword repeated_c;
-  unsigned char c;
-
-  c = (unsigned char) c_in;
+  unsigned char c = (unsigned char) c_in;
   if (!c)
     return rawmemchr (s, 0);
 
-  /* Handle the first few bytes by reading one byte at a time.
-     Do this until CHAR_PTR is aligned on a longword boundary.  */
-  for (char_ptr = (const unsigned char *) s;
-       (size_t) char_ptr % sizeof (longword) != 0;
-       ++char_ptr)
-    if (!*char_ptr || *char_ptr == c)
-      return (char *) char_ptr;
+  const longword *longword_ptr;
+
+  {
+    const unsigned char *char_ptr;
+
+    /* Handle the first few bytes by reading one byte at a time.
+       Do this until CHAR_PTR is aligned on a longword boundary.  */
+    for (char_ptr = (const unsigned char *) s;
+         (size_t) char_ptr % sizeof (longword) != 0;
+         ++char_ptr)
+      if (!*char_ptr || *char_ptr == c)
+        return (char *) char_ptr;
 
-  longword_ptr = (const longword *) char_ptr;
+    longword_ptr = (const longword *) char_ptr;
+  }
 
   /* All these elucidatory comments refer to 4-byte longwords,
      but the theory applies equally well to any size longwords.  */
-
-  /* Compute auxiliary longword values:
-     repeated_one is a value which has a 1 in every byte.
-     repeated_c has c in every byte.  */
-  repeated_one = 0x01010101;
-  repeated_c = c | (c << 8);
-  repeated_c |= repeated_c << 16;
-  if (0xffffffffU < (longword) -1)
-    {
-      repeated_one |= repeated_one << 31 << 1;
-      repeated_c |= repeated_c << 31 << 1;
-      if (8 < sizeof (longword))
-        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 longword at a time.  The tricky part is testing if *any of
-     the four* bytes in the longword in question are equal to NUL or
-     c.  We first use an xor with repeated_c.  This reduces the task
-     to testing whether *any of the four* bytes in longword1 or
-     longword2 is zero.
-
-     Let's consider longword1.  We compute tmp =
-       ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
-     That is, we perform the following operations:
-       1. Subtract repeated_one.
-       2. & ~longword1.
-       3. & a mask consisting of 0x80 in every byte.
-     Consider what happens in each byte:
-       - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
-         and step 3 transforms it into 0x80.  A carry can also be propagated
-         to more significant bytes.
-       - If a byte of longword1 is nonzero, let its lowest 1 bit be at
-         position k (0 <= k <= 7); so the lowest k bits are 0.  After step 1,
-         the byte ends in a single bit of value 0 and k bits of value 1.
-         After step 2, the result is just k bits of value 1: 2^k - 1.  After
-         step 3, the result is 0.  And no carry is produced.
-     So, if longword1 has only non-zero bytes, tmp is zero.
-     Whereas if longword1 has a zero byte, call j the position of the least
-     significant zero byte.  Then the result has a zero at positions 0, ...,
-     j-1 and a 0x80 at position j.  We cannot predict the result at the more
-     significant bytes (positions j+1..3), but it does not matter since we
-     already have a non-zero bit at position 8*j+7.
-
-     The test whether any byte in longword1 or longword2 is zero is equivalent
-     to testing whether tmp1 is nonzero or tmp2 is nonzero.  We can combine
-     this into a single test, whether (tmp1 | tmp2) is nonzero.
-
-     This test can read more than one byte beyond the end of a string,
-     depending on where the terminating NUL is encountered.  However,
-     this is considered safe since the initialization phase ensured
-     that the read will be aligned, therefore, the read will not cross
-     page boundaries and will not cause a fault.  */
-
-  while (1)
-    {
-      longword longword1 = *longword_ptr ^ repeated_c;
-      longword longword2 = *longword_ptr;
-
-      if (((((longword1 - repeated_one) & ~longword1)
-            | ((longword2 - repeated_one) & ~longword2))
-           & (repeated_one << 7)) != 0)
-        break;
-      longword_ptr++;
-    }
-
-  char_ptr = (const unsigned char *) longword_ptr;
-
-  /* At this point, we know that one of the sizeof (longword) bytes
-     starting at char_ptr is == 0 or == c.  On little-endian machines,
-     we could determine the first such byte without any further memory
-     accesses, just by looking at the tmp result from the last loop
-     iteration.  But this does not work on big-endian machines.
-     Choose code that works in both cases.  */
-
-  char_ptr = (unsigned char *) longword_ptr;
-  while (*char_ptr && (*char_ptr != c))
-    char_ptr++;
-  return (char *) char_ptr;
+  {
+    /* Compute auxiliary longword values:
+       repeated_one is a value which has a 1 in every byte.
+       repeated_c has c in every byte.  */
+    longword repeated_one = 0x01010101;
+    longword repeated_c = c | (c << 8);
+    repeated_c |= repeated_c << 16;
+    if (0xffffffffU < (longword) -1)
+      {
+        repeated_one |= repeated_one << 31 << 1;
+        repeated_c |= repeated_c << 31 << 1;
+        if (8 < sizeof (longword))
+          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 longword at a time.  The tricky part is testing if *any of
+       the four* bytes in the longword in question are equal to NUL or
+       c.  We first use an xor with repeated_c.  This reduces the task
+       to testing whether *any of the four* bytes in longword1 or
+       longword2 is zero.
+
+       Let's consider longword1.  We compute tmp =
+         ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
+       That is, we perform the following operations:
+         1. Subtract repeated_one.
+         2. & ~longword1.
+         3. & a mask consisting of 0x80 in every byte.
+       Consider what happens in each byte:
+         - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
+           and step 3 transforms it into 0x80.  A carry can also be propagated
+           to more significant bytes.
+         - If a byte of longword1 is nonzero, let its lowest 1 bit be at
+           position k (0 <= k <= 7); so the lowest k bits are 0.  After step 1,
+           the byte ends in a single bit of value 0 and k bits of value 1.
+           After step 2, the result is just k bits of value 1: 2^k - 1.  After
+           step 3, the result is 0.  And no carry is produced.
+       So, if longword1 has only non-zero bytes, tmp is zero.
+       Whereas if longword1 has a zero byte, call j the position of the least
+       significant zero byte.  Then the result has a zero at positions 0, ...,
+       j-1 and a 0x80 at position j.  We cannot predict the result at the more
+       significant bytes (positions j+1..3), but it does not matter since we
+       already have a non-zero bit at position 8*j+7.
+
+       The test whether any byte in longword1 or longword2 is zero is equivalent
+       to testing whether tmp1 is nonzero or tmp2 is nonzero.  We can combine
+       this into a single test, whether (tmp1 | tmp2) is nonzero.
+
+       This test can read more than one byte beyond the end of a string,
+       depending on where the terminating NUL is encountered.  However,
+       this is considered safe since the initialization phase ensured
+       that the read will be aligned, therefore, the read will not cross
+       page boundaries and will not cause a fault.  */
+
+    while (1)
+      {
+        longword longword1 = *longword_ptr ^ repeated_c;
+        longword longword2 = *longword_ptr;
+
+        if (((((longword1 - repeated_one) & ~longword1)
+              | ((longword2 - repeated_one) & ~longword2))
+             & (repeated_one << 7)) != 0)
+          break;
+        longword_ptr++;
+      }
+  }
+
+  {
+    const unsigned char *char_ptr = (const unsigned char *) longword_ptr;
+
+    /* At this point, we know that one of the sizeof (longword) bytes
+       starting at char_ptr is == 0 or == c.  On little-endian machines,
+       we could determine the first such byte without any further memory
+       accesses, just by looking at the tmp result from the last loop
+       iteration.  But this does not work on big-endian machines.
+       Choose code that works in both cases.  */
+
+    while (*char_ptr && (*char_ptr != c))
+      char_ptr++;
+    return (char *) char_ptr;
+  }
 }
index 72572ae433b93e079744c79bd788e5083d143469..060fca1aff798ae3431c72863be435d07c0a6dfb 100644 (file)
@@ -42,7 +42,6 @@ strerror (int n)
 #undef strerror
 {
   static char buf[STACKBUF_LEN];
-  size_t len;
 
   /* Cast away const, due to the historical signature of strerror;
      callers should not be modifying the string.  */
@@ -67,7 +66,7 @@ strerror (int n)
     }
 
   /* Fix STACKBUF_LEN if this ever aborts.  */
-  len = strlen (msg);
+  size_t len = strlen (msg);
   if (sizeof buf <= len)
     abort ();
 
index 8203088a55fb04b2af5f8cda544be8736afb5ab1..14ae2a0c2c04406691f35e1bd48fe9c229e8e399 100644 (file)
@@ -114,8 +114,8 @@ safe_copy (char *buf, size_t buflen, const char *msg)
 int
 strerror_l_r (int errnum, char *buf, size_t buflen, locale_t locale)
 {
-  int ret;
   int saved_errno = errno;
+  int ret;
 
 #if GNULIB_defined_locale_t
 
index 1e6974e3278f057ceeb649e617caa64659e83965..3a22615fb11adcc0c404f1095aa04a5e1f5da924 100644 (file)
@@ -103,10 +103,8 @@ static int
 local_snprintf (char *buf, size_t buflen, const char *format, ...)
 {
   va_list args;
-  int result;
-
   va_start (args, format);
-  result = _vsnprintf (buf, buflen, format, args);
+  int result = _vsnprintf (buf, buflen, format, args);
   va_end (args);
   if (buflen > 0 && (result < 0 || result >= buflen))
     buf[buflen - 1] = '\0';
@@ -222,9 +220,8 @@ strerror_r (int errnum, char *buf, size_t buflen)
     if (!ret && strlen (buf) == buflen - 1)
       {
         char stackbuf[STACKBUF_LEN];
-        size_t len;
         strerror_r (errnum, stackbuf, sizeof stackbuf);
-        len = strlen (stackbuf);
+        size_t len = strlen (stackbuf);
         /* STACKBUF_LEN should have been large enough.  */
         if (len + 1 == sizeof stackbuf)
           abort ();
index 1da4d1d8fe49e542478756a3b2eacfe4d872510c..56d0046938ba13b2b2bb85c24488a73118e43664 100644 (file)
@@ -121,12 +121,8 @@ rpl_strfmon_l (char *s, size_t maxsize, locale_t locale, const char *format, ...
 {
   /* Work around glibc 2.23 bug
      <https://sourceware.org/PR19633>.  */
-  va_list argptr;
-  locale_t orig_locale;
-  directives_t directives;
-  ssize_t result;
 
-  orig_locale = uselocale ((locale_t)0);
+  locale_t orig_locale = uselocale ((locale_t)0);
 
   if (uselocale (locale) == (locale_t)0)
     /* errno is set.  */
@@ -138,6 +134,8 @@ rpl_strfmon_l (char *s, size_t maxsize, locale_t locale, const char *format, ...
      requests 'long double' arguments.  But since 'long double' arguments
      are only supported on glibc, do so only if the original format string
      consumes at least one 'long double' argument.  */
+  ssize_t result;
+  directives_t directives;
   if (fmon_parse (format, &directives) < 0)
     {
       errno = EINVAL;
@@ -145,9 +143,7 @@ rpl_strfmon_l (char *s, size_t maxsize, locale_t locale, const char *format, ...
     }
   else
     {
-      bool use_long_double;
-
-      use_long_double = false;
+      bool use_long_double = false;
       for (unsigned int i = 0; i < directives.count; i++)
         if (directives.dir[i].needs_long_double)
           {
@@ -155,14 +151,13 @@ rpl_strfmon_l (char *s, size_t maxsize, locale_t locale, const char *format, ...
             break;
           }
 
+      va_list argptr;
       va_start (argptr, format);
 
       if (use_long_double)
         {
-          char *ld_format;
-
           /* Allocate room for the modified format string.  */
-          ld_format = (char *) malloc (strlen (format) + directives.count + 1);
+          char *ld_format = (char *) malloc (strlen (format) + directives.count + 1);
           if (ld_format == NULL)
             {
               errno = ENOMEM;
index 291c650b97031f78439b65084481aadb0f349c7d..16e1cb3bc653ec06c6bf90b087a73910e5330270 100644 (file)
@@ -1356,13 +1356,12 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
              an error, or come back to the initial shift state.  */
           {
             mbstate_t mbstate = mbstate_zero;
-            size_t len = 0;
-            size_t fsize;
 
             if (! format_end)
               format_end = f + strlen (f) + 1;
-            fsize = format_end - f;
+            size_t fsize = format_end - f;
 
+            size_t len = 0;
             do
               {
                 size_t bytes = mbrlen (f + len, fsize - len, &mbstate);
@@ -2086,12 +2085,9 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
 
         case L_('s'):           /* GNU extension.  */
           {
-            struct tm ltm;
-            time_t t;
-
-            ltm = *tp;
+            struct tm ltm = *tp;
             ltm.tm_yday = -1;
-            t = mktime_z (tz, &ltm);
+            time_t t = mktime_z (tz, &ltm);
             if (ltm.tm_yday < 0)
               {
                 errno = EOVERFLOW;
@@ -2359,9 +2355,6 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
 
           {
             int diff;
-            int hour_diff;
-            int min_diff;
-            int sec_diff;
 #if HAVE_STRUCT_TM_TM_GMTOFF
             diff = tp->tm_gmtoff;
 #else
@@ -2369,14 +2362,13 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
               diff = 0;
             else
               {
-                struct tm gtm;
-                struct tm ltm;
-                time_t lt;
-
-                ltm = *tp;
+                struct tm ltm = *tp;
                 ltm.tm_wday = -1;
-                lt = mktime_z (tz, &ltm);
-                if (ltm.tm_wday < 0 || ! localtime_rz (0, &lt, &gtm))
+                time_t lt = mktime_z (tz, &ltm);
+                if (ltm.tm_wday < 0)
+                  break;
+                struct tm gtm;
+                if (! localtime_rz (0, &lt, &gtm))
                   break;
                 diff = tm_diff (&ltm, &gtm);
               }
@@ -2390,9 +2382,9 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
                                                  0, tp)
                                    == '-');
               }
-            hour_diff = diff / 60 / 60;
-            min_diff = diff / 60 % 60;
-            sec_diff = diff % 60;
+            int hour_diff = diff / 60 / 60;
+            int min_diff = diff / 60 % 60;
+            int sec_diff = diff % 60;
 
             switch (colons)
               {
index 4a94ed87c2589f89cf0e78813c14dec4544701d3..42b47e399677d3d6957f5ef515a81ebf06e9b9d2 100644 (file)
@@ -44,13 +44,12 @@ mem_cd_iconv (const char *src, size_t srclen, iconv_t cd,
               char **resultp, size_t *lengthp)
 {
 # define tmpbufsize 4096
-  size_t length;
-  char *result;
 
   /* Set to the initial state.  */
   iconv (cd, NULL, NULL, NULL, NULL);
 
   /* Determine the length we need.  */
+  size_t length;
   {
     size_t count = 0;
     /* The alignment is needed when converting e.g. to glibc's WCHAR_T or
@@ -108,6 +107,8 @@ mem_cd_iconv (const char *src, size_t srclen, iconv_t cd,
       *lengthp = 0;
       return 0;
     }
+
+  char *result;
   if (*resultp != NULL && *lengthp >= length)
     result = *resultp;
   else
@@ -199,7 +200,6 @@ str_cd_iconv (const char *src, iconv_t cd)
   char *result = NULL;
   size_t length = 0;
   int retval = mem_cd_iconv (src, strlen (src), cd, &result, &length);
-  char *final_result;
 
   if (retval < 0)
     {
@@ -209,7 +209,7 @@ str_cd_iconv (const char *src, iconv_t cd)
     }
 
   /* Add the terminating NUL byte.  */
-  final_result =
+  char *final_result =
     (result != NULL ? realloc (result, length + 1) : malloc (length + 1));
   if (final_result == NULL)
     {
@@ -226,16 +226,12 @@ str_cd_iconv (const char *src, iconv_t cd)
      iconv() returns for an E2BIG reason, when the output size guess is too
      small.  Therefore it can only be used when we don't need the number of
      irreversible conversions performed.  */
-  char *result;
-  size_t result_size;
-  size_t length;
-  const char *inptr = src;
   size_t inbytes_remaining = strlen (src);
 
   /* Make a guess for the worst-case output size, in order to avoid a
      realloc.  It's OK if the guess is wrong as long as it is not zero and
      doesn't lead to an integer overflow.  */
-  result_size = inbytes_remaining;
+  size_t result_size = inbytes_remaining;
   {
     size_t approx_sqrt_SIZE_MAX = SIZE_MAX >> (sizeof (size_t) * CHAR_BIT / 2);
     if (result_size <= approx_sqrt_SIZE_MAX / MB_LEN_MAX)
@@ -243,7 +239,7 @@ str_cd_iconv (const char *src, iconv_t cd)
   }
   result_size += 1; /* for the terminating NUL */
 
-  result = (char *) malloc (result_size);
+  char *result = (char *) malloc (result_size);
   if (result == NULL)
     {
       errno = ENOMEM;
@@ -254,6 +250,8 @@ str_cd_iconv (const char *src, iconv_t cd)
   iconv (cd, NULL, NULL, NULL, NULL);
 
   /* Do the conversion.  */
+  size_t length;
+  const char *inptr = src;
   {
     char *outptr = result;
     size_t outbytes_remaining = result_size - 1;
@@ -374,14 +372,11 @@ str_iconv (const char *src, const char *from_codeset, const char *to_codeset)
   else
     {
 #if HAVE_ICONV
-      iconv_t cd;
-      char *result;
-
-      cd = iconv_open (to_codeset, from_codeset);
+      iconv_t cd = iconv_open (to_codeset, from_codeset);
       if (cd == (iconv_t) -1)
         return NULL;
 
-      result = str_cd_iconv (src, cd);
+      char *result = str_cd_iconv (src, cd);
 
       if (result == NULL)
         {
index 3fac3f4006aef63d68d123110baf1db525d975ce..88577fa77616c3320e4bf54ec7b302d7d6642e32 100644 (file)
 int
 iconveh_open (const char *to_codeset, const char *from_codeset, iconveh_t *cdp)
 {
-  iconv_t cd;
-  iconv_t cd1;
-  iconv_t cd2;
-
-  cd = iconv_open (to_codeset, from_codeset);
+  iconv_t cd = iconv_open (to_codeset, from_codeset);
 
+  iconv_t cd1;
   if (STRCASEEQ (from_codeset, "UTF-8", 'U','T','F','-','8',0,0,0,0))
     cd1 = (iconv_t)(-1);
   else
@@ -67,6 +64,7 @@ iconveh_open (const char *to_codeset, const char *from_codeset, iconveh_t *cdp)
         }
     }
 
+  iconv_t cd2;
   if (STRCASEEQ (to_codeset, "UTF-8", 'U','T','F','-','8',0,0,0,0)
 # if (((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2) \
       && !defined __UCLIBC__) \
@@ -276,16 +274,11 @@ utf8conv_carefully (bool one_character_only,
   size_t insize = *inbytesleft;
   char *outptr = *outbuf;
   size_t outsize = *outbytesleft;
-  size_t res;
-
-  res = 0;
+  size_t res = 0;
   do
     {
       ucs4_t uc;
-      int n;
-      int m;
-
-      n = u8_mbtoucr (&uc, (const uint8_t *) inptr, insize);
+      int n = u8_mbtoucr (&uc, (const uint8_t *) inptr, insize);
       if (n < 0)
         {
           errno = (n == -2 ? EINVAL : EILSEQ);
@@ -303,7 +296,7 @@ utf8conv_carefully (bool one_character_only,
           *incremented = false;
           break;
         }
-      m = u8_uctomb ((uint8_t *) outptr, uc, outsize);
+      int m = u8_uctomb ((uint8_t *) outptr, uc, outsize);
       if (m == -2)
         {
           errno = E2BIG;
@@ -352,11 +345,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
 # define tmpbuf tmp.buf
 
   char *initial_result;
-  char *result;
   size_t allocated;
-  size_t length;
-  size_t last_length = (size_t)(-1); /* only needed if offsets != NULL */
-
   if (*resultp != NULL && *lengthp >= sizeof (tmpbuf))
     {
       initial_result = *resultp;
@@ -367,12 +356,14 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
       initial_result = tmpbuf;
       allocated = sizeof (tmpbuf);
     }
-  result = initial_result;
+
+  char *result = initial_result;
 
   /* Test whether a direct conversion is possible at all.  */
   if (cd == (iconv_t)(-1))
     goto indirectly;
 
+  size_t last_length = (size_t)(-1); /* only needed if offsets != NULL */
   if (offsets != NULL)
     {
       for (size_t i = 0; i < srclen; i++)
@@ -380,25 +371,24 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
 
       last_length = (size_t)(-1);
     }
-  length = 0;
+  size_t length = 0;
 
   /* First, try a direct conversion, and see whether a conversion error
      occurs at all.  */
   {
-    const char *inptr = src;
-    size_t insize = srclen;
-
     /* Set to the initial state.  */
     iconv (cd, NULL, NULL, NULL, NULL);
 
+    const char *inptr = src;
+    size_t insize = srclen;
+
     while (insize > 0)
       {
         char *outptr = result + length;
         size_t outsize = allocated - extra_alloc - length;
+
         bool incremented;
         size_t res;
-        bool grow;
-
         if (offsets != NULL)
           {
             if (length != last_length) /* ensure that offset[] be increasing */
@@ -424,7 +414,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
                                  &incremented);
 
         length = outptr - result;
-        grow = (length + extra_alloc > allocated / 2);
+        bool grow = (length + extra_alloc > allocated / 2);
         if (res == (size_t)(-1))
           {
             if (errno == E2BIG)
@@ -442,13 +432,12 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
                       (handler == iconveh_replacement_character ? 3 : 1);
                     if (length + extra_need + extra_alloc > allocated)
                       {
-                        char *memory;
-
                         allocated = 2 * allocated;
                         if (length + extra_need + extra_alloc > allocated)
                           allocated = 2 * allocated;
                         if (length + extra_need + extra_alloc > allocated)
                           abort ();
+                        char *memory;
                         if (result == initial_result)
                           memory = (char *) malloc (allocated);
                         else
@@ -502,9 +491,8 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
           break;
         if (grow)
           {
-            char *memory;
-
             allocated = 2 * allocated;
+            char *memory;
             if (result == initial_result)
               memory = (char *) malloc (allocated);
             else
@@ -532,17 +520,15 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
     {
       char *outptr = result + length;
       size_t outsize = allocated - extra_alloc - length;
-      size_t res;
-
-      res = iconv (cd, NULL, NULL, &outptr, &outsize);
+      size_t res = iconv (cd, NULL, NULL, &outptr, &outsize);
       length = outptr - result;
       if (res == (size_t)(-1))
         {
           if (errno == E2BIG)
             {
-              char *memory;
 
               allocated = 2 * allocated;
+              char *memory;
               if (result == initial_result)
                 memory = (char *) malloc (allocated);
               else
@@ -585,6 +571,12 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
     }
   length = 0;
   {
+    /* Set to the initial state.  */
+    if (cd1 != (iconv_t)(-1))
+      iconv (cd1, NULL, NULL, NULL, NULL);
+    if (cd2 != (iconv_t)(-1))
+      iconv (cd2, NULL, NULL, NULL, NULL);
+
     const bool slowly = (offsets != NULL || handler == iconveh_error);
 # define utf8bufsize 4096 /* may also be smaller or larger than tmpbufsize */
     char utf8buf[utf8bufsize + 3];
@@ -594,21 +586,14 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
     bool do_final_flush1 = true;
     bool do_final_flush2 = true;
 
-    /* Set to the initial state.  */
-    if (cd1 != (iconv_t)(-1))
-      iconv (cd1, NULL, NULL, NULL, NULL);
-    if (cd2 != (iconv_t)(-1))
-      iconv (cd2, NULL, NULL, NULL, NULL);
-
     while (in1size > 0 || do_final_flush1 || utf8len > 0 || do_final_flush2)
       {
         char *out1ptr = utf8buf + utf8len;
         size_t out1size = utf8bufsize - utf8len;
-        bool incremented1;
-        size_t res1;
-        int errno1;
 
         /* Conversion step 1: from FROM_CODESET to UTF-8.  */
+        bool incremented1;
+        size_t res1;
         if (in1size > 0)
           {
             if (offsets != NULL
@@ -691,7 +676,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
               *out1ptr++ = '?';
             res1 = 0;
           }
-        errno1 = errno;
+        int errno1 = errno;
         utf8len = out1ptr - utf8buf;
 
         if (offsets != NULL
@@ -708,10 +693,9 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
               {
                 char *out2ptr = result + length;
                 size_t out2size = allocated - extra_alloc - length;
+
                 bool incremented2;
                 size_t res2;
-                bool grow;
-
                 if (in2size > 0)
                   {
                     if (cd2 != (iconv_t)(-1))
@@ -744,7 +728,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
                   }
 
                 length = out2ptr - result;
-                grow = (length + extra_alloc > allocated / 2);
+                bool grow = (length + extra_alloc > allocated / 2);
                 if (res2 == (size_t)(-1))
                   {
                     if (errno == E2BIG)
@@ -756,12 +740,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
                         /* Error handling can produce up to 10 bytes of UTF-8
                            output.  But TO_CODESET may be UCS-2, UTF-16 or
                            UCS-4, so use CD2 here as well.  */
-                        char scratchbuf[10];
-                        size_t scratchlen;
                         ucs4_t uc;
-                        const char *inptr;
-                        size_t insize;
-                        size_t res;
 
                         if (incremented2)
                           {
@@ -781,6 +760,8 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
                             in2size -= n;
                           }
 
+                        char scratchbuf[10];
+                        size_t scratchlen;
                         if (handler == iconveh_escape_sequence)
                           {
                             static char const hex[16] _GL_ATTRIBUTE_NONSTRING =
@@ -816,8 +797,9 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
                             scratchlen = 1;
                           }
 
-                        inptr = scratchbuf;
-                        insize = scratchlen;
+                        const char *inptr = scratchbuf;
+                        size_t insize = scratchlen;
+                        size_t res;
                         if (cd2 != (iconv_t)(-1))
                           {
                             char *out2ptr_try = out2ptr;
@@ -877,11 +859,10 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
                         length = out2ptr - result;
                         if (res == (size_t)(-1) && errno == E2BIG)
                           {
-                            char *memory;
-
                             allocated = 2 * allocated;
                             if (length + 1 + extra_alloc > allocated)
                               abort ();
+                            char *memory;
                             if (result == initial_result)
                               memory = (char *) malloc (allocated);
                             else
@@ -953,9 +934,8 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
                   break;
                 if (grow)
                   {
-                    char *memory;
-
                     allocated = 2 * allocated;
+                    char *memory;
                     if (result == initial_result)
                       memory = (char *) malloc (allocated);
                     else
@@ -1005,9 +985,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
         result = *resultp;
       else
         {
-          char *memory;
-
-          memory = (char *) malloc (memsize > 0 ? memsize : 1);
+          char *memory = (char *) malloc (memsize > 0 ? memsize : 1);
           if (memory != NULL)
             result = memory;
           else
@@ -1022,9 +1000,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen,
     {
       /* Shrink the allocated memory if possible.  */
       size_t memsize = length + extra_alloc;
-      char *memory;
-
-      memory = (char *) realloc (result, memsize > 0 ? memsize : 1);
+      char *memory = (char *) realloc (result, memsize > 0 ? memsize : 1);
       if (memory != NULL)
         result = memory;
     }
@@ -1112,17 +1088,13 @@ mem_iconveh (const char *src, size_t srclen,
     {
 #if HAVE_ICONV
       iconveh_t cd;
-      char *result;
-      size_t length;
-      int retval;
-
       if (iconveh_open (to_codeset, from_codeset, &cd) < 0)
         return -1;
 
-      result = *resultp;
-      length = *lengthp;
-      retval = mem_cd_iconveh (src, srclen, &cd, handler, offsets,
-                               &result, &length);
+      char *result = *resultp;
+      size_t length = *lengthp;
+      int retval = mem_cd_iconveh (src, srclen, &cd, handler, offsets,
+                                   &result, &length);
 
       if (retval < 0)
         {
@@ -1172,12 +1144,10 @@ str_iconveh (const char *src,
     {
 #if HAVE_ICONV
       iconveh_t cd;
-      char *result;
-
       if (iconveh_open (to_codeset, from_codeset, &cd) < 0)
         return NULL;
 
-      result = str_cd_iconveh (src, &cd, handler);
+      char *result = str_cd_iconveh (src, &cd, handler);
 
       if (result == NULL)
         {
index f3e41cfc6ae1bc313041acb9b07e44dfc1845ffa..cc93ec2c39488067ebd00ff66d780a890303e4a4 100644 (file)
@@ -84,11 +84,6 @@ int
 uniconv_register_autodetect (const char *name,
                              const char * const *try_in_order)
 {
-  size_t namelen;
-  size_t listlen;
-  size_t memneed;
-  size_t i;
-
   /* The TRY_IN_ORDER list must not be empty.  */
   if (try_in_order[0] == NULL)
     {
@@ -98,11 +93,15 @@ uniconv_register_autodetect (const char *name,
 
   /* We must deep-copy NAME and TRY_IN_ORDER, because they may be allocated
      with dynamic extent.  */
-  namelen = strlen (name) + 1;
-  memneed = sizeof (struct autodetect_alias) + namelen + sizeof (char *);
-  for (i = 0; try_in_order[i] != NULL; i++)
-    memneed += sizeof (char *) + strlen (try_in_order[i]) + 1;
-  listlen = i;
+  size_t namelen = strlen (name) + 1;
+  size_t memneed = sizeof (struct autodetect_alias) + namelen + sizeof (char *);
+  size_t listlen;
+  {
+    size_t i;
+    for (i = 0; try_in_order[i] != NULL; i++)
+      memneed += sizeof (char *) + strlen (try_in_order[i]) + 1;
+    listlen = i;
+  }
 
   void *memory = malloc (memneed);
   if (memory != NULL)
@@ -116,14 +115,17 @@ uniconv_register_autodetect (const char *name,
       char *new_name = memcpy (memory, name, namelen);
       memory = new_name + namelen;
 
-      for (i = 0; i < listlen; i++)
-        {
-          size_t len = strlen (try_in_order[i]) + 1;
-          char *copy = memcpy (memory, try_in_order[i], len);
-          new_try_in_order[i] = copy;
-          memory = copy + len;
-        }
-      new_try_in_order[i] = NULL;
+      {
+        size_t i;
+        for (i = 0; i < listlen; i++)
+          {
+            size_t len = strlen (try_in_order[i]) + 1;
+            char *copy = memcpy (memory, try_in_order[i], len);
+            new_try_in_order[i] = copy;
+            memory = copy + len;
+          }
+        new_try_in_order[i] = NULL;
+      }
 
       /* Now insert the new alias.  */
       new_alias->name = new_name;
@@ -162,12 +164,10 @@ mem_iconveha_notranslit (const char *src, size_t srclen,
            alias = alias->next)
         if (streq (from_codeset, alias->name))
           {
-            const char * const *encodings;
-
             if (handler != iconveh_error)
               {
                 /* First try all encodings without any forgiving.  */
-                encodings = alias->encodings_to_try;
+                const char * const *encodings = alias->encodings_to_try;
                 do
                   {
                     retval = mem_iconveha_notranslit (src, srclen,
@@ -181,7 +181,7 @@ mem_iconveha_notranslit (const char *src, size_t srclen,
                 while (*encodings != NULL);
               }
 
-            encodings = alias->encodings_to_try;
+            const char * const *encodings = alias->encodings_to_try;
             do
               {
                 retval = mem_iconveha_notranslit (src, srclen,
@@ -227,7 +227,6 @@ mem_iconveha (const char *src, size_t srclen,
     || defined ICONV_SET_TRANSLITERATE
   if (transliterate)
     {
-      int retval;
       size_t len = strlen (to_codeset);
       char *to_codeset_suffixed = (char *) malloca (len + 10 + 1);
       if (to_codeset_suffixed == NULL)
@@ -238,9 +237,9 @@ mem_iconveha (const char *src, size_t srclen,
       memcpy (to_codeset_suffixed, to_codeset, len);
       memcpy (to_codeset_suffixed + len, "//TRANSLIT", 10 + 1);
 
-      retval = mem_iconveha_notranslit (src, srclen,
-                                        from_codeset, to_codeset_suffixed,
-                                        handler, offsets, resultp, lengthp);
+      int retval = mem_iconveha_notranslit (src, srclen,
+                                            from_codeset, to_codeset_suffixed,
+                                            handler, offsets, resultp, lengthp);
 
       freea (to_codeset_suffixed);
 
@@ -272,12 +271,10 @@ str_iconveha_notranslit (const char *src,
            alias = alias->next)
         if (streq (from_codeset, alias->name))
           {
-            const char * const *encodings;
-
             if (handler != iconveh_error)
               {
                 /* First try all encodings without any forgiving.  */
-                encodings = alias->encodings_to_try;
+                const char * const *encodings = alias->encodings_to_try;
                 do
                   {
                     result = str_iconveha_notranslit (src,
@@ -290,7 +287,7 @@ str_iconveha_notranslit (const char *src,
                 while (*encodings != NULL);
               }
 
-            encodings = alias->encodings_to_try;
+            const char * const *encodings = alias->encodings_to_try;
             do
               {
                 result = str_iconveha_notranslit (src,
@@ -335,7 +332,6 @@ str_iconveha (const char *src,
     || defined ICONV_SET_TRANSLITERATE
   if (transliterate)
     {
-      char *result;
       size_t len = strlen (to_codeset);
       char *to_codeset_suffixed = (char *) malloca (len + 10 + 1);
       if (to_codeset_suffixed == NULL)
@@ -346,8 +342,9 @@ str_iconveha (const char *src,
       memcpy (to_codeset_suffixed, to_codeset, len);
       memcpy (to_codeset_suffixed + len, "//TRANSLIT", 10 + 1);
 
-      result = str_iconveha_notranslit (src, from_codeset, to_codeset_suffixed,
-                                        handler);
+      char *result =
+        str_iconveha_notranslit (src, from_codeset, to_codeset_suffixed,
+                                 handler);
 
       freea (to_codeset_suffixed);
 
index ef9ad122e8c60caabfbd20b254c672c8eb586873..8e467678a2dc0a82993626f9171d2bb0cd2fbfb5 100644 (file)
@@ -34,8 +34,6 @@ int
 sb_appendvf (struct string_buffer *buffer, const char *formatstring,
              va_list list)
 {
-  va_list list_copy;
-
   /* Make a bit of room, so that the probability that the first vsnzprintf()
      call succeeds is high.  */
   size_t room = buffer->allocated - buffer->length;
@@ -50,6 +48,7 @@ sb_appendvf (struct string_buffer *buffer, const char *formatstring,
       room = buffer->allocated - buffer->length;
     }
 
+  va_list list_copy;
   va_copy (list_copy, list);
 
   /* First vsnzprintf() call.  */
@@ -121,8 +120,6 @@ sb_appendvf (struct string_buffer *buffer, const char *formatstring,
 int
 sb_appendf (struct string_buffer *buffer, const char *formatstring, ...)
 {
-  va_list args;
-
   /* Make a bit of room, so that the probability that the first vsnzprintf()
      call succeeds is high.  */
   size_t room = buffer->allocated - buffer->length;
@@ -137,6 +134,7 @@ sb_appendf (struct string_buffer *buffer, const char *formatstring, ...)
       room = buffer->allocated - buffer->length;
     }
 
+  va_list args;
   va_start (args, formatstring);
 
   /* First vsnzprintf() call.  */
index adcdc54bc37a9686c98cd799ad6615a395d1d4a5..4cf3f4746eee61e9cba948ad1c21927ceb7875f7 100644 (file)
@@ -36,7 +36,6 @@ int
 sbr_prependvf (struct string_buffer_reversed *buffer, const char *formatstring,
                va_list list)
 {
-  va_list list_copy;
 
   /* Make a bit of room, so that the probability that the first vsnzprintf()
      call succeeds is high.  */
@@ -52,6 +51,7 @@ sbr_prependvf (struct string_buffer_reversed *buffer, const char *formatstring,
       room = buffer->allocated - buffer->length;
     }
 
+  va_list list_copy;
   va_copy (list_copy, list);
 
   /* First vsnzprintf() call.  */
@@ -128,7 +128,6 @@ int
 sbr_prependf (struct string_buffer_reversed *buffer, const char *formatstring,
               ...)
 {
-  va_list args;
 
   /* Make a bit of room, so that the probability that the first vsnzprintf()
      call succeeds is high.  */
@@ -144,6 +143,7 @@ sbr_prependf (struct string_buffer_reversed *buffer, const char *formatstring,
       room = buffer->allocated - buffer->length;
     }
 
+  va_list args;
   va_start (args, formatstring);
 
   /* First vsnzprintf() call.  */
index 6ac8d58ea9017c6822ed6905614b3ea7101b603f..5dabf67f0d66112f805a7492700de70f4b297801 100644 (file)
@@ -222,12 +222,12 @@ _sd_fwrite (FILE *fp, idx_t s_nbytes, const char *s_data)
 int
 sd_new (rw_string_desc_t *resultp, idx_t n)
 {
-  rw_string_desc_t result;
-
   if (!(n >= 0))
     /* Invalid argument.  */
     abort ();
 
+  rw_string_desc_t result;
+
   result._nbytes = n;
   if (n == 0)
     result._data = NULL;
index d5b07bca8207baddf31843a3a8ddba23bf4cf8f6..766b082d4ed67d081757db4f6257396628ad5b7d 100644 (file)
@@ -31,15 +31,13 @@ bool
 strip_trailing_slashes (char *file)
 {
   char *base = last_component (file);
-  char *base_lim;
-  bool had_slash;
 
   /* last_component returns "" for file system roots, but we need to turn
      "///" into "/".  */
   if (! *base)
     base = file;
-  base_lim = base + base_len (base);
-  had_slash = (*base_lim != '\0');
+  char *base_lim = base + base_len (base);
+  bool had_slash = (*base_lim != '\0');
   *base_lim = '\0';
   return had_slash;
 }
index 7d7c5b7f04a7de59e805721fa80363f1bdf7d1f8..d38804caa5123c8524dc8234ef4e762d586a51bd 100644 (file)
@@ -32,29 +32,24 @@ strncasecmp (const char *s1, const char *s2, size_t n)
 {
   register const unsigned char *p1 = (const unsigned char *) s1;
   register const unsigned char *p2 = (const unsigned char *) s2;
-  unsigned char c1, c2;
 
   if (p1 == p2 || n == 0)
     return 0;
 
-  do
+  for (;; p1++, p2++)
     {
-      c1 = tolower (*p1);
-      c2 = tolower (*p2);
-
-      if (--n == 0 || c1 == '\0')
-        break;
-
-      ++p1;
-      ++p2;
+      unsigned char c1 = tolower (*p1);
+      unsigned char c2 = tolower (*p2);
+
+      if (--n == 0 || c1 == '\0' || c1 != c2)
+        {
+          if (UCHAR_MAX <= INT_MAX)
+            return c1 - c2;
+          else
+            /* On machines where 'char' and 'int' are types of the same size,
+               the difference of two 'unsigned char' values - including the
+               sign bit - doesn't fit in an 'int'.  */
+            return _GL_CMP (c1, c2);
+        }
     }
-  while (c1 == c2);
-
-  if (UCHAR_MAX <= INT_MAX)
-    return c1 - c2;
-  else
-    /* On machines where 'char' and 'int' are types of the same size, the
-       difference of two 'unsigned char' values - including the sign bit -
-       doesn't fit in an 'int'.  */
-    return _GL_CMP (c1, c2);
 }
index 9981b90fd768f4bca01d1ff44b96796fe436aaa5..7b2baafbc9eb30ea5e401a787a933e6dd169452d 100644 (file)
@@ -42,11 +42,10 @@ strncasecmp_l (const char *s1, const char *s2, size_t n, locale_t locale)
 # else
   /* Implementation for the global locale.  */
   {
-    int ret;
 #  if HAVE_WORKING_USELOCALE
     locale_t saved_locale = uselocale (LC_GLOBAL_LOCALE);
 #  endif
-    ret = strncasecmp (s1, s2, n);
+    int ret = strncasecmp (s1, s2, n);
 #  if HAVE_WORKING_USELOCALE
     uselocale (saved_locale);
 #  endif
@@ -56,31 +55,25 @@ strncasecmp_l (const char *s1, const char *s2, size_t n, locale_t locale)
 
 #else
 
-  unsigned char c1, c2;
-
   if (s1 == s2 || n == 0)
     return 0;
 
-  do
+  for (;; s1++, s2++)
     {
-      c1 = tolower_l ((unsigned char) *s1, locale);
-      c2 = tolower_l ((unsigned char) *s2, locale);
-
-      if (--n == 0 || c1 == '\0')
-        break;
-
-      ++s1;
-      ++s2;
+      unsigned char c1 = tolower_l ((unsigned char) *s1, locale);
+      unsigned char c2 = tolower_l ((unsigned char) *s2, locale);
+
+      if (--n == 0 || c1 == '\0' || c1 != c2)
+        {
+          if (UCHAR_MAX <= INT_MAX)
+            return c1 - c2;
+          else
+            /* On machines where 'char' and 'int' are types of the same size,
+               the difference of two 'unsigned char' values - including the
+               sign bit - doesn't fit in an 'int'.  */
+            return _GL_CMP (c1, c2);
+        }
     }
-  while (c1 == c2);
-
-  if (UCHAR_MAX <= INT_MAX)
-    return c1 - c2;
-  else
-    /* On machines where 'char' and 'int' are types of the same size, the
-       difference of two 'unsigned char' values - including the sign bit -
-       doesn't fit in an 'int'.  */
-    return _GL_CMP (c1, c2);
 
 #endif
 }
index 89388c11bc72a9ab1f6f000221dc22d6f164a3a0..d9bf3a9ed7ab2feffdd11dd176a12d48d6838532 100644 (file)
@@ -233,7 +233,6 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tm,
   struct locale_data *const current = locale->__locales[LC_TIME];
 #endif
 
-  int cnt;
   size_t val;
   int have_I, is_pm;
   int century, want_century;
@@ -296,82 +295,88 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tm,
         case 'a':
         case 'A':
           /* Match day of week.  */
-          for (cnt = 0; cnt < 7; ++cnt)
-            {
+          {
+            int cnt;
+            for (cnt = 0; cnt < 7; ++cnt)
+              {
 #ifdef _NL_CURRENT
-              if (*decided !=raw)
-                {
-                  if (match_string (_NL_CURRENT (LC_TIME, DAY_1 + cnt), rp))
-                    {
-                      if (*decided == not
-                          && strcmp (_NL_CURRENT (LC_TIME, DAY_1 + cnt),
-                                     weekday_name[cnt]))
-                        *decided = loc;
-                      break;
-                    }
-                  if (match_string (_NL_CURRENT (LC_TIME, ABDAY_1 + cnt), rp))
-                    {
-                      if (*decided == not
-                          && strcmp (_NL_CURRENT (LC_TIME, ABDAY_1 + cnt),
-                                     ab_weekday_name[cnt]))
-                        *decided = loc;
-                      break;
-                    }
-                }
+                if (*decided !=raw)
+                  {
+                    if (match_string (_NL_CURRENT (LC_TIME, DAY_1 + cnt), rp))
+                      {
+                        if (*decided == not
+                            && strcmp (_NL_CURRENT (LC_TIME, DAY_1 + cnt),
+                                       weekday_name[cnt]))
+                          *decided = loc;
+                        break;
+                      }
+                    if (match_string (_NL_CURRENT (LC_TIME, ABDAY_1 + cnt), rp))
+                      {
+                        if (*decided == not
+                            && strcmp (_NL_CURRENT (LC_TIME, ABDAY_1 + cnt),
+                                       ab_weekday_name[cnt]))
+                          *decided = loc;
+                        break;
+                      }
+                  }
 #endif
-              if (*decided != loc
-                  && (match_string (weekday_name[cnt], rp)
-                      || match_string (ab_weekday_name[cnt], rp)))
-                {
-                  *decided = raw;
-                  break;
-                }
-            }
-          if (cnt == 7)
-            /* Does not match a weekday name.  */
-            return NULL;
-          tm->tm_wday = cnt;
-          have_wday = 1;
+                if (*decided != loc
+                    && (match_string (weekday_name[cnt], rp)
+                        || match_string (ab_weekday_name[cnt], rp)))
+                  {
+                    *decided = raw;
+                    break;
+                  }
+              }
+            if (cnt == 7)
+              /* Does not match a weekday name.  */
+              return NULL;
+            tm->tm_wday = cnt;
+            have_wday = 1;
+          }
           break;
         case 'b':
         case 'B':
         case 'h':
           /* Match month name.  */
-          for (cnt = 0; cnt < 12; ++cnt)
-            {
+          {
+            int cnt;
+            for (cnt = 0; cnt < 12; ++cnt)
+              {
 #ifdef _NL_CURRENT
-              if (*decided !=raw)
-                {
-                  if (match_string (_NL_CURRENT (LC_TIME, MON_1 + cnt), rp))
-                    {
-                      if (*decided == not
-                          && strcmp (_NL_CURRENT (LC_TIME, MON_1 + cnt),
-                                     month_name[cnt]))
-                        *decided = loc;
-                      break;
-                    }
-                  if (match_string (_NL_CURRENT (LC_TIME, ABMON_1 + cnt), rp))
-                    {
-                      if (*decided == not
-                          && strcmp (_NL_CURRENT (LC_TIME, ABMON_1 + cnt),
-                                     ab_month_name[cnt]))
-                        *decided = loc;
-                      break;
-                    }
-                }
+                if (*decided !=raw)
+                  {
+                    if (match_string (_NL_CURRENT (LC_TIME, MON_1 + cnt), rp))
+                      {
+                        if (*decided == not
+                            && strcmp (_NL_CURRENT (LC_TIME, MON_1 + cnt),
+                                       month_name[cnt]))
+                          *decided = loc;
+                        break;
+                      }
+                    if (match_string (_NL_CURRENT (LC_TIME, ABMON_1 + cnt), rp))
+                      {
+                        if (*decided == not
+                            && strcmp (_NL_CURRENT (LC_TIME, ABMON_1 + cnt),
+                                       ab_month_name[cnt]))
+                          *decided = loc;
+                        break;
+                      }
+                  }
 #endif
-              if (match_string (month_name[cnt], rp)
-                  || match_string (ab_month_name[cnt], rp))
-                {
-                  *decided = raw;
-                  break;
-                }
-            }
-          if (cnt == 12)
-            /* Does not match a month name.  */
-            return NULL;
-          tm->tm_mon = cnt;
-          want_xday = 1;
+                if (match_string (month_name[cnt], rp)
+                    || match_string (ab_month_name[cnt], rp))
+                  {
+                    *decided = raw;
+                    break;
+                  }
+              }
+            if (cnt == 12)
+              /* Does not match a month name.  */
+              return NULL;
+            tm->tm_mon = cnt;
+            want_xday = 1;
+          }
           break;
         case 'c':
           /* Match locale's date and time format.  */
index 5a489d11d0cfc8c4e46900f45c7cc4f4ace227dd..36d3a1b89990700a13b7dd790e9b7b936257b4b8 100644 (file)
@@ -26,7 +26,6 @@ char *
 strsep (char **stringp, const char *delim)
 {
   char *start = *stringp;
-  char *ptr;
 
   if (start == NULL)
     return NULL;
@@ -38,12 +37,14 @@ strsep (char **stringp, const char *delim)
       return start;
     }
 
+  char *ptr;
   /* Optimize the case of one delimiter.  */
   if (delim[1] == '\0')
     ptr = strchr (start, delim[0]);
   else
     /* The general case.  */
     ptr = strpbrk (start, delim);
+
   if (ptr == NULL)
     {
       *stringp = NULL;
index 86653b3ac04294bfe178f632c728129ce1346349..88ed1de80da29e7c06ead96a481b1115e87dd057 100644 (file)
@@ -94,12 +94,12 @@ static char *getbuffer (void);
 char *
 strsignal (int signum)
 {
-  const char *desc;
   __libc_once_define (static, once);
 
   /* If we have not yet initialized the buffer do it now.  */
   __libc_once (once, init);
 
+  const char *desc;
   if (
 #ifdef SIGRTMIN
       (signum >= SIGRTMIN && signum <= SIGRTMAX) ||
index d6953f906caf6238465f78a4cbabd2dd6935abcf..61fa07d927e0024bb1c32b37779a6ac271c44e40 100644 (file)
 char *
 strstr (const char *haystack_start, const char *needle_start)
 {
-  const char *haystack = haystack_start;
   const char *needle = needle_start;
-  size_t needle_len; /* Length of NEEDLE.  */
-  size_t haystack_len; /* Known minimum length of HAYSTACK.  */
-  bool ok = true; /* True if NEEDLE is prefix of HAYSTACK.  */
 
   /* Determine length of NEEDLE, and in the process, make sure
      HAYSTACK is at least as long (no point processing all of a long
      NEEDLE if HAYSTACK is too short).  */
-  while (*haystack && *needle)
-    ok &= *haystack++ == *needle++;
-  if (*needle)
-    return NULL;
-  if (ok)
-    return (char *) haystack_start;
+  {
+    const char *haystack = haystack_start;
+    bool ok = true; /* True if NEEDLE is prefix of HAYSTACK.  */
+    while (*haystack && *needle)
+      ok &= *haystack++ == *needle++;
+    if (*needle)
+      return NULL;
+    if (ok)
+      return (char *) haystack_start;
+  }
 
   /* Reduce the size of haystack using strchr, since it has a smaller
      linear coefficient than the Two-Way algorithm.  */
-  needle_len = needle - needle_start;
-  haystack = strchr (haystack_start + 1, *needle_start);
+  size_t needle_len = /* Length of NEEDLE.  */
+    needle - needle_start;
+  const char *haystack = strchr (haystack_start + 1, *needle_start);
   if (!haystack || __builtin_expect (needle_len == 1, 0))
     return (char *) haystack;
   needle -= needle_len;
-  haystack_len = (haystack > haystack_start + needle_len ? 1
-                  : needle_len + haystack_start - haystack);
+  size_t haystack_len = /* Known minimum length of HAYSTACK.  */
+    (haystack > haystack_start + needle_len ? 1
+     : needle_len + haystack_start - haystack);
 
   /* Perform the search.  Abstract memory is considered to be an array
      of 'unsigned char' values, not an array of 'char' values.  See
index 24593e5b9ebf292062fd3649787308f7ce4072ae..a6453a6dd87a9853be314902a297da8785265275 100644 (file)
@@ -230,15 +230,10 @@ parse_number (const char *nptr,
               char **endptr)
 {
   const char *s = nptr;
-  const char *digits_start;
-  const char *digits_end;
-  const char *radixchar_ptr;
-  long int exponent;
-  DOUBLE num;
 
   /* First, determine the start and end of the digit sequence.  */
-  digits_start = s;
-  radixchar_ptr = NULL;
+  const char *digits_start = s;
+  const char *radixchar_ptr = NULL;
   for (;; ++s)
     {
       if (base == 16 ? c_isxdigit (*s) : c_isdigit (*s))
@@ -252,10 +247,11 @@ parse_number (const char *nptr,
         /* Any other character terminates the digit sequence.  */
         break;
     }
-  digits_end = s;
+  const char *digits_end = s;
   /* Now radixchar_ptr == NULL or
      digits_start <= radixchar_ptr < digits_end.  */
 
+  long int exponent;
   if (false)
     { /* Unoptimized.  */
       exponent =
@@ -282,13 +278,12 @@ parse_number (const char *nptr,
     }
 
   /* Then, convert the digit sequence to a number.  */
+  DOUBLE num;
   {
     num = 0;
     for (const char *dp = digits_start; dp < digits_end; dp++)
       if (dp != radixchar_ptr)
         {
-          int digit;
-
           /* Make sure that multiplication by BASE will not overflow.  */
           if (!(num <= MAX / base))
             {
@@ -304,6 +299,7 @@ parse_number (const char *nptr,
             }
 
           /* Eat the next digit.  */
+          int digit;
           if (c_isdigit (*dp))
             digit = *dp - '0';
           else if (base == 16 && c_isxdigit (*dp))
@@ -387,31 +383,26 @@ STRTOD (const char *nptr, char **endptr)
 /* From here on, STRTOD refers to the underlying implementation.  It needs
    to handle only finite unsigned decimal numbers with non-null ENDPTR.  */
 {
-  char radixchar;
-  bool negative = false;
+  int saved_errno = errno;
 
-  /* The number so far.  */
-  DOUBLE num;
+  char radixchar = decimal_point_char ();
 
   const char *s = nptr;
-  const char *end;
-  char *endbuf;
-  int saved_errno = errno;
-
-  radixchar = decimal_point_char ();
 
   /* Eat whitespace.  */
   while (locale_isspace (*s))
     ++s;
 
   /* Get the sign.  */
-  negative = *s == '-';
+  bool negative = *s == '-';
   if (*s == '-' || *s == '+')
     ++s;
 
-  num = STRTOD (s, &endbuf);
+  char *endbuf;
+  DOUBLE num = /* The number so far.  */
+    STRTOD (s, &endbuf);
   SET_ERRNO_UPON_GRADUAL_UNDERFLOW (num);
-  end = endbuf;
+  const char *end = endbuf;
 
   if (c_isdigit (s[*s == radixchar]))
     {
index 26da42ec6529c7726a5bc394bdcbd767d0bb6b68..9847d995f171628cca2174856901b127cebf6caa 100644 (file)
@@ -43,8 +43,6 @@
 char *
 __strtok_r (char *s, const char *delim, char **save_ptr)
 {
-  char *token;
-
   if (s == NULL)
     s = *save_ptr;
 
@@ -57,7 +55,7 @@ __strtok_r (char *s, const char *delim, char **save_ptr)
     }
 
   /* Find the end of the token.  */
-  token = s;
+  char *token = s;
   s = strpbrk (token, delim);
   if (s == NULL)
     /* This token finishes the string.  */
index 954ba67a4a7bff4e3567f3853d96ba7a3b8360c7..68ce07d0819e3cb1b42af9f9c1f7016aabf0f751 100644 (file)
@@ -212,14 +212,6 @@ INT
 INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr,
                    int base GROUP_PARAM_PROTO LOCALE_PARAM_PROTO)
 {
-  int negative;
-  register unsigned LONG int cutoff;
-  register unsigned int cutlim;
-  register unsigned LONG int i;
-  register const STRING_TYPE *s;
-  const STRING_TYPE *save, *end;
-  int overflow;
-
 #ifdef USE_NUMBER_GROUPING
 # ifdef USE_IN_EXTENDED_LOCALE_MODEL
   struct locale_data *current = loc->__locales[LC_NUMERIC];
@@ -257,7 +249,8 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr,
       return 0;
     }
 
-  save = s = nptr;
+  register const STRING_TYPE *s = nptr;
+  const STRING_TYPE *save = s;
 
   /* Skip white space.  */
   while (ISSPACE (*s))
@@ -266,6 +259,7 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr,
     goto noconv;
 
   /* Check for a sign.  */
+  int negative;
   if (*s == L_('-'))
     {
       negative = 1;
@@ -301,6 +295,7 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr,
   /* Save the pointer so we can check later if anything happened.  */
   save = s;
 
+  const STRING_TYPE *end;
 #ifdef USE_NUMBER_GROUPING
   if (group)
     {
@@ -320,11 +315,11 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr,
 #endif
     end = NULL;
 
-  cutoff = STRTOL_ULONG_MAX / (unsigned LONG int) base;
-  cutlim = STRTOL_ULONG_MAX % (unsigned LONG int) base;
+  register unsigned LONG int cutoff = STRTOL_ULONG_MAX / (unsigned LONG int) base;
+  register unsigned int cutlim = STRTOL_ULONG_MAX % (unsigned LONG int) base;
 
-  overflow = 0;
-  i = 0;
+  int overflow = 0;
+  register unsigned LONG int i = 0;
   for (UCHAR_TYPE c = *s; c != L_('\0'); c = *++s)
     {
       if (s == end)
index 211b97a7ceec675d02cede4491229e60df4a3910..27f8425c2c63b07690fa1484cce4872616dc3aef 100644 (file)
@@ -80,13 +80,11 @@ struniq (const char *string)
 {
   size_t hashcode = string_hash (string);
   size_t slot = hashcode % STRUNIQ_HASH_TABLE_SIZE;
-  size_t size;
-  struct struniq_hash_node *new_node;
   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;
-  new_node =
+  size_t size = strlen (string) + 1;
+  struct struniq_hash_node *new_node =
     (struct struniq_hash_node *)
     malloc (FLEXSIZEOF (struct struniq_hash_node, contents, size));
   if (new_node == NULL)
index 49206d746b039705a3a0aeff922fd1c1e0212a64..2092bbc0e509a157e1dc510fb6d79409de55f9e3 100644 (file)
@@ -79,7 +79,6 @@ open_supersede (const char *filename, int flags, mode_t mode,
                 bool supersede_if_exists, bool supersede_if_does_not_exist,
                 struct supersede_final_action *action)
 {
-  int fd;
   /* Extra flags for existing devices.  */
   int extra_flags =
     #if defined __sun || (defined _WIN32 && !defined __CYGWIN__)
@@ -101,6 +100,7 @@ open_supersede (const char *filename, int flags, mode_t mode,
     filename = "NUL";
 #endif
 
+  int fd;
   if (supersede_if_exists)
     {
       if (supersede_if_does_not_exist)
@@ -293,9 +293,9 @@ after_close_actions (int ret, const struct supersede_final_action *action)
              file.  */
           {
             struct timespec ts[2];
-
             ts[0] = get_stat_atime (&dest_statbuf);
             ts[1] = get_stat_mtime (&temp_statbuf);
+
             ignore_value (utimens (action->final_rename_temp, ts));
           }
 
index e0c6bf04c9e0f2427ebb1709985b29bbd756fd1d..b535ff5e1d960fd6a0005db400a10919204a4187 100644 (file)
@@ -262,11 +262,7 @@ system_quote_argv (enum system_command_interpreter interpreter,
 {
   if (*argv != NULL)
     {
-      size_t length;
-      char *command;
-      char *p;
-
-      length = 0;
+      size_t length = 0;
       for (char * const *argp = argv; ; )
         {
           length += system_quote_length (interpreter, *argp) + 1;
@@ -275,18 +271,20 @@ system_quote_argv (enum system_command_interpreter interpreter,
             break;
         }
 
-      command = XNMALLOC (length, char);
+      char *command = XNMALLOC (length, char);
 
-      p = command;
-      for (char * const *argp = argv; ; )
-        {
-          p = system_quote_copy (p, interpreter, *argp);
-          argp++;
-          if (*argp == NULL)
-            break;
-          *p++ = ' ';
-        }
-      *p = '\0';
+      {
+        char *p = command;
+        for (char * const *argp = argv; ; )
+          {
+            p = system_quote_copy (p, interpreter, *argp);
+            argp++;
+            if (*argp == NULL)
+              break;
+            *p++ = ' ';
+          }
+        *p = '\0';
+      }
 
       return command;
     }
index a7c402cdbbad30ae09e9f2cdaeccb8d7b17a6b10..5d932313489734a74ab2fc4a6352872f0f5ae924 100644 (file)
 ptrdiff_t
 szprintf (char *str, const char *format, ...)
 {
-  char *output;
-  size_t len;
-  size_t lenbuf;
   va_list args;
+  va_start (args, format);
 
   /* Set lenbuf = min (SIZE_MAX, - (uintptr_t) str - 1).  */
-  lenbuf = SIZE_MAX;
+  size_t lenbuf = SIZE_MAX;
   if (lenbuf >= ~ (uintptr_t) str)
     lenbuf = ~ (uintptr_t) str;
 
-  va_start (args, format);
-  output = vasnprintf (str, &lenbuf, format, args);
-  len = lenbuf;
+  char *output = vasnprintf (str, &lenbuf, format, args);
+  size_t len = lenbuf;
+
   va_end (args);
 
   if (!output)
index 908676b1d445f8d346a2512e81627be8f1ed99c0..61af6dba26efba6b4efed940dc95a1595efe2ce1 100644 (file)
@@ -148,10 +148,7 @@ static const long double
 static long double
 kernel_tanl (long double x, long double y, int iy)
 {
-  long double z, r, v, w, s, u, u1;
-  int invert = 0, sign;
-
-  sign = 1;
+  int sign = 1;
   if (x < 0)
     {
       x = -x;
@@ -169,24 +166,27 @@ kernel_tanl (long double x, long double y, int iy)
             return (iy == 1 ? x : -1.0L / x) * sign;
         }
     }
+
+  int invert = 0;
   if (x >= 0.6743316650390625) /* |x| >= 0.6743316650390625 */
     {
       invert = 1;
 
-      z = pio4hi - x;
-      w = pio4lo - y;
+      long double z = pio4hi - x;
+      long double w = pio4lo - y;
       x = z + w;
       y = 0.0;
     }
-  z = x * x;
-  r = T0 + z * (T1 + z * (T2 + z * (T3 + z * T4)));
-  v = U0 + z * (U1 + z * (U2 + z * (U3 + z * (U4 + z))));
+
+  long double z = x * x;
+  long double r = T0 + z * (T1 + z * (T2 + z * (T3 + z * T4)));
+  long double v = U0 + z * (U1 + z * (U2 + z * (U3 + z * (U4 + z))));
   r = r / v;
 
-  s = z * x;
+  long double s = z * x;
   r = y + z * (s * r + y);
   r += TH * s;
-  w = x + r;
+  long double w = x + r;
   if (invert)
     {
       v = (long double) iy;
@@ -199,10 +199,10 @@ kernel_tanl (long double x, long double y, int iy)
     {                           /* if allow error up to 2 ulp,
                                    simply return -1.0/(x+r) here */
       /*  compute -1.0/(x+r) accurately */
-      u1 = (double) w;
+      long double u1 = (double) w;
       v = r - (u1 - x);
       z = -1.0 / w;
-      u = (double) z;
+      long double u = (double) z;
       s = 1.0 + u * u1;
       return (u + z * (s + u * v)) * sign;
     }
@@ -211,9 +211,6 @@ kernel_tanl (long double x, long double y, int iy)
 long double
 tanl (long double x)
 {
-  long double y[2], z = 0.0L;
-  int n;
-
   /* tanl(NaN) is NaN */
   if (isnanl (x))
     return x;
@@ -221,7 +218,10 @@ tanl (long double x)
   /* |x| ~< pi/4 */
   if (x >= -0.7853981633974483096156608458198757210492 &&
       x <= 0.7853981633974483096156608458198757210492)
-    return kernel_tanl (x, z, 1);
+    {
+      long double z = 0.0L;
+      return kernel_tanl (x, z, 1);
+    }
 
   /* tanl(Inf) is NaN, tanl(0) is 0 */
   else if (x + x == x)
@@ -230,7 +230,8 @@ tanl (long double x)
   /* argument reduction needed */
   else
     {
-      n = ieee754_rem_pio2l (x, y);
+      long double y[2];
+      int n = ieee754_rem_pio2l (x, y);
       /* 1 -- n even, -1 -- n odd */
       return kernel_tanl (y[0], y[1], 1 - ((n & 1) << 1));
     }
index 30a681033cea693396eb45a2e99ac982f707ecdc..3fa6b901b6bd800cb5c8f202f93de2116a4698e0 100644 (file)
@@ -189,9 +189,6 @@ int
 try_tempname_len (char *tmpl, int suffixlen, void *args,
                   int (*tryfunc) (char *, void *), size_t x_suffix_len)
 {
-  size_t len;
-  char *XXXXXX;
-  int fd;
   int saved_errno = errno;
 
   /* A lower bound on the number of temporary files to attempt to
@@ -224,7 +221,7 @@ try_tempname_len (char *tmpl, int suffixlen, void *args,
   random_value const biased_min
     = RANDOM_VALUE_MAX - RANDOM_VALUE_MAX % BASE_62_POWER;
 
-  len = strlen (tmpl);
+  size_t len = strlen (tmpl);
   if (len < x_suffix_len + suffixlen
       || strspn (&tmpl[len - x_suffix_len - suffixlen], "X") < x_suffix_len)
     {
@@ -233,7 +230,7 @@ try_tempname_len (char *tmpl, int suffixlen, void *args,
     }
 
   /* This is where the Xs start.  */
-  XXXXXX = &tmpl[len - x_suffix_len - suffixlen];
+  char *XXXXXX = &tmpl[len - x_suffix_len - suffixlen];
 
   for (unsigned int count = 0; count < attempts; ++count)
     {
@@ -254,7 +251,7 @@ try_tempname_len (char *tmpl, int suffixlen, void *args,
           vdigits--;
         }
 
-      fd = tryfunc (tmpl, args);
+      int fd = tryfunc (tmpl, args);
       if (fd >= 0)
         {
           __set_errno (saved_errno);
index 54fdd0d140e409350c4d3f735af8a3c7a2e85cae..ecc7b4c9e4c540f37bd480fe293e57ad697f3fcb 100644 (file)
@@ -119,10 +119,6 @@ static _GL_ASYNC_SAFE void
 sprintf_integer (char *str, int x)
 {
   unsigned int y;
-  char buf[20];
-  char *p;
-  size_t n;
-
   if (x < 0)
     {
       *str++ = '-';
@@ -131,14 +127,15 @@ sprintf_integer (char *str, int x)
   else
     y = x;
 
-  p = buf + sizeof (buf);
+  char buf[20];
+  char *p = buf + sizeof (buf);
   do
     {
       *--p = '0' + (y % 10);
       y = y / 10;
     }
   while (y > 0);
-  n = buf + sizeof (buf) - p;
+  size_t n = buf + sizeof (buf) - p;
   memcpy (str, p, n);
   str[n] = '\0';
 }
index b1b40db8737f7c25a7a32708a02ed2c79b002273..662c2dda41b168db9dc0f2c80ef702c556277fe5 100644 (file)
@@ -153,11 +153,10 @@ static inline ptrdiff_t
 ostream_printf (ostream_t stream, const char *format, ...)
 {
   va_list args;
-  char *temp_string;
-  ptrdiff_t ret;
 
   va_start (args, format);
-  ret = vasprintf (&temp_string, format, args);
+  char *temp_string;
+  ptrdiff_t ret = vasprintf (&temp_string, format, args);
   va_end (args);
   if (ret >= 0)
     {
index 1d35c5d40b6a58775c90c2a4c017170b9ab8ee67..83c40c212090c735f51eb222c1a7b156d3513489 100644 (file)
@@ -28,11 +28,9 @@ time_t
 time (time_t *tp)
 {
   struct timeval tv;
-  time_t tt;
-
   if (gettimeofday (&tv, NULL) < 0)
     abort ();
-  tt = tv.tv_sec;
+  time_t tt = tv.tv_sec;
 
   if (tp)
     *tp = tt;
index ecec1b9c0e6bcb7840b2a9ff9d2cfa9870f7d0f8..71e90ecf0446f921e12d63a7d2f0de7524b8e18a 100644 (file)
@@ -31,8 +31,6 @@
 static clock_t
 filetime2clock (FILETIME time)
 {
-  float f;
-
   /* We have a 64-bit value, in the form of two DWORDS aka unsigned
      int, counting the number of 100-nanosecond intervals.  We need to
      convert these to clock ticks.  Older POSIX uses CLK_TCK to
@@ -42,7 +40,7 @@ filetime2clock (FILETIME time)
      use it.  Note that CLOCKS_PER_SEC constant does not apply here,
      it is for use with the clock function.  */
 
-  f = (unsigned long long) time.dwHighDateTime << 32;
+  float f = (unsigned long long) time.dwHighDateTime << 32;
   f += time.dwLowDateTime;
   f = f * CLK_TCK / 10000000;
   return (clock_t) round (f);
index 3e154f248532e66b096a955df53f9229a0956dba..a16cb05e828747c602100695dab747a755918cbf 100644 (file)
@@ -32,8 +32,8 @@ timespec_add (struct timespec a, struct timespec b)
   int nssum = a.tv_nsec + b.tv_nsec;
   int carry = TIMESPEC_HZ <= nssum;
   time_t rs;
-  int rns;
   bool v = ckd_add (&rs, a.tv_sec, b.tv_sec);
+  int rns;
   if (v == ckd_add (&rs, rs, carry))
     rns = nssum - TIMESPEC_HZ * carry;
   else
index 7cde18be90c19657859e8125a5d843b0d4ee73b5..df51a49c215bedc1ad407917e7a736fbb5b3a432 100644 (file)
@@ -33,8 +33,8 @@ timespec_sub (struct timespec a, struct timespec b)
   int nsdiff = a.tv_nsec - b.tv_nsec;
   int borrow = nsdiff < 0;
   time_t rs;
-  int rns;
   bool v = ckd_sub (&rs, a.tv_sec, b.tv_sec);
+  int rns;
   if (v == ckd_sub (&rs, rs, borrow))
     rns = nsdiff + TIMESPEC_HZ * borrow;
   else
index db1f1e48eb4f15d5f3e7f60a4b4508ada17f324e..9ff6938fb7ae9304da54cc3b0246b114fc0822e0 100644 (file)
@@ -92,10 +92,7 @@ int
 path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
              bool try_tmpdir)
 {
-  const char *d;
-  size_t dlen, plen;
-  bool add_slash;
-
+  size_t plen;
   if (!pfx || !pfx[0])
     {
       pfx = "file";
@@ -110,7 +107,7 @@ path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
 
   if (try_tmpdir)
     {
-      d = __libc_secure_getenv ("TMPDIR");
+      const char *d = __libc_secure_getenv ("TMPDIR");
       if (d != NULL && direxists (d))
         dir = d;
       else if (dir != NULL && direxists (dir))
@@ -122,13 +119,12 @@ path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
     {
 #if defined _WIN32 && ! defined __CYGWIN__
       char dirbuf[PATH_MAX];
-      DWORD retval;
 
       /* Find Windows temporary file directory.
          We try this before P_tmpdir because Windows defines P_tmpdir to "\\"
          and will therefore try to put all temporary files in the root
          directory (unless $TMPDIR is set).  */
-      retval = GetTempPath (PATH_MAX, dirbuf);
+      DWORD retval = GetTempPath (PATH_MAX, dirbuf);
       if (retval > 0 && retval < PATH_MAX && direxists (dirbuf))
         dir = dirbuf;
       else
@@ -144,7 +140,9 @@ path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
         }
     }
 
-  dlen = strlen (dir);
+  size_t dlen = strlen (dir);
+
+  bool add_slash;
 #ifdef __VMS
   add_slash = 0;
 #else
index f5588c3c07e1d837a071029a9c05cdf072a5bd6d..9cbbef9aa05b9357375048c730f7d1d02f0b04e4 100644 (file)
@@ -90,13 +90,12 @@ FILE *
 tmpfile (void)
 {
   char dir[PATH_MAX];
-  DWORD retval;
 
   /* Find Windows temporary file directory.
      We provide this as the directory argument to path_search because Windows
      defines P_tmpdir to "\\" and will therefore try to put all temporary files
      in the root directory (unless $TMPDIR is set). */
-  retval = GetTempPath (PATH_MAX, dir);
+  DWORD retval = GetTempPath (PATH_MAX, dir);
   if (retval > 0 && retval < PATH_MAX)
     {
       char xtemplate[PATH_MAX];
@@ -105,8 +104,8 @@ tmpfile (void)
         {
           size_t len = strlen (xtemplate);
           int o_temporary = (supports_delete_on_close () ? _O_TEMPORARY : 0);
-          int fd;
 
+          int fd;
           do
             {
               memcpy (&xtemplate[len - 6], "XXXXXX", 6);
@@ -156,8 +155,6 @@ FILE *
 tmpfile (void)
 {
   char buf[PATH_MAX];
-  int fd;
-  FILE *fp;
 
   /* Try $TMPDIR first, not /tmp nor P_tmpdir, because we need this replacement
      on Android, and /tmp does not exist on Android.  */
@@ -165,7 +162,7 @@ tmpfile (void)
   if (path_search (buf, sizeof buf, NULL, "tmpf", true))
     return NULL;
 
-  fd = gen_tempname (buf, 0, 0, GT_FILE);
+  int fd = gen_tempname (buf, 0, 0, GT_FILE);
   if (fd < 0)
     return NULL;
 
@@ -173,7 +170,8 @@ tmpfile (void)
      a file is not really removed until it is closed.  */
   (void) unlink (buf);
 
-  if ((fp = fdopen (fd, "w+b")) == NULL)
+  FILE *fp = fdopen (fd, "w+b");
+  if (fp == NULL)
     {
       int saved_errno = errno;
       close (fd);
index d7bd166cc193a2944d08b47e8ddc4d5b29a0002a..82e84246488eadf3c51a8c9bf5e6ebdfba5f553b 100644 (file)
@@ -37,11 +37,10 @@ FUNC (int c, locale_t locale)
 #else
   /* Implementation for the global locale.  */
   {
-    int ret;
 # if HAVE_WORKING_USELOCALE
     locale_t saved_locale = uselocale (LC_GLOBAL_LOCALE);
 # endif
-    ret = GLOBAL_FUNC (c);
+    int ret = GLOBAL_FUNC (c);
 # if HAVE_WORKING_USELOCALE
     uselocale (saved_locale);
 # endif
index a08fb93fdd417258910336073c49b8cee45bcc6e..943a3c9b303aa6ea154f79f461203cb83bb729b4 100644 (file)
@@ -258,22 +258,14 @@ tparm (const char *str, ...)
   static int termcap;
   static char OOPS[] = "OOPS";
   static char buf[MAX_LINE];
-  const char *sp;
-  char *dp;
-  const char *fmt;
-  char scan_for;
-  int scan_depth;
-  int if_depth;
-  char fmt_buf[MAX_LINE];
-  char sbuf[MAX_LINE];
 
   va_start (tparm_args, str);
 
-  sp = str;
-  dp = buf;
-  scan_for = 0;
-  scan_depth = 0;
-  if_depth = 0;
+  const char *sp = str;
+  char *dp = buf;
+  char scan_for = 0;
+  int scan_depth = 0;
+  int if_depth = 0;
   argcnt = 0;
   pos = 0;
   termcap = 1;
@@ -314,7 +306,8 @@ tparm (const char *str, ...)
               sp++;
               break;
             }
-          fmt = NULL;
+          char fmt_buf[MAX_LINE];
+          const char *fmt = NULL;
           switch (*sp)
             {
             case '%':
@@ -471,60 +464,62 @@ tparm (const char *str, ...)
             case 'x': case 'X': case 'o': case 'c':
             case '0': case '1': case '4': case '5':
             case '6': case '7': case '8': case '9':
-              if (fmt == NULL)
-                {
-                  char *fmtp;
-                  if (termcap)
-                    return OOPS;
-                  if (*sp == ':')
-                    sp++;
-                  fmtp = fmt_buf;
-                  *fmtp++ = '%';
-                  while (*sp != 's' && *sp != 'x' && *sp != 'X' && *sp != 'd'
-                         && *sp != 'o' && *sp != 'c' && *sp != 'u')
-                    {
-                      if (*sp == '\0')
-                        return OOPS;
-                      *fmtp++ = *sp++;
-                    }
-                  *fmtp++ = *sp;
-                  *fmtp = '\0';
-                  fmt = fmt_buf;
-                }
               {
-                char conv_char = fmt[strlen (fmt) - 1];
-                if (conv_char == 's')
+                char sbuf[MAX_LINE];
+                if (fmt == NULL)
                   {
-                    char *s;
-                    if (popstring (&s))
-                      return OOPS;
-                    sprintf (sbuf, fmt, s);
-                  }
-                else
-                  {
-                    int i;
                     if (termcap)
+                      return OOPS;
+                    if (*sp == ':')
+                      sp++;
+                    char *fmtp = fmt_buf;
+                    *fmtp++ = '%';
+                    while (*sp != 's' && *sp != 'x' && *sp != 'X' && *sp != 'd'
+                           && *sp != 'o' && *sp != 'c' && *sp != 'u')
                       {
-                        if (getarg (termcap++ - 1, INTEGER, &i))
+                        if (*sp == '\0')
                           return OOPS;
+                        *fmtp++ = *sp++;
                       }
-                    else
-                      if (popnum (&i))
-                        return OOPS;
-                    if (i == 0 && conv_char == 'c')
-                      strcpy (sbuf, "\000");
-                    else
-                      sprintf (sbuf, fmt, i);
+                    *fmtp++ = *sp;
+                    *fmtp = '\0';
+                    fmt = fmt_buf;
                   }
-              }
-              sp++;
-              fmt = sbuf;
-              while (*fmt != '\0')
                 {
-                  if (*fmt == '$')
-                    *dp++ = '\\';
-                  *dp++ = *fmt++;
+                  char conv_char = fmt[strlen (fmt) - 1];
+                  if (conv_char == 's')
+                    {
+                      char *s;
+                      if (popstring (&s))
+                        return OOPS;
+                      sprintf (sbuf, fmt, s);
+                    }
+                  else
+                    {
+                      int i;
+                      if (termcap)
+                        {
+                          if (getarg (termcap++ - 1, INTEGER, &i))
+                            return OOPS;
+                        }
+                      else
+                        if (popnum (&i))
+                          return OOPS;
+                      if (i == 0 && conv_char == 'c')
+                        strcpy (sbuf, "\000");
+                      else
+                        sprintf (sbuf, fmt, i);
+                    }
                 }
+                sp++;
+                fmt = sbuf;
+                while (*fmt != '\0')
+                  {
+                    if (*fmt == '$')
+                      *dp++ = '\\';
+                    *dp++ = *fmt++;
+                  }
+              }
               break;
             case 'r':
               {
index b73090ff3f39882e69ab78f4e2833744bb6a6d67..faa51811cc6740a2130c994b2a1eb25250d38a4b 100644 (file)
@@ -204,10 +204,6 @@ static int kernel_rem_pio2 (double *x, double *y, int e0, int nx, int prec,
 int
 ieee754_rem_pio2l (long double x, long double *y)
 {
-  long double z, w, t;
-  double tx[8];
-  int exp, n;
-
   if (x >= -0.78539816339744830961566084581987572104929234984377
       && x <= 0.78539816339744830961566084581987572104929234984377)
     /* x in <-pi/4, pi/4> */
@@ -220,7 +216,7 @@ ieee754_rem_pio2l (long double x, long double *y)
   if (x > 0 && x < 2.35619449019234492884698253745962716314787704953131)
       {
         /* 113 + 93 bit PI is ok */
-        z = x - PI_2_1;
+        long double z = x - PI_2_1;
         y[0] = z - PI_2_1t;
         y[1] = (z - y[0]) - PI_2_1t;
         return 1;
@@ -229,7 +225,7 @@ ieee754_rem_pio2l (long double x, long double *y)
   if (x < 0 && x > -2.35619449019234492884698253745962716314787704953131)
       {
         /* 113 + 93 bit PI is ok */
-        z = x + PI_2_1;
+        long double z = x + PI_2_1;
         y[0] = z + PI_2_1t;
         y[1] = (z - y[0]) + PI_2_1t;
         return -1;
@@ -245,7 +241,10 @@ ieee754_rem_pio2l (long double x, long double *y)
   /* Handle large arguments.
      We split the 113 bits of the mantissa into 5 24bit integers
      stored in a double array.  */
-  z = frexp (x, &exp);
+  int exp;
+  long double z = frexp (x, &exp);
+
+  double tx[8];
   tx[0] = floorl (z *= 16777216.0);
   z -= tx[0];
   tx[1] = floorl (z *= 16777216.0);
@@ -256,12 +255,12 @@ ieee754_rem_pio2l (long double x, long double *y)
   z -= tx[3];
   tx[4] = floorl (z *= 16777216.0);
 
-  n = kernel_rem_pio2 (tx, tx + 5, exp - 24, tx[4] ? 5 : 4, 3, two_over_pi);
+  int n = kernel_rem_pio2 (tx, tx + 5, exp - 24, tx[4] ? 5 : 4, 3, two_over_pi);
 
   /* The result is now stored in 3 double values, we need to convert it into
      two long double values.  */
-  t = (long double) tx[6] + (long double) tx[7];
-  w = (long double) tx[5];
+  long double t = (long double) tx[6] + (long double) tx[7];
+  long double w = (long double) tx[5];
 
   if (x > 0)
     {
@@ -429,53 +428,59 @@ static int
 kernel_rem_pio2 (double *x, double *y, int e0, int nx, int prec,
                  const int *ipio2)
 {
-  int jz, jx, jv, jp, jk, carry, n, iq[20], i, j, k, m, q0, ih;
-  double z, fw, f[20], fq[20], q[20];
-
   /* initialize jk */
-  jk = init_jk[prec];
-  jp = jk;
+  int jk = init_jk[prec];
+  int jp = jk;
 
   /* determine jx,jv,q0, note that 3>q0 */
-  jx = nx - 1;
-  jv = (e0 - 3) / 24;
+  int jx = nx - 1;
+  int jv = (e0 - 3) / 24;
   if (jv < 0)
     jv = 0;
-  q0 = e0 - 24 * (jv + 1);
+  int q0 = e0 - 24 * (jv + 1);
 
   /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
-  j = jv - jx;
-  m = jx + jk;
-  for (i = 0; i <= m; i++, j++)
+  int j = jv - jx;
+  int m = jx + jk;
+  double f[20];
+  for (int i = 0; i <= m; i++, j++)
     f[i] = (j < 0) ? zero : (double) ipio2[j];
 
   /* compute q[0],q[1],...q[jk] */
-  for (i = 0; i <= jk; i++)
+  double q[20];
+  for (int i = 0; i <= jk; i++)
     {
+      double fw;
       for (j = 0, fw = 0.0; j <= jx; j++)
         fw += x[j] * f[jx + i - j];
       q[i] = fw;
     }
 
-  jz = jk;
-recompute:
+  int jz = jk;
+recompute: ;
+  double z;
+
   /* distill q[] into iq[] in reverse order */
-  for (i = 0, j = jz, z = q[jz]; j > 0; i++, j--)
-    {
-      fw = (double) ((int) (twon24 * z));
-      iq[i] = (int) (z - two24 * fw);
-      z = q[j - 1] + fw;
-    }
+  int iq[20];
+  {
+    int i;
+    for (i = 0, j = jz, z = q[jz]; j > 0; i++, j--)
+      {
+        double fw = (double) ((int) (twon24 * z));
+        iq[i] = (int) (z - two24 * fw);
+        z = q[j - 1] + fw;
+      }
+  }
 
   /* compute n */
   z = ldexp (z, q0);            /* actual value of z */
   z -= 8.0 * floor (z * 0.125); /* trim off integer >= 8 */
-  n = (int) z;
+  int n = (int) z;
   z -= (double) n;
-  ih = 0;
+  int ih = 0;
   if (q0 > 0)
     {                           /* need iq[jz-1] to determine n */
-      i = (iq[jz - 1] >> (24 - q0));
+      int i = (iq[jz - 1] >> (24 - q0));
       n += i;
       iq[jz - 1] -= i << (24 - q0);
       ih = iq[jz - 1] >> (23 - q0);
@@ -488,8 +493,8 @@ recompute:
   if (ih > 0)
     {                           /* q > 0.5 */
       n += 1;
-      carry = 0;
-      for (i = 0; i < jz; i++)
+      int carry = 0;
+      for (int i = 0; i < jz; i++)
         {                       /* compute 1-q */
           j = iq[i];
           if (carry == 0)
@@ -527,15 +532,17 @@ recompute:
   if (z == zero)
     {
       j = 0;
-      for (i = jz - 1; i >= jk; i--)
+      for (int i = jz - 1; i >= jk; i--)
         j |= iq[i];
       if (j == 0)
         {                       /* need recomputation */
+          int k;
           for (k = 1; iq[jk - k] == 0; k++);    /* k = no. of terms needed */
 
-          for (i = jz + 1; i <= jz + k; i++)
+          for (int i = jz + 1; i <= jz + k; i++)
             {                   /* add q[jz+1] to q[jz+k] */
               f[jx + i] = (double) ipio2[jv + i];
+              double fw;
               for (j = 0, fw = 0.0; j <= jx; j++)
                 fw += x[j] * f[jx + i - j];
               q[i] = fw;
@@ -561,7 +568,7 @@ recompute:
       z = ldexp (z, -q0);
       if (z >= two24)
         {
-          fw = (double) ((int) (twon24 * z));
+          double fw = (double) ((int) (twon24 * z));
           iq[jz] = (int) (z - two24 * fw);
           jz += 1;
           q0 += 24;
@@ -572,54 +579,61 @@ recompute:
     }
 
   /* convert integer "bit" chunk to floating-point value */
-  fw = ldexp (one, q0);
-  for (i = jz; i >= 0; i--)
-    {
-      q[i] = fw * (double) iq[i];
-      fw *= twon24;
-    }
+  {
+    double fw = ldexp (one, q0);
+    for (int i = jz; i >= 0; i--)
+      {
+        q[i] = fw * (double) iq[i];
+        fw *= twon24;
+      }
+  }
 
   /* compute PIo2[0,...,jp]*q[jz,...,0] */
-  for (i = jz; i >= 0; i--)
+  double fq[20];
+  for (int i = jz; i >= 0; i--)
     {
+      double fw;
+      int k;
       for (fw = 0.0, k = 0; k <= jp && k <= jz - i; k++)
         fw += PIo2[k] * q[i + k];
       fq[jz - i] = fw;
     }
 
   /* compress fq[] into y[] */
+  double fw;
   switch (prec)
     {
     case 0:
       fw = 0.0;
-      for (i = jz; i >= 0; i--)
+      for (int i = jz; i >= 0; i--)
         fw += fq[i];
       y[0] = (ih == 0) ? fw : -fw;
       break;
     case 1:
     case 2:
       fw = 0.0;
-      for (i = jz; i >= 0; i--)
+      for (int i = jz; i >= 0; i--)
         fw += fq[i];
       y[0] = (ih == 0) ? fw : -fw;
       fw = fq[0] - fw;
-      for (i = 1; i <= jz; i++)
+      for (int i = 1; i <= jz; i++)
         fw += fq[i];
       y[1] = (ih == 0) ? fw : -fw;
       break;
     case 3:                     /* painful */
-      for (i = jz; i > 0; i--)
+      for (int i = jz; i > 0; i--)
         {
           fw = fq[i - 1] + fq[i];
           fq[i] += fq[i - 1] - fw;
           fq[i - 1] = fw;
         }
-      for (i = jz; i > 1; i--)
+      for (int i = jz; i > 1; i--)
         {
           fw = fq[i - 1] + fq[i];
           fq[i] += fq[i - 1] - fw;
           fq[i - 1] = fw;
         }
+      int i;
       for (fw = 0.0, i = jz; i >= 2; i--)
         fw += fq[i];
       if (ih == 0)
index c59f0241e5ce468fad97db751e5e52bcac314a6c..7730da342d2fe28ffcf3219547046ded556296f1 100644 (file)
@@ -45,11 +45,12 @@ trim2 (const char *s, int how)
 #if GNULIB_MCEL_PREFER
       /* Skip leading whitespace. */
       if (how != TRIM_TRAILING)
-        for (mcel_t g; *start; start += g.len)
+        for (; *start; )
           {
-            g = mcel_scanz (start);
+            mcel_t g = mcel_scanz (start);
             if (!c32isspace (g.ch))
               break;
+            start += g.len;
           }
 
       /* Find start of any trailing whitespace.  */
index 4f180467f31459f21cca6e1729cf2c3735b1cc04..2518bc8cf63096917c3e7bd8a4471bb2b15e253a 100644 (file)
@@ -153,10 +153,10 @@ check_tree_recurse (node p, int d_sofar, int d_total)
 static void
 check_tree (node root)
 {
-  int cnt = 0;
   if (root == NULL)
     return;
   root->red = 0;
+  int cnt = 0;
   for (node p = root->left; p; p = p->left)
     cnt += !p->red;
   check_tree_recurse (root, 0, cnt);
@@ -182,9 +182,8 @@ maybe_split_for_insert (node *rootp, node *parentp, node *gparentp,
                         int p_r, int gp_r, int mode)
 {
   node root = *rootp;
-  node *rp, *lp;
-  rp = &(*rootp)->right;
-  lp = &(*rootp)->left;
+  node *rp = &(*rootp)->right;
+  node *lp = &(*rootp)->left;
 
   /* See if we have to split this node (both successors red).  */
   if (mode == 1
@@ -263,11 +262,7 @@ maybe_split_for_insert (node *rootp, node *parentp, node *gparentp,
 void *
 __tsearch (const void *key, void **vrootp, __compar_fn_t compar)
 {
-  node q;
-  node *parentp = NULL, *gparentp = NULL;
   node *rootp = (node *) vrootp;
-  node *nextp;
-  int r = 0, p_r = 0, gp_r = 0; /* No they might not, Mr Compiler.  */
 
   if (rootp == NULL)
     return NULL;
@@ -278,7 +273,11 @@ __tsearch (const void *key, void **vrootp, __compar_fn_t compar)
 
   CHECK_TREE (*rootp);
 
-  nextp = rootp;
+  node *parentp = NULL;
+  node *gparentp = NULL;
+  int r = 0, p_r = 0, gp_r = 0; /* No they might not, Mr Compiler.  */
+
+  node *nextp = rootp;
   while (*nextp != NULL)
     {
       node root = *rootp;
@@ -303,7 +302,7 @@ __tsearch (const void *key, void **vrootp, __compar_fn_t compar)
       p_r = r;
     }
 
-  q = (struct node_t *) malloc (sizeof (struct node_t));
+  node q = (struct node_t *) malloc (sizeof (struct node_t));
   if (q != NULL)
     {
       *nextp = q;                       /* link new node to old */
@@ -340,9 +339,7 @@ __tfind (const void *key, void *const *vrootp, __compar_fn_t compar)
   while (*rootp != NULL)
     {
       node root = *rootp;
-      int r;
-
-      r = (*compar) (key, root->key);
+      int r = (*compar) (key, root->key);
       if (r == 0)
         return root;
 
@@ -361,53 +358,55 @@ weak_alias (__tfind, tfind)
 void *
 __tdelete (const void *key, void **vrootp, __compar_fn_t compar)
 {
-  node p, q, r, retval;
-  int cmp;
   node *rootp = (node *) vrootp;
-  node root, unchained;
-  /* Stack of nodes so we remember the parents without recursion.  It's
-     _very_ unlikely that there are paths longer than 40 nodes.  The tree
-     would need to have around 250.000 nodes.  */
-  int stacksize = 100;
-  int sp = 0;
-  node *nodestack[100];
 
   if (rootp == NULL)
     return NULL;
-  p = *rootp;
+
+  node p = *rootp;
   if (p == NULL)
     return NULL;
 
   CHECK_TREE (p);
 
-  while ((cmp = (*compar) (key, (*rootp)->key)) != 0)
-    {
-      if (sp == stacksize)
-        abort ();
-
-      nodestack[sp++] = rootp;
-      p = *rootp;
-      rootp = ((cmp < 0)
-               ? &(*rootp)->left
-               : &(*rootp)->right);
-      if (*rootp == NULL)
-        return NULL;
-    }
+  /* Stack of nodes so we remember the parents without recursion.  It's
+     _very_ unlikely that there are paths longer than 40 nodes.  The tree
+     would need to have around 250.000 nodes.  */
+  int stacksize = 100;
+  int sp = 0;
+  node *nodestack[100];
+  {
+    int cmp;
+    while ((cmp = (*compar) (key, (*rootp)->key)) != 0)
+      {
+        if (sp == stacksize)
+          abort ();
+
+        nodestack[sp++] = rootp;
+        p = *rootp;
+        rootp = ((cmp < 0)
+                 ? &(*rootp)->left
+                 : &(*rootp)->right);
+        if (*rootp == NULL)
+          return NULL;
+      }
+  }
 
   /* This is bogus if the node to be deleted is the root... this routine
      really should return an integer with 0 for success, -1 for failure
      and errno = ESRCH or something.  */
-  retval = p;
+  node retval = p;
 
   /* We don't unchain the node we want to delete. Instead, we overwrite
      it with its successor and unchain the successor.  If there is no
      successor, we really unchain the node to be deleted.  */
 
-  root = *rootp;
+  node root = *rootp;
 
-  r = root->right;
-  q = root->left;
+  node r = root->right;
+  node q = root->left;
 
+  node unchained;
   if (q == NULL || r == NULL)
     unchained = root;
   else
index ce7511bc66571b85c20b756cfd577e4e52ca6602..1c6ed9af2f251b78187af53949e82d26dacd5655 100644 (file)
@@ -43,11 +43,11 @@ ttyname_r (int fd, char *buf, size_t buflen)
     {
       char procfile[14+11+1];
       char largerbuf[512];
-      ssize_t ret;
       sprintf (procfile, "/proc/self/fd/%d", fd);
-      ret = (buflen < sizeof (largerbuf)
-             ? readlink (procfile, largerbuf, sizeof (largerbuf))
-             : readlink (procfile, buf, buflen <= INT_MAX ? buflen : INT_MAX));
+      ssize_t ret =
+        (buflen < sizeof (largerbuf)
+         ? readlink (procfile, largerbuf, sizeof (largerbuf))
+         : readlink (procfile, buf, buflen <= INT_MAX ? buflen : INT_MAX));
       if (ret < 0)
         return errno;
       if ((size_t) ret >= buflen)
@@ -95,13 +95,10 @@ ttyname_r (int fd, char *buf, size_t buflen)
   return 0;
 #elif HAVE_TTYNAME
   /* Note: This is not multithread-safe.  */
-  char *name;
-  size_t namelen;
-
-  name = ttyname (fd);
+  char *name = ttyname (fd);
   if (name == NULL)
     return errno;
-  namelen = strlen (name) + 1;
+  size_t namelen = strlen (name) + 1;
   if (namelen > buflen)
     return ERANGE;
   memcpy (buf, name, namelen);
index c80a1fe0805faf3e085a545eb6ff491057e9322b..32b2c1ac4217ab050100b5ecd599deb6176f8a9f 100644 (file)
 int
 uname (struct utsname *buf)
 {
-  OSVERSIONINFO version;
-  OSVERSIONINFOEX versionex;
-  BOOL have_versionex; /* indicates whether versionex is filled */
-  const char *super_version;
-
   /* Preparation: Fill version and, if possible, also versionex.
      But try to call GetVersionEx only once in the common case.  */
+  OSVERSIONINFO version;
+  OSVERSIONINFOEX versionex;
   versionex.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
-  have_versionex = GetVersionEx ((OSVERSIONINFO *) &versionex);
+  BOOL have_versionex = /* indicates whether versionex is filled */
+    GetVersionEx ((OSVERSIONINFO *) &versionex);
   if (have_versionex)
     {
       /* We know that OSVERSIONINFO is a subset of OSVERSIONINFOEX.  */
@@ -81,6 +79,7 @@ uname (struct utsname *buf)
     strcpy (buf->nodename, "localhost");
 
   /* Determine major-major Windows version.  */
+  const char *super_version;
   if (version.dwPlatformId == VER_PLATFORM_WIN32_NT)
     {
       /* Windows NT or newer.  */
@@ -162,15 +161,15 @@ uname (struct utsname *buf)
           VERSION2 (6, 1, "Windows 7", "Windows Server 2008 R2"),
           VERSION2 (-1, -1, "Windows", "Windows Server")
         };
-      const char *base;
-      const struct windows_version *v = versions;
 
       /* Find a version that matches ours.  The last element is a
          wildcard that always ends the loop.  */
+      const struct windows_version *v = versions;
       while ((v->major != version.dwMajorVersion && v->major != -1)
              || (v->minor != version.dwMinorVersion && v->minor != -1))
         v++;
 
+      const char *base;
       if (have_versionex && versionex.wProductType != VER_NT_WORKSTATION)
         base = v->name + v->server_offset;
       else
index 8a064acff05546dc4c660015e77daa805262c77d..4a8d316935056bc99f74e5a72a72d27b6fe3810b 100644 (file)
@@ -39,10 +39,9 @@ const char *
 uc_locale_language (void)
 {
   const char *locale_name = gl_locale_name (LC_CTYPE, "LC_CTYPE");
-  const char *p;
 
   /* Find the end of the language portion.  */
-  p = locale_name;
+  const char *p = locale_name;
   while (*p != '\0' && *p != '_' && *p != '.' && *p != '@')
     p++;
 
index 4869e33555c14a028bf0fc1513d4494c1a387dbd..59b0d13fae2b3375603f9a83a164d8f0f49ade5c 100644 (file)
@@ -27,29 +27,23 @@ int
 FUNC (const SRC_UNIT *s1, size_t n1, const SRC_UNIT *s2, size_t n2,
       const char *iso639_language, uninorm_t nf, int *resultp)
 {
-  UNIT buf1[2048 / sizeof (UNIT)];
-  UNIT buf2[2048 / sizeof (UNIT)];
-  UNIT *norms1;
-  size_t norms1_length;
-  UNIT *norms2;
-  size_t norms2_length;
-  int cmp;
-
   /* Optimization: There is no need to do canonical composition of each string.
      Decomposition is enough.  */
   if (nf != NULL)
     nf = uninorm_decomposing_form (nf);
 
   /* Case-fold and normalize S1.  */
-  norms1_length = sizeof (buf1) / sizeof (UNIT);
-  norms1 = U_CASEFOLD (s1, n1, iso639_language, nf, buf1, &norms1_length);
+  UNIT buf1[2048 / sizeof (UNIT)];
+  size_t norms1_length = sizeof (buf1) / sizeof (UNIT);
+  UNIT *norms1 = U_CASEFOLD (s1, n1, iso639_language, nf, buf1, &norms1_length);
   if (norms1 == NULL)
     /* errno is set here.  */
     return -1;
 
   /* Case-fold and normalize S2.  */
-  norms2_length = sizeof (buf2) / sizeof (UNIT);
-  norms2 = U_CASEFOLD (s2, n2, iso639_language, nf, buf2, &norms2_length);
+  UNIT buf2[2048 / sizeof (UNIT)];
+  size_t norms2_length = sizeof (buf2) / sizeof (UNIT);
+  UNIT *norms2 = U_CASEFOLD (s2, n2, iso639_language, nf, buf2, &norms2_length);
   if (norms2 == NULL)
     {
       if (norms1 != buf1)
@@ -62,7 +56,7 @@ FUNC (const SRC_UNIT *s1, size_t n1, const SRC_UNIT *s2, size_t n2,
     }
 
   /* Compare the normalized strings.  */
-  cmp = U_CMP2 (norms1, norms1_length, norms2, norms2_length);
+  int cmp = U_CMP2 (norms1, norms1_length, norms2, norms2_length);
   if (cmp > 0)
     cmp = 1;
   else if (cmp < 0)
index 8787b451f550252a0e27ddae74185fe009453a7d..7e9570142c308bbc0e340c90dd34cdeb59919659 100644 (file)
@@ -28,25 +28,19 @@ int
 FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2,
       const char *iso639_language, uninorm_t nf, int *resultp)
 {
-  char buf1[2048];
-  char buf2[2048];
-  char *transformed1;
-  size_t transformed1_length;
-  char *transformed2;
-  size_t transformed2_length;
-  int cmp;
-
   /* Normalize and transform S1.  */
-  transformed1_length = sizeof (buf1);
-  transformed1 =
+  char buf1[2048];
+  size_t transformed1_length = sizeof (buf1);
+  char *transformed1 =
     U_CASEXFRM (s1, n1, iso639_language, nf, buf1, &transformed1_length);
   if (transformed1 == NULL)
     /* errno is set here.  */
     return -1;
 
   /* Normalize and transform S2.  */
-  transformed2_length = sizeof (buf2);
-  transformed2 =
+  char buf2[2048];
+  size_t transformed2_length = sizeof (buf2);
+  char *transformed2 =
     U_CASEXFRM (s2, n2, iso639_language, nf, buf2, &transformed2_length);
   if (transformed2 == NULL)
     {
@@ -60,8 +54,8 @@ FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2,
     }
 
   /* Compare the transformed strings.  */
-  cmp = memcmp2 (transformed1, transformed1_length,
-                 transformed2, transformed2_length);
+  int cmp = memcmp2 (transformed1, transformed1_length,
+                     transformed2, transformed2_length);
   if (cmp < 0)
     cmp = -1;
   else if (cmp > 0)
index 7af1375c3e2f1377d718ac1b9515c005d1f003b8..240bf1a637ac457743bd06dfc2389c250e686126 100644 (file)
@@ -35,10 +35,7 @@ FUNC (const UNIT *s, size_t n,
 {
   /* The result being accumulated.  */
   UNIT *result;
-  size_t length;
   size_t allocated;
-
-  /* Initialize the accumulator.  */
   if (nf != NULL || resultbuf == NULL)
     {
       result = NULL;
@@ -49,7 +46,7 @@ FUNC (const UNIT *s, size_t n,
       result = resultbuf;
       allocated = *lengthp;
     }
-  length = 0;
+  size_t length = 0;
 
   {
     const UNIT *s_end = s + n;
@@ -97,10 +94,10 @@ FUNC (const UNIT *s, size_t n,
                   {
                     /* Does the context apply?  */
                     int context = rule->context;
-                    bool applies;
-
                     if (context < 0)
                       context = - context;
+
+                    bool applies;
                     switch (context)
                       {
                       case SCC_ALWAYS:
@@ -373,9 +370,8 @@ FUNC (const UNIT *s, size_t n,
   if (nf != NULL)
     {
       /* Finally, normalize the result.  */
-      UNIT *normalized_result;
-
-      normalized_result = U_NORMALIZE (nf, result, length, resultbuf, lengthp);
+      UNIT *normalized_result =
+        U_NORMALIZE (nf, result, length, resultbuf, lengthp);
       if (normalized_result == NULL)
         goto fail;
 
@@ -399,9 +395,7 @@ FUNC (const UNIT *s, size_t n,
   else if (result != resultbuf && length < allocated)
     {
       /* Shrink the allocated memory if possible.  */
-      UNIT *memory;
-
-      memory = (UNIT *) realloc (result, length * sizeof (UNIT));
+      UNIT *memory = (UNIT *) realloc (result, length * sizeof (UNIT));
       if (memory != NULL)
         result = memory;
     }
index c5d0c978254984ac821fc9c51b37290851b155c2..98512dc2bffcb2434e48a6631bb08eaf46d6e098 100644 (file)
@@ -28,28 +28,22 @@ char *
 FUNC (const UNIT *s, size_t n, const char *iso639_language, uninorm_t nf,
       char *resultbuf, size_t *lengthp)
 {
-  UNIT foldedsbuf[2048 / sizeof (UNIT)];
-  UNIT *foldeds;
-  size_t foldeds_length;
-  char convsbuf[2048];
-  char *convs;
-  size_t convs_length;
-  char *result;
-
   /* Casefold and normalize the Unicode string.  */
-  foldeds_length = sizeof (foldedsbuf) / sizeof (UNIT);
-  foldeds = U_CASEFOLD (s, n, iso639_language, nf, foldedsbuf, &foldeds_length);
+  UNIT foldedsbuf[2048 / sizeof (UNIT)];
+  size_t foldeds_length = sizeof (foldedsbuf) / sizeof (UNIT);
+  UNIT *foldeds = U_CASEFOLD (s, n, iso639_language, nf, foldedsbuf, &foldeds_length);
   if (foldeds == NULL)
     /* errno is set here.  */
     return NULL;
 
   /* Convert it to locale encoding.  */
-  convs_length = sizeof (convsbuf) - 1;
-  convs = U_CONV_TO_ENCODING (locale_charset (),
-                              iconveh_error,
-                              foldeds, foldeds_length,
-                              NULL,
-                              convsbuf, &convs_length);
+  char convsbuf[2048];
+  size_t convs_length = sizeof (convsbuf) - 1;
+  char *convs = U_CONV_TO_ENCODING (locale_charset (),
+                                    iconveh_error,
+                                    foldeds, foldeds_length,
+                                    NULL,
+                                    convsbuf, &convs_length);
   if (convs == NULL)
     {
       if (foldeds != foldedsbuf)
@@ -78,7 +72,7 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, uninorm_t nf,
     }
 
   /* Apply locale dependent transformations for comparison.  */
-  result = amemxfrm (convs, convs_length, resultbuf, lengthp);
+  char *result = amemxfrm (convs, convs_length, resultbuf, lengthp);
   if (result == NULL)
     {
       if (convs != convsbuf)
index bd8cee180ee36e02bfaab5879cb8b8639d57eb77..753b02a2ad9070c0df21e66ed831d48d17a03db8 100644 (file)
@@ -53,27 +53,23 @@ FUNC (const UNIT *s, size_t n,
       /* X -> nf(toCasefold(NFD(X))) or
          X -> nf(toCasefold(nfd(toCasefold(NFD(X)))))  */
       int repeat = (uninorm_is_compat_decomposing (nf) ? 2 : 1);
-      UNIT tmpbuf1[2048 / sizeof (UNIT)];
-      UNIT tmpbuf2[2048 / sizeof (UNIT)];
-      UNIT *tmp1;
-      size_t tmp1_length;
-      UNIT *tmp2;
-      size_t tmp2_length;
 
-      tmp1_length = sizeof (tmpbuf1) / sizeof (UNIT);
-      tmp1 = U_NORMALIZE (UNINORM_NFD, s, n, tmpbuf1, &tmp1_length);
+      UNIT tmpbuf1[2048 / sizeof (UNIT)];
+      size_t tmp1_length = sizeof (tmpbuf1) / sizeof (UNIT);
+      UNIT *tmp1 = U_NORMALIZE (UNINORM_NFD, s, n, tmpbuf1, &tmp1_length);
       if (tmp1 == NULL)
         /* errno is set here.  */
         return NULL;
 
       do
         {
-          tmp2_length = sizeof (tmpbuf2) / sizeof (UNIT);
-          tmp2 = U_CASEMAP (tmp1, tmp1_length,
-                            prefix_context, suffix_context, iso639_language,
-                            uc_tocasefold, offsetof (struct special_casing_rule, casefold[0]),
-                            NULL,
-                            tmpbuf2, &tmp2_length);
+          UNIT tmpbuf2[2048 / sizeof (UNIT)];
+          size_t tmp2_length = sizeof (tmpbuf2) / sizeof (UNIT);
+          UNIT *tmp2 = U_CASEMAP (tmp1, tmp1_length,
+                                  prefix_context, suffix_context, iso639_language,
+                                  uc_tocasefold, offsetof (struct special_casing_rule, casefold[0]),
+                                  NULL,
+                                  tmpbuf2, &tmp2_length);
           if (tmp2 == NULL)
             {
               int saved_errno = errno;
index dcefd0366be00ba4d0cfbe1a3f5feed231950690..28405b339d05732eb368459c473f6f6c553e6f09 100644 (file)
@@ -40,12 +40,7 @@ FUNC (const UNIT *s, size_t n,
 {
   /* The result being accumulated.  */
   UNIT *result;
-  size_t length;
   size_t allocated;
-  /* An array containing the word break positions.  */
-  char *wordbreaks;
-
-  /* Initialize the accumulator.  */
   if (nf != NULL || resultbuf == NULL)
     {
       result = NULL;
@@ -56,8 +51,10 @@ FUNC (const UNIT *s, size_t n,
       result = resultbuf;
       allocated = *lengthp;
     }
-  length = 0;
+  size_t length = 0;
 
+  /* An array containing the word break positions.  */
+  char *wordbreaks;
   /* Initialize the word breaks array.  */
   if (n > 0)
     {
@@ -102,16 +99,13 @@ FUNC (const UNIT *s, size_t n,
         ucs4_t uc;
         int count = U_MBTOUC_UNSAFE (&uc, s, s_end - s);
 
-        ucs4_t (*single_character_map) (ucs4_t);
-        size_t offset_in_rule; /* offset in 'struct special_casing_rule' */
-
-        ucs4_t mapped_uc[3];
-        unsigned int mapped_count;
-
         if (*wp)
           /* Crossing a word boundary.  */
           in_word_first_part = true;
 
+        ucs4_t (*single_character_map) (ucs4_t);
+        size_t offset_in_rule; /* offset in 'struct special_casing_rule' */
+
         /* Determine single_character_map, offset_in_rule.
            There are three possibilities:
              - uc should not be converted.
@@ -140,6 +134,9 @@ FUNC (const UNIT *s, size_t n,
             offset_in_rule = offsetof (struct special_casing_rule, lower[0]);
           }
 
+        ucs4_t mapped_uc[3];
+        unsigned int mapped_count;
+
         /* Actually map uc.  */
         if (single_character_map == NULL)
           {
@@ -173,10 +170,11 @@ FUNC (const UNIT *s, size_t n,
                   {
                     /* Does the context apply?  */
                     int context = rule->context;
-                    bool applies;
 
                     if (context < 0)
                       context = - context;
+
+                    bool applies;
                     switch (context)
                       {
                       case SCC_ALWAYS:
@@ -452,9 +450,8 @@ FUNC (const UNIT *s, size_t n,
   if (nf != NULL)
     {
       /* Finally, normalize the result.  */
-      UNIT *normalized_result;
-
-      normalized_result = U_NORMALIZE (nf, result, length, resultbuf, lengthp);
+      UNIT *normalized_result =
+        U_NORMALIZE (nf, result, length, resultbuf, lengthp);
       if (normalized_result == NULL)
         goto fail2;
 
@@ -478,9 +475,7 @@ FUNC (const UNIT *s, size_t n,
   else if (result != resultbuf && length < allocated)
     {
       /* Shrink the allocated memory if possible.  */
-      UNIT *memory;
-
-      memory = (UNIT *) realloc (result, length * sizeof (UNIT));
+      UNIT *memory = (UNIT *) realloc (result, length * sizeof (UNIT));
       if (memory != NULL)
         result = memory;
     }
index f22282af0e89a1a78bdf0bc9e3c625987f430328..0333edeb9f199e49950a597abcacbb078b3eea4c 100644 (file)
@@ -27,27 +27,20 @@ int
 FUNC (const UNIT *s, size_t n, const char *iso639_language,
       bool *resultp)
 {
-  UNIT normsbuf[2048 / sizeof (UNIT)];
-  UNIT *norms;
-  size_t norms_length;
-  UNIT mappedbuf[2048 / sizeof (UNIT)];
-  UNIT *mapped_toupper;
-  UNIT *mapped_tolower;
-  UNIT *mapped_totitle;
-  size_t mapped_length;
-
   /* Apply canonical decomposition to S.  */
-  norms_length = sizeof (normsbuf) / sizeof (UNIT);
-  norms = U_NORMALIZE (UNINORM_NFD, s, n, normsbuf, &norms_length);
+  UNIT normsbuf[2048 / sizeof (UNIT)];
+  size_t norms_length = sizeof (normsbuf) / sizeof (UNIT);
+  UNIT *norms = U_NORMALIZE (UNINORM_NFD, s, n, normsbuf, &norms_length);
   if (norms == NULL)
     /* errno is set here.  */
     return -1;
 
-  mapped_length = sizeof (mappedbuf) / sizeof (UNIT);
+  UNIT mappedbuf[2048 / sizeof (UNIT)];
+  size_t mapped_length = sizeof (mappedbuf) / sizeof (UNIT);
 
   /* Apply toupper mapping.  */
-  mapped_toupper = U_TOUPPER (norms, norms_length, iso639_language, NULL,
-                              mappedbuf, &mapped_length);
+  UNIT *mapped_toupper = U_TOUPPER (norms, norms_length, iso639_language, NULL,
+                                    mappedbuf, &mapped_length);
   if (mapped_toupper == NULL)
     goto fail;
 
@@ -61,8 +54,8 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language,
     }
 
   /* Apply tolower mapping.  */
-  mapped_tolower = U_TOLOWER (norms, norms_length, iso639_language, NULL,
-                              mapped_toupper, &mapped_length);
+  UNIT *mapped_tolower = U_TOLOWER (norms, norms_length, iso639_language, NULL,
+                                    mapped_toupper, &mapped_length);
   if (mapped_tolower == NULL)
     {
       if (mapped_toupper != mappedbuf)
@@ -87,8 +80,8 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language,
     }
 
   /* Apply totitle mapping.  */
-  mapped_totitle = U_TOTITLE (norms, norms_length, iso639_language, NULL,
-                              mapped_tolower, &mapped_length);
+  UNIT *mapped_totitle = U_TOTITLE (norms, norms_length, iso639_language, NULL,
+                                    mapped_tolower, &mapped_length);
   if (mapped_totitle == NULL)
     {
       if (mapped_tolower != mappedbuf)
index 131c1aa63130819d1b56198a05b0b9307b1dd522..09137d367a2a589b052d7c15492418ec1fa50358 100644 (file)
@@ -31,24 +31,19 @@ FUNC (const UNIT *s, size_t n,
       const char *iso639_language,
       bool *resultp)
 {
-  UNIT normsbuf[2048 / sizeof (UNIT)];
-  UNIT *norms;
-  size_t norms_length;
-  UNIT mappedbuf[2048 / sizeof (UNIT)];
-  UNIT *mapped;
-  size_t mapped_length;
-
   /* Apply canonical decomposition to S.  */
-  norms_length = sizeof (normsbuf) / sizeof (UNIT);
-  norms = U_NORMALIZE (UNINORM_NFD, s, n, normsbuf, &norms_length);
+  UNIT normsbuf[2048 / sizeof (UNIT)];
+  size_t norms_length = sizeof (normsbuf) / sizeof (UNIT);
+  UNIT *norms = U_NORMALIZE (UNINORM_NFD, s, n, normsbuf, &norms_length);
   if (norms == NULL)
     /* errno is set here.  */
     return -1;
 
   /* Apply mapping.  */
-  mapped_length = sizeof (mappedbuf) / sizeof (UNIT);
-  mapped = mapping (norms, norms_length, iso639_language, NULL,
-                    mappedbuf, &mapped_length);
+  UNIT mappedbuf[2048 / sizeof (UNIT)];
+  size_t mapped_length = sizeof (mappedbuf) / sizeof (UNIT);
+  UNIT *mapped = mapping (norms, norms_length, iso639_language, NULL,
+                          mappedbuf, &mapped_length);
   if (mapped == NULL)
     {
       if (norms != normsbuf)
index 59dee49efb623a1dc8ae5647c1514ef100f39235..8ba68c00d7a9f7690d81674ccac955066c1bacd9 100644 (file)
@@ -50,7 +50,6 @@ read_file (FILE *stream)
   char *buf = NULL;
   int alloc = 0;
   int size = 0;
-  int count;
 
   while (! feof (stream))
     {
@@ -66,7 +65,7 @@ read_file (FILE *stream)
               exit (1);
             }
         }
-      count = fread (buf + size, 1, BUFSIZE, stream);
+      int count = fread (buf + size, 1, BUFSIZE, stream);
       if (count == 0)
         {
           if (ferror (stream))
index 352a0ef9ecc208ed3d651da58f53736212165902..333e362ff5c5749843d10cc55f12d0c89fce088c 100644 (file)
@@ -63,7 +63,6 @@ read_file (FILE *stream)
   char *buf = NULL;
   int alloc = 0;
   int size = 0;
-  int count;
 
   while (! feof (stream))
     {
@@ -79,7 +78,7 @@ read_file (FILE *stream)
               exit (1);
             }
         }
-      count = fread (buf + size, 1, BUFSIZE, stream);
+      int count = fread (buf + size, 1, BUFSIZE, stream);
       if (count == 0)
         {
           if (ferror (stream))
index c72e5d828527c6482dbc7950b2d15fdded3937a1..53b6cafafdc8a719ca1152d1fe6f227c67fa85ce 100644 (file)
@@ -50,7 +50,6 @@ read_file (FILE *stream)
   char *buf = NULL;
   int alloc = 0;
   int size = 0;
-  int count;
 
   while (! feof (stream))
     {
@@ -66,7 +65,7 @@ read_file (FILE *stream)
               exit (1);
             }
         }
-      count = fread (buf + size, 1, BUFSIZE, stream);
+      int count = fread (buf + size, 1, BUFSIZE, stream);
       if (count == 0)
         {
           if (ferror (stream))
index 2968d9892895155b6277b70bdfc8f74df563e552..e3edf64c1175f191c5aa4db709277f1684351af0 100644 (file)
@@ -63,7 +63,6 @@ read_file (FILE *stream)
   char *buf = NULL;
   int alloc = 0;
   int size = 0;
-  int count;
 
   while (! feof (stream))
     {
@@ -79,7 +78,7 @@ read_file (FILE *stream)
               exit (1);
             }
         }
-      count = fread (buf + size, 1, BUFSIZE, stream);
+      int count = fread (buf + size, 1, BUFSIZE, stream);
       if (count == 0)
         {
           if (ferror (stream))
index ced4f8e4d75b1e3a2eafb32bf939560804b0da6d..b049effdd5c7213309432b8cbef40dfac35cfab6 100644 (file)
@@ -41,14 +41,10 @@ ulc_u8_casefold (const char *s, size_t n, const char *iso639_language,
                  uninorm_t nf,
                  uint8_t *resultbuf, size_t *lengthp)
 {
-  uint8_t convbuf[2048 / sizeof (uint8_t)];
-  uint8_t *conv;
-  size_t conv_length;
-  uint8_t *result;
-
   /* Convert the string to UTF-8.  */
-  conv_length = sizeof (convbuf) / sizeof (uint8_t);
-  conv =
+  uint8_t convbuf[2048 / sizeof (uint8_t)];
+  size_t conv_length = sizeof (convbuf) / sizeof (uint8_t);
+  uint8_t *conv =
     u8_conv_from_encoding (locale_charset (), iconveh_error, s, n, NULL,
                            convbuf, &conv_length);
   if (conv == NULL)
@@ -56,8 +52,8 @@ ulc_u8_casefold (const char *s, size_t n, const char *iso639_language,
     return NULL;
 
   /* Case-fold and normalize.  */
-  result = u8_casefold (conv, conv_length, iso639_language, nf,
-                        resultbuf, lengthp);
+  uint8_t *result = u8_casefold (conv, conv_length, iso639_language, nf,
+                                 resultbuf, lengthp);
   if (result == NULL)
     {
       if (conv != convbuf)
index f18ad5662d18aa684767e1a54473febb7d454bd2..c0961946b8f9fa1d77357df5e0ea7360efc2cd41 100644 (file)
@@ -38,14 +38,10 @@ ulc_casexfrm (const char *s, size_t n, const char *iso639_language,
               uninorm_t nf,
               char *resultbuf, size_t *lengthp)
 {
-  uint8_t convbuf[2048 / sizeof (uint8_t)];
-  uint8_t *conv;
-  size_t conv_length;
-  char *result;
-
   /* Convert the string to UTF-8.  */
-  conv_length = sizeof (convbuf) / sizeof (uint8_t);
-  conv =
+  uint8_t convbuf[2048 / sizeof (uint8_t)];
+  size_t conv_length = sizeof (convbuf) / sizeof (uint8_t);
+  uint8_t *conv =
     u8_conv_from_encoding (locale_charset (), iconveh_error, s, n, NULL,
                            convbuf, &conv_length);
   if (conv == NULL)
@@ -53,8 +49,8 @@ ulc_casexfrm (const char *s, size_t n, const char *iso639_language,
     return NULL;
 
   /* Case-fold and normalize.  */
-  result = u8_casexfrm (conv, conv_length, iso639_language, nf,
-                        resultbuf, lengthp);
+  char *result = u8_casexfrm (conv, conv_length, iso639_language, nf,
+                              resultbuf, lengthp);
   if (result == NULL)
     {
       if (conv != convbuf)
index 5c67283a27c09f9ea22c2a2047268aa117347935..740046efa016739ef45b0e0c2a87d4b23ff1ceae 100644 (file)
@@ -74,9 +74,6 @@ unicode_to_mb (unsigned int code,
   static iconv_t utf8_to_local;
 #endif
 
-  char inbuf[6];
-  int count;
-
   if (!initialized)
     {
       const char *charset = locale_charset ();
@@ -106,7 +103,8 @@ unicode_to_mb (unsigned int code,
     }
 
   /* Convert the character to UTF-8.  */
-  count = u8_uctomb ((unsigned char *) inbuf, code, sizeof (inbuf));
+  char inbuf[6];
+  int count = u8_uctomb ((unsigned char *) inbuf, code, sizeof (inbuf));
   if (count < 0)
     return failure (code, _("character out of range"), callback_arg);
 
@@ -114,21 +112,15 @@ unicode_to_mb (unsigned int code,
   if (!is_utf8)
     {
       char outbuf[25];
-      const char *inptr;
-      size_t inbytesleft;
-      char *outptr;
-      size_t outbytesleft;
-      size_t res;
-
-      inptr = inbuf;
-      inbytesleft = count;
-      outptr = outbuf;
-      outbytesleft = sizeof (outbuf);
+      const char *inptr = inbuf;
+      size_t inbytesleft = count;
+      char *outptr = outbuf;
+      size_t outbytesleft = sizeof (outbuf);
 
       /* Convert the character from UTF-8 to the locale's charset.  */
-      res = iconv (utf8_to_local,
-                   (ICONV_CONST char **)&inptr, &inbytesleft,
-                   &outptr, &outbytesleft);
+      size_t res = iconv (utf8_to_local,
+                          (ICONV_CONST char **)&inptr, &inbytesleft,
+                          &outptr, &outbytesleft);
       /* Analyze what iconv() actually did and distinguish replacements
          that are OK (no need to invoke the FAILURE callback), such as
            - replacing GREEK SMALL LETTER MU with MICRO SIGN, or
index 808726e0e3d3b9e0dc21270d2221a49fdf19aefd..a98595b1907bf102f21f2f9c2320a9405fc5d1dd 100644 (file)
@@ -50,16 +50,14 @@ FUNC (const char *fromcode,
   *lengthp = length / sizeof (UNIT);
   return (UNIT *) result;
 #else
-  uint8_t *utf8_string;
   size_t utf8_length;
-  UNIT *result;
-
-  utf8_string =
+  uint8_t *utf8_string =
     u8_conv_from_encoding (fromcode, handler, src, srclen, offsets,
                            NULL, &utf8_length);
   if (utf8_string == NULL)
     return NULL;
-  result = U8_TO_U (utf8_string, utf8_length, resultbuf, lengthp);
+
+  UNIT *result = U8_TO_U (utf8_string, utf8_length, resultbuf, lengthp);
   if (result == NULL)
     {
       int saved_errno = errno;
@@ -71,9 +69,9 @@ FUNC (const char *fromcode,
     {
       size_t length = *lengthp;
       size_t *offsets_end = offsets + srclen;
-      size_t off8 = 0;  /* offset into utf8_string */
-      size_t offunit = 0;       /* offset into result */
 
+      size_t off8 = 0;          /* offset into utf8_string */
+      size_t offunit = 0;       /* offset into result */
       for (size_t *o = offsets; o < offsets_end; o++)
         if (*o != (size_t)(-1))
           {
index 723e8207dae01cc670e3ca2744d17c4ec937c6a9..e12336f044e0df2cfac1593fcf5554ec18d06703 100644 (file)
@@ -31,9 +31,6 @@ FUNC (const char *tocode,
 {
 #if HAVE_UTF_NAME
   size_t *scaled_offsets;
-  char *result;
-  size_t length;
-
   if (offsets != NULL && srclen > 0)
     {
       scaled_offsets =
@@ -47,8 +44,8 @@ FUNC (const char *tocode,
   else
     scaled_offsets = NULL;
 
-  result = resultbuf;
-  length = *lengthp;
+  char *result = resultbuf;
+  size_t length = *lengthp;
   if (mem_iconveha ((const char *) src, srclen * sizeof (UNIT),
                     UTF_NAME, tocode,
                     handler == iconveh_question_mark, handler,
@@ -83,16 +80,12 @@ FUNC (const char *tocode,
 #else
   uint8_t tmpbuf[4096];
   size_t tmpbufsize = SIZEOF (tmpbuf);
-  uint8_t *utf8_src;
-  size_t utf8_srclen;
-  size_t *scaled_offsets;
-  char *result;
-
-  utf8_src = U_TO_U8 (src, srclen, tmpbuf, &tmpbufsize);
+  uint8_t *utf8_src = U_TO_U8 (src, srclen, tmpbuf, &tmpbufsize);
   if (utf8_src == NULL)
     return NULL;
-  utf8_srclen = tmpbufsize;
+  size_t utf8_srclen = tmpbufsize;
 
+  size_t *scaled_offsets;
   if (offsets != NULL && utf8_srclen > 0)
     {
       scaled_offsets = (size_t *) malloc (utf8_srclen * sizeof (size_t));
@@ -107,8 +100,8 @@ FUNC (const char *tocode,
   else
     scaled_offsets = NULL;
 
-  result = u8_conv_to_encoding (tocode, handler, utf8_src, utf8_srclen,
-                                scaled_offsets, resultbuf, lengthp);
+  char *result = u8_conv_to_encoding (tocode, handler, utf8_src, utf8_srclen,
+                                      scaled_offsets, resultbuf, lengthp);
   if (result == NULL)
     {
       int saved_errno = errno;
@@ -123,20 +116,14 @@ FUNC (const char *tocode,
       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 */
-
-      iunit = 0;
-      i8 = 0;
+      size_t iunit = 0;         /* offset into src */
+      size_t i8 = 0;            /* offset into utf8_src */
       while (iunit < srclen && i8 < utf8_srclen)
         {
-          int countunit;
-          int count8;
-
           offsets[iunit] = scaled_offsets[i8];
 
-          countunit = U_MBLEN (src + iunit, srclen - iunit);
-          count8 = u8_mblen (utf8_src + i8, utf8_srclen - i8);
+          int countunit = U_MBLEN (src + iunit, srclen - iunit);
+          int count8 = u8_mblen (utf8_src + i8, utf8_srclen - i8);
           if (countunit < 0 || count8 < 0)
             abort ();
           iunit += countunit;
index 2d1e4ce6180f45efc2af5239dbedc24ea4effd9c..09481a15ce19a4d4785c8152e0ec4e5c8ac319a5 100644 (file)
@@ -19,10 +19,8 @@ FUNC (const char *string,
       const char *fromcode,
       enum iconv_ilseq_handler handler)
 {
-  UNIT *result;
   size_t length;
-
-  result =
+  UNIT *result =
     U_CONV_FROM_ENCODING (fromcode, handler,
                           string, strlen (string) + 1, NULL,
                           NULL, &length);
index 91b8e1a9da1890ca49aa80bab254c29a4c492b09..8235d2daae809caa511a20abefd3484809956a98 100644 (file)
@@ -47,13 +47,10 @@ FUNC (const UNIT *string,
 #else
   uint8_t tmpbuf[4096];
   size_t tmpbufsize = SIZEOF (tmpbuf);
-  uint8_t *utf8_string;
-  char *result;
-
-  utf8_string = U_TO_U8 (string, U_STRLEN (string) + 1, tmpbuf, &tmpbufsize);
+  uint8_t *utf8_string = U_TO_U8 (string, U_STRLEN (string) + 1, tmpbuf, &tmpbufsize);
   if (utf8_string == NULL)
     return NULL;
-  result = u8_strconv_to_encoding (utf8_string, tocode, handler);
+  char *result = u8_strconv_to_encoding (utf8_string, tocode, handler);
   if (result == NULL)
     {
       if (utf8_string != tmpbuf)
index f44e90f0108f2c93e1931c51c9c40b7194cd411c..541ad069dd3a1be5dd1a9cd3afbd38437240aba3 100644 (file)
@@ -62,11 +62,10 @@ static DST_UNIT *
 FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
 {
   const SRC_UNIT *s_end = s + n;
+
   /* Output string accumulator.  */
   DST_UNIT *result;
   size_t allocated;
-  size_t length;
-
   if (resultbuf != NULL)
     {
       result = resultbuf;
@@ -77,18 +76,16 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
       result = NULL;
       allocated = 0;
     }
-  length = 0;
+  size_t length = 0;
   /* Invariants:
      result is either == resultbuf or == NULL or malloc-allocated.
      If length > 0, then result != NULL.  */
 
   while (s < s_end)
     {
-      ucs4_t uc;
-      int count;
-
       /* Fetch a Unicode character from the input string.  */
-      count = u16_mbtoucr (&uc, s, s_end - s);
+      ucs4_t uc;
+      int count = u16_mbtoucr (&uc, s, s_end - s);
       if (count < 0)
         {
           if (count == -2)
@@ -112,11 +109,11 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
         }
       if (count == -2)
         {
-          DST_UNIT *memory;
-
           allocated = (allocated > 0 ? 2 * allocated : 12);
           if (length + 6 > allocated)
             allocated = length + 6;
+
+          DST_UNIT *memory;
           if (result == resultbuf || result == NULL)
             memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT));
           else
@@ -157,9 +154,8 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
   else if (result != resultbuf && length < allocated)
     {
       /* Shrink the allocated memory if possible.  */
-      DST_UNIT *memory;
-
-      memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT));
+      DST_UNIT *memory =
+        (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT));
       if (memory != NULL)
         result = memory;
     }
index 57df9a3b606f9d216d5bb058ebcccd96a3fff5a3..e6e0c2cdec0bfb8a0cb30e06b821f03a64a15eb2 100644 (file)
@@ -39,7 +39,6 @@ u8_conv_from_encoding (const char *fromcode,
   if (STRCASEEQ (fromcode, "UTF-8", 'U','T','F','-','8',0,0,0,0))
     {
       /* Conversion from UTF-8 to UTF-8.  No need to go through iconv().  */
-      uint8_t *result;
 
       if (u8_check ((const uint8_t *) src, srclen))
         {
@@ -61,6 +60,7 @@ u8_conv_from_encoding (const char *fromcode,
           }
 
       /* Memory allocation.  */
+      uint8_t *result;
       if (resultbuf != NULL && *lengthp >= srclen)
         result = resultbuf;
       else
index bd6c150c14c9cdf3a2291b98c72db0506e5009c5..6b19c24a7247897b2b840ca2b36d4ba3e567ea91 100644 (file)
@@ -46,8 +46,6 @@ u8_conv_to_encoding (const char *tocode,
 {
   if (STRCASEEQ (tocode, "UTF-8", 'U','T','F','-','8',0,0,0,0))
     {
-      char *result;
-
       /* Conversion from UTF-8 to UTF-8.  No need to go through iconv().  */
       if (u8_check (src, srclen))
         {
@@ -56,6 +54,7 @@ u8_conv_to_encoding (const char *tocode,
         }
 
       /* Memory allocation.  */
+      char *result;
       if (resultbuf != NULL && *lengthp >= srclen)
         result = resultbuf;
       else
index d346c482a79dd368f7af4c950d2c0af187769b6a..f7f0d76bbd9aa538a50bc2c81e0c75b32af15b85 100644 (file)
@@ -42,19 +42,16 @@ u8_strconv_to_encoding (const uint8_t *string,
                         const char *tocode,
                         enum iconv_ilseq_handler handler)
 {
-  char *result;
-  size_t length;
-
   if (STRCASEEQ (tocode, "UTF-8", 'U','T','F','-','8',0,0,0,0))
     {
       /* Conversion from UTF-8 to UTF-8.  No need to go through iconv().  */
-      length = u8_strlen (string) + 1;
+      size_t length = u8_strlen (string) + 1;
       if (u8_check (string, length))
         {
           errno = EILSEQ;
           return NULL;
         }
-      result = (char *) malloc (length);
+      char *result = (char *) malloc (length);
       if (result == NULL)
         {
           errno = ENOMEM;
@@ -65,8 +62,8 @@ u8_strconv_to_encoding (const uint8_t *string,
     }
   else
     {
-      result = NULL;
-      length = 0;
+      char *result = NULL;
+      size_t length = 0;
       if (mem_iconveha ((const char *) string, u8_strlen (string) + 1,
                         "UTF-8", tocode,
                         handler == iconveh_question_mark, handler,
index b309253f6ac8d4e66b827a8214b47caa0d0be298..f325737d1fc98c8265868305d93d341f4b8df6b4 100644 (file)
@@ -113,7 +113,6 @@ 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 i1, i2;
 
   if (value == CONCAT(TABLE,_get) (t, wc))
     return;
@@ -142,8 +141,8 @@ CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc, ELEMENT value)
                                              (alloc << t->q) * sizeof (uint32_t));
           t->level2_alloc = alloc;
         }
-      i1 = t->level2_size << t->q;
-      i2 = (t->level2_size + 1) << t->q;
+      size_t i1 = t->level2_size << t->q;
+      size_t i2 = (t->level2_size + 1) << t->q;
       for (size_t i = i1; i < i2; i++)
         t->level2[i] = EMPTY;
       t->level1[index1] = t->level2_size++;
@@ -160,8 +159,8 @@ CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc, ELEMENT value)
                                             (alloc << t->p) * sizeof (ELEMENT));
           t->level3_alloc = alloc;
         }
-      i1 = t->level3_size << t->p;
-      i2 = (t->level3_size + 1) << t->p;
+      size_t i1 = t->level3_size << t->p;
+      size_t i2 = (t->level3_size + 1) << t->p;
       for (size_t i = i1; i < i2; i++)
         t->level3[i] = DEFAULT;
       t->level2[index2] = t->level3_size++;
@@ -209,63 +208,68 @@ CONCAT(TABLE,_iterate) (struct TABLE *t,
 static void
 CONCAT(TABLE,_finalize) (struct TABLE *t)
 {
-  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 (size_t j = 0; j < t->level3_size; j++)
+  {
+    uint32_t reorder3[t->level3_size];
     {
-      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)))
-          break;
-      /* Relocate block j to block i.  */
-      reorder3[j] = i;
-      if (i == k)
+      size_t k = 0;
+      for (size_t j = 0; j < t->level3_size; j++)
         {
-          if (i != j)
-            memcpy (&t->level3[i << t->p], &t->level3[j << t->p],
-                    (1 << t->p) * sizeof (ELEMENT));
-          k++;
+          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)))
+              break;
+          /* Relocate block j to block i.  */
+          reorder3[j] = i;
+          if (i == k)
+            {
+              if (i != j)
+                memcpy (&t->level3[i << t->p], &t->level3[j << t->p],
+                        (1 << t->p) * sizeof (ELEMENT));
+              k++;
+            }
         }
+      t->level3_size = k;
     }
-  t->level3_size = k;
 
-  for (size_t i = 0; i < (t->level2_size << t->q); i++)
-    if (t->level2[i] != EMPTY)
-      t->level2[i] = reorder3[t->level2[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 (size_t j = 0; j < t->level2_size; j++)
+  {
+    uint32_t reorder2[t->level2_size];
     {
-      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)))
-          break;
-      /* Relocate block j to block i.  */
-      reorder2[j] = i;
-      if (i == k)
+      size_t k = 0;
+      for (size_t j = 0; j < t->level2_size; j++)
         {
-          if (i != j)
-            memcpy (&t->level2[i << t->q], &t->level2[j << t->q],
-                    (1 << t->q) * sizeof (uint32_t));
-          k++;
+          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)))
+              break;
+          /* Relocate block j to block i.  */
+          reorder2[j] = i;
+          if (i == k)
+            {
+              if (i != j)
+                memcpy (&t->level2[i << t->q], &t->level2[j << t->q],
+                        (1 << t->q) * sizeof (uint32_t));
+              k++;
+            }
         }
+      t->level2_size = k;
     }
-  t->level2_size = k;
 
-  for (size_t i = 0; i < t->level1_size; i++)
-    if (t->level1[i] != EMPTY)
-      t->level1[i] = reorder2[t->level1[i]];
+    for (size_t i = 0; i < t->level1_size; i++)
+      if (t->level1[i] != EMPTY)
+        t->level1[i] = reorder2[t->level1[i]];
+  }
 
   /* Create and fill the resulting compressed representation.  */
-  last_offset =
+  uint32_t last_offset =
     5 * sizeof (uint32_t)
     + t->level1_size * sizeof (uint32_t)
     + (t->level2_size << t->q) * sizeof (uint32_t)
@@ -273,12 +277,12 @@ CONCAT(TABLE,_finalize) (struct TABLE *t)
   t->result_size = (last_offset + 3) & ~3ul;
   t->result = (char *) xmalloc (t->result_size);
 
-  level1_offset =
+  uint32_t level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  uint32_t level2_offset =
     5 * sizeof (uint32_t)
     + t->level1_size * sizeof (uint32_t);
-  level3_offset =
+  uint32_t level3_offset =
     5 * sizeof (uint32_t)
     + t->level1_size * sizeof (uint32_t)
     + (t->level2_size << t->q) * sizeof (uint32_t);
index 0af9be9b71045c91dd36f33bcc7b00876752e528..d99a988833849c480be1763048527cf4c627ea0d 100644 (file)
@@ -112,7 +112,6 @@ 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 i1, i2;
 
   if (index1 >= t->level1_size)
     {
@@ -138,8 +137,8 @@ CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc)
                                              (alloc << t->q) * sizeof (uint32_t));
           t->level2_alloc = alloc;
         }
-      i1 = t->level2_size << t->q;
-      i2 = (t->level2_size + 1) << t->q;
+      size_t i1 = t->level2_size << t->q;
+      size_t i2 = (t->level2_size + 1) << t->q;
       for (size_t i = i1; i < i2; i++)
         t->level2[i] = EMPTY;
       t->level1[index1] = t->level2_size++;
@@ -156,8 +155,8 @@ CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc)
                                             (alloc << t->p) * sizeof (uint32_t));
           t->level3_alloc = alloc;
         }
-      i1 = t->level3_size << t->p;
-      i2 = (t->level3_size + 1) << t->p;
+      size_t i1 = t->level3_size << t->p;
+      size_t i2 = (t->level3_size + 1) << t->p;
       for (size_t i = i1; i < i2; i++)
         t->level3[i] = 0;
       t->level2[index2] = t->level3_size++;
@@ -204,60 +203,67 @@ CONCAT(TABLE,_iterate) (struct TABLE *t, void (*fn) (uint32_t wc))
 static void
 CONCAT(TABLE,_finalize) (struct TABLE *t)
 {
-  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 (size_t j = 0; j < t->level3_size; j++)
+  {
+    uint32_t reorder3[t->level3_size];
     {
-      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)))
-          break;
-      /* Relocate block j to block i.  */
-      reorder3[j] = i;
-      if (i == k)
+      size_t k = 0;
+      for (size_t j = 0; j < t->level3_size; j++)
         {
-          if (i != j)
-            memcpy (&t->level3[i << t->p], &t->level3[j << t->p],
-                    (1 << t->p) * sizeof (uint32_t));
-          k++;
+          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)))
+              break;
+          /* Relocate block j to block i.  */
+          reorder3[j] = i;
+          if (i == k)
+            {
+              if (i != j)
+                memcpy (&t->level3[i << t->p], &t->level3[j << t->p],
+                        (1 << t->p) * sizeof (uint32_t));
+              k++;
+            }
         }
+      t->level3_size = k;
     }
-  t->level3_size = k;
 
-  for (size_t i = 0; i < (t->level2_size << t->q); i++)
-    if (t->level2[i] != EMPTY)
-      t->level2[i] = reorder3[t->level2[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 (size_t j = 0; j < t->level2_size; j++)
+  {
+    uint32_t reorder2[t->level2_size];
     {
-      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)))
-          break;
-      /* Relocate block j to block i.  */
-      reorder2[j] = i;
-      if (i == k)
+      size_t k = 0;
+      for (size_t j = 0; j < t->level2_size; j++)
         {
-          if (i != j)
-            memcpy (&t->level2[i << t->q], &t->level2[j << t->q],
-                    (1 << t->q) * sizeof (uint32_t));
-          k++;
+          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)))
+              break;
+          /* Relocate block j to block i.  */
+          reorder2[j] = i;
+          if (i == k)
+            {
+              if (i != j)
+                memcpy (&t->level2[i << t->q], &t->level2[j << t->q],
+                        (1 << t->q) * sizeof (uint32_t));
+              k++;
+            }
         }
+      t->level2_size = k;
     }
-  t->level2_size = k;
 
-  for (size_t i = 0; i < t->level1_size; i++)
-    if (t->level1[i] != EMPTY)
-      t->level1[i] = reorder2[t->level1[i]];
+    for (size_t i = 0; i < t->level1_size; i++)
+      if (t->level1[i] != EMPTY)
+        t->level1[i] = reorder2[t->level1[i]];
+  }
 
   /* Create and fill the resulting compressed representation.  */
   t->result_size =
@@ -267,12 +273,12 @@ CONCAT(TABLE,_finalize) (struct TABLE *t)
     + (t->level3_size << t->p) * sizeof (uint32_t);
   t->result = (char *) xmalloc (t->result_size);
 
-  level1_offset =
+  uint32_t level1_offset =
     5 * sizeof (uint32_t);
-  level2_offset =
+  uint32_t level2_offset =
     5 * sizeof (uint32_t)
     + t->level1_size * sizeof (uint32_t);
-  level3_offset =
+  uint32_t level3_offset =
     5 * sizeof (uint32_t)
     + t->level1_size * sizeof (uint32_t)
     + (t->level2_size << t->q) * sizeof (uint32_t);
index a4175604ef7d357e287966eb28d1529820bf421a..a4ad28e35377265829d949b659dd8b9294b28311 100644 (file)
 int
 uc_bidi_class_byname (const char *bidi_class_name)
 {
-  size_t len;
-
-  len = strlen (bidi_class_name);
+  size_t len = strlen (bidi_class_name);
   if (len <= MAX_WORD_LENGTH)
     {
       char buf[MAX_WORD_LENGTH + 1];
-      const struct named_bidi_class *found;
 
       /* Copy bidi_class_name into buf, converting '_' and '-' to ' '.  */
       {
@@ -62,7 +59,7 @@ uc_bidi_class_byname (const char *bidi_class_name)
       /* Here q == buf + len.  */
 
       /* Do a hash table lookup, with case-insensitive comparison.  */
-      found = uc_bidi_class_lookup (buf, len);
+      const struct named_bidi_class *found = uc_bidi_class_lookup (buf, len);
       if (found != NULL)
         return found->bidi_class;
     }
index 35d3991e2048e88bf4246b384f1e5314b6c573cc..3d4e6a891cc75a2e708cfe21ab0b138eb3261853 100644 (file)
@@ -32,10 +32,7 @@ uc_general_category_t
 uc_general_category_and (uc_general_category_t category1,
                          uc_general_category_t category2)
 {
-  uint32_t bitmask;
-  uc_general_category_t result;
-
-  bitmask = category1.bitmask & category2.bitmask;
+  uint32_t bitmask = category1.bitmask & category2.bitmask;
 
   if (bitmask == category1.bitmask)
     return category1;
@@ -46,6 +43,7 @@ uc_general_category_and (uc_general_category_t category1,
   if (bitmask == 0)
     return _UC_CATEGORY_NONE;
 
+  uc_general_category_t result;
   result.bitmask = bitmask;
   result.generic = 1;
   result.lookup.lookup_fn = &uc_is_general_category_withtable;
index d771de1b600f450b46f2883f33e4f1f50c2accba..af547c0dafb6ecf3c41a4a99ab867dbfcc34f59f 100644 (file)
@@ -32,10 +32,7 @@ uc_general_category_t
 uc_general_category_and_not (uc_general_category_t category1,
                              uc_general_category_t category2)
 {
-  uint32_t bitmask;
-  uc_general_category_t result;
-
-  bitmask = category1.bitmask & ~category2.bitmask;
+  uint32_t bitmask = category1.bitmask & ~category2.bitmask;
 
   if (bitmask == category1.bitmask)
     return category1;
@@ -43,6 +40,7 @@ uc_general_category_and_not (uc_general_category_t category1,
   if (bitmask == 0)
     return _UC_CATEGORY_NONE;
 
+  uc_general_category_t result;
   result.bitmask = bitmask;
   result.generic = 1;
   result.lookup.lookup_fn = &uc_is_general_category_withtable;
index cb6123868d330f035b48d2979cffb8d37e8ffa61..20750c3056804843470927513a864b3f80a0f07a 100644 (file)
@@ -81,13 +81,10 @@ enum
 uc_general_category_t
 uc_general_category_byname (const char *category_name)
 {
-  size_t len;
-
-  len = strlen (category_name);
+  size_t len = strlen (category_name);
   if (len <= MAX_WORD_LENGTH)
     {
       char buf[MAX_WORD_LENGTH + 1];
-      const struct named_category *found;
 
       /* Copy category_name into buf, converting '_' and '-' to ' '.  */
       {
@@ -108,7 +105,8 @@ uc_general_category_byname (const char *category_name)
       /* Here q == buf + len.  */
 
       /* Do a hash table lookup, with case-insensitive comparison.  */
-      found = uc_general_category_lookup (buf, len);
+      const struct named_category *found =
+        uc_general_category_lookup (buf, len);
       if (found != NULL)
         /* Use a 'switch' statement here, because a table would introduce
            load-time relocations.  */
index 0fe94567cc9a9d9e32ac12e2f32480f56b2911dc..96d00910c2429eec5644885eec63cd622fa6ca89 100644 (file)
@@ -68,10 +68,10 @@ uc_general_category_t
 uc_general_category (ucs4_t uc)
 {
   int bit = lookup_withtable (uc);
-  uc_general_category_t result;
 
   if (bit >= 0)
     {
+      uc_general_category_t result;
       result.bitmask = 1 << bit;
       result.generic = 1;
       result.lookup.lookup_fn = &uc_is_general_category_withtable;
index 89c3f922ee1362121ad1ed844aee09a0c23e043a..2ea25a1eaaace4df0fa9fdb31dc2baee8e7408b9 100644 (file)
@@ -32,10 +32,7 @@ uc_general_category_t
 uc_general_category_or (uc_general_category_t category1,
                         uc_general_category_t category2)
 {
-  uint32_t bitmask;
-  uc_general_category_t result;
-
-  bitmask = category1.bitmask | category2.bitmask;
+  uint32_t bitmask = category1.bitmask | category2.bitmask;
 
   if (bitmask == category1.bitmask)
     return category1;
@@ -43,6 +40,7 @@ uc_general_category_or (uc_general_category_t category1,
   if (bitmask == category2.bitmask)
     return category2;
 
+  uc_general_category_t result;
   result.bitmask = bitmask;
   result.generic = 1;
   result.lookup.lookup_fn = &uc_is_general_category_withtable;
index ee162607d6797f4d9397befaef2c4a80264eeeb7..77e65524faa14c18fdef07ee8b84740d4167ea1a 100644 (file)
 int
 uc_combining_class_byname (const char *ccc_name)
 {
-  size_t len;
-
-  len = strlen (ccc_name);
+  size_t len = strlen (ccc_name);
   if (len <= MAX_WORD_LENGTH)
     {
       char buf[MAX_WORD_LENGTH + 1];
-      const struct named_combining_class *found;
 
       /* Copy ccc_name into buf, converting '_' and '-' to ' '.  */
       {
@@ -62,7 +59,8 @@ uc_combining_class_byname (const char *ccc_name)
       /* Here q == buf + len.  */
 
       /* Do a hash table lookup, with case-insensitive comparison.  */
-      found = uc_combining_class_lookup (buf, len);
+      const struct named_combining_class *found =
+        uc_combining_class_lookup (buf, len);
       if (found != NULL)
         return found->combining_class;
     }
index ae343b6f568fd6588752dffd8b28ed33cdc49268..d87c3ccf3fd840ac59f959e872a3e78e5daadcb6 100644 (file)
@@ -118,7 +118,6 @@ uc_combining_class_long_name (int ccc)
   if (ccc >= 0)
     {
       int index;
-
       if (ccc < 10)
         index = u_combining_class_index_part1[ccc];
       else if (ccc >= 200 && ccc < 241)
index fdc0cc003aced4e79eb0b234a9b30c54dbbb28fe..689c6f5619dbc01c80373fc158e8cd93186bf537 100644 (file)
@@ -118,7 +118,6 @@ uc_combining_class_name (int ccc)
   if (ccc >= 0)
     {
       int index;
-
       if (ccc < 10)
         index = u_combining_class_index_part1[ccc];
       else if (ccc >= 200 && ccc < 241)
index 09ffd218631dc704be15c8e5170cc7dcc7b58e2b..af12884c9cc62abf9c6b7ec7c17ba5a59c0c75be 100644 (file)
 int
 uc_indic_conjunct_break_byname (const char *indic_conjunct_break_name)
 {
-  size_t len;
-
-  len = strlen (indic_conjunct_break_name);
+  size_t len = strlen (indic_conjunct_break_name);
   if (len <= MAX_WORD_LENGTH)
     {
       char buf[MAX_WORD_LENGTH + 1];
-      const struct named_indic_conjunct_break *found;
 
       /* Copy indic_conjunct_break_name into buf, converting '_' and '-'
          to ' '.  */
@@ -63,7 +60,8 @@ uc_indic_conjunct_break_byname (const char *indic_conjunct_break_name)
       /* Here q == buf + len.  */
 
       /* Do a hash table lookup, with case-insensitive comparison.  */
-      found = uc_indic_conjunct_break_lookup (buf, len);
+      const struct named_indic_conjunct_break *found =
+        uc_indic_conjunct_break_lookup (buf, len);
       if (found != NULL)
         return found->indic_conjunct_break;
     }
index 00aaaaee2ac9e55f969a1ae1abc9666641565db6..2a2444f58830149ec33731ecde29f4eb1aaa9f1b 100644 (file)
 int
 uc_joining_group_byname (const char *joining_group_name)
 {
-  size_t len;
-
-  len = strlen (joining_group_name);
+  size_t len = strlen (joining_group_name);
   if (len <= MAX_WORD_LENGTH)
     {
       char buf[MAX_WORD_LENGTH + 1];
-      const struct named_joining_group *found;
 
       /* Copy joining_group_name into buf, converting '_' and '-' to ' '.  */
       {
@@ -62,7 +59,8 @@ uc_joining_group_byname (const char *joining_group_name)
       /* Here q == buf + len.  */
 
       /* Do a hash table lookup, with case-insensitive comparison.  */
-      found = uc_joining_group_lookup (buf, len);
+      const struct named_joining_group *found =
+        uc_joining_group_lookup (buf, len);
       if (found != NULL)
         return found->joining_group;
     }
index 055869cca439fbc3ad7fa563908bc7a46a91b9e6..c3f22d52a7d3f84a8ad8733e7794ff666b2a3c32 100644 (file)
 int
 uc_joining_type_byname (const char *joining_type_name)
 {
-  size_t len;
-
-  len = strlen (joining_type_name);
+  size_t len = strlen (joining_type_name);
   if (len <= MAX_WORD_LENGTH)
     {
       char buf[MAX_WORD_LENGTH + 1];
-      const struct named_joining_type *found;
 
       /* Copy joining_type_name into buf, converting '_' and '-' to ' '.  */
       {
@@ -62,7 +59,8 @@ uc_joining_type_byname (const char *joining_type_name)
       /* Here q == buf + len.  */
 
       /* Do a hash table lookup, with case-insensitive comparison.  */
-      found = uc_joining_type_lookup (buf, len);
+      const struct named_joining_type *found =
+        uc_joining_type_lookup (buf, len);
       if (found != NULL)
         return found->joining_type;
     }
index 459ab382e3d6744be71be23a51660faf86f1eca6..b8bf13de889ca0f7dae77742ac600c265635ade4 100644 (file)
@@ -146,27 +146,29 @@ uc_property_t
 uc_property_byname (const char *property_name)
 {
   char buf[MAX_WORD_LENGTH + 1];
-  const char *cp;
   char *bp;
-  unsigned int count;
-  const struct named_property *found;
 
-  for (cp = property_name, bp = buf, count = MAX_WORD_LENGTH + 1; ; cp++, bp++)
-    {
-      unsigned char c = (unsigned char) *cp;
-      if (c >= 0x80)
-        goto invalid;
-      if (c >= 'A' && c <= 'Z')
-        c += 'a' - 'A';
-      else if (c == ' ' || c == '-')
-        c = '_';
-      *bp = c;
-      if (c == '\0')
-        break;
-      if (--count == 0)
-        goto invalid;
-    }
-  found = uc_property_lookup (buf, bp - buf);
+  {
+    const char *cp;
+    unsigned int count;
+    for (cp = property_name, bp = buf, count = MAX_WORD_LENGTH + 1; ; cp++, bp++)
+      {
+        unsigned char c = (unsigned char) *cp;
+        if (c >= 0x80)
+          goto invalid;
+        if (c >= 'A' && c <= 'Z')
+          c += 'a' - 'A';
+        else if (c == ' ' || c == '-')
+          c = '_';
+        *bp = c;
+        if (c == '\0')
+          break;
+        if (--count == 0)
+          goto invalid;
+      }
+  }
+
+  const struct named_property *found = uc_property_lookup (buf, bp - buf);
   if (found != NULL)
     /* Use a 'switch' statement here, because a table would introduce load-time
        relocations.  */
index 637623edd1d09697554159b5c7c52baab4027a79..fad525dc8f6980666e6c97a5c1658d536b7d5b88 100644 (file)
@@ -52,9 +52,8 @@ uc_script (ucs4_t uc)
 const uc_script_t *
 uc_script_byname (const char *script_name)
 {
-  const struct named_script *found;
-
-  found = uc_script_lookup (script_name, strlen (script_name));
+  const struct named_script *found =
+    uc_script_lookup (script_name, strlen (script_name));
   if (found != NULL)
     return &scripts[found->index];
   else
index 0894d5992e908b2a2588aa753910cb88c06911e5..6ffbb9fec357755f4d8e32414123c0490c719db3 100644 (file)
@@ -43,10 +43,8 @@ ends_with_incb_consonant_extended_linker_extended (const UNIT *s,
 
   while (s > s_start)
     {
-      const UNIT *prev_s;
       ucs4_t uc;
-
-      prev_s = U_PREV (&uc, s, s_start);
+      const UNIT *prev_s = U_PREV (&uc, s, s_start);
       if (prev_s == NULL)
         /* Ill-formed UTF-8 encoding. */
         break;
@@ -73,10 +71,8 @@ ends_with_emoji_modifier_sequence (const UNIT *s, const UNIT *s_start)
 {
   while (s > s_start)
     {
-      const UNIT *prev_s;
       ucs4_t uc;
-
-      prev_s = U_PREV (&uc, s, s_start);
+      const UNIT *prev_s = U_PREV (&uc, s, s_start);
       if (prev_s == NULL)
         /* Ill-formed UTF-8 encoding. */
         break;
@@ -102,10 +98,8 @@ ends_with_ri_count (const UNIT *s, const UNIT *s_start)
 
   while (s > s_start)
     {
-      const UNIT *prev_s;
       ucs4_t uc;
-
-      prev_s = U_PREV (&uc, s, s_start);
+      const UNIT *prev_s = U_PREV (&uc, s, s_start);
       if (prev_s == NULL)
         /* Ill-formed UTF-8 encoding. */
         break;
@@ -143,10 +137,8 @@ FUNC (const UNIT *s, const UNIT *s_start)
 
   do
     {
-      const UNIT *prev_s;
       ucs4_t uc;
-
-      prev_s = U_PREV (&uc, s, s_start);
+      const UNIT *prev_s = U_PREV (&uc, s, s_start);
       if (prev_s == NULL)
         {
           /* Ill-formed UTF-8 encoding. */
index 1451efa8316655fa57056f4af54f59a37d16c514..0a619f465c109ee4cc9125d581dd733cc1c0ba66 100644 (file)
@@ -118,15 +118,13 @@ static const unsigned long int gb_table[18] =
 bool
 uc_is_grapheme_break (ucs4_t a, ucs4_t b)
 {
-  int a_gcp, b_gcp;
-
   if ((a | b) < 0x300)
     {
       /* GB3 is the only relevant rule for this case. */
       return a != '\r' || b != '\n';
     }
 
-  a_gcp = uc_graphemeclusterbreak_property (a);
-  b_gcp = uc_graphemeclusterbreak_property (b);
+  int a_gcp = uc_graphemeclusterbreak_property (a);
+  int b_gcp = uc_graphemeclusterbreak_property (b);
   return (gb_table[a_gcp] >> b_gcp) & 1;
 }
index 9413bceacc126e7fb6fc6c02fbc12e68095f91ed..ae8efb60f308a61e0958c3019cd7fa7373214949 100644 (file)
@@ -90,11 +90,10 @@ ulc_grapheme_breaks (const char *s, size_t n, char *p)
 
           if (offsets != NULL)
             {
-              uint8_t *t;
               size_t m;
-
-              t = u8_conv_from_encoding (encoding, iconveh_question_mark,
-                                         s, n, offsets, NULL, &m);
+              uint8_t *t =
+                u8_conv_from_encoding (encoding, iconveh_question_mark,
+                                       s, n, offsets, NULL, &m);
               if (t != NULL)
                 {
                   char *q = (char *) (m > 0 ? malloc (m) : NULL);
index 70c31acec99b02ece14d03379f326de82ae4b359..8e1e346cb38144d5d4562de3fff7382b596e395b 100644 (file)
@@ -39,17 +39,12 @@ u16_width_linebreaks_internal (const uint16_t *s, size_t n,
                                const char *o, const char *encoding, int cr,
                                char *p)
 {
-  const uint16_t *s_end;
-  char *last_p;
-  int last_column;
-  int piece_width;
-
   u16_possible_linebreaks_loop (s, n, encoding, cr, p);
 
-  s_end = s + n;
-  last_p = NULL;
-  last_column = start_column;
-  piece_width = 0;
+  const uint16_t *s_end = s + n;
+  char *last_p = NULL;
+  int last_column = start_column;
+  int piece_width = 0;
   while (s < s_end)
     {
       ucs4_t uc;
@@ -82,8 +77,6 @@ u16_width_linebreaks_internal (const uint16_t *s, size_t n,
       else
         {
           /* uc is not a line break character.  */
-          int w;
-
           if (*p == UC_BREAK_POSSIBLE)
             {
               /* Start a new piece.  */
@@ -96,7 +89,7 @@ u16_width_linebreaks_internal (const uint16_t *s, size_t n,
 
           *p = UC_BREAK_PROHIBITED;
 
-          w = uc_width (uc, encoding);
+          int w = uc_width (uc, encoding);
           if (w >= 0) /* ignore control characters in the string */
             piece_width += w;
         }
index 5fa736395a53b8522ed8f3cf55b532a876e44fa1..c70212d81475f85714fa2ded8e658e6b93c133e6 100644 (file)
@@ -38,17 +38,12 @@ u32_width_linebreaks_internal (const uint32_t *s, size_t n,
                               const char *o, const char *encoding, int cr,
                               char *p)
 {
-  const uint32_t *s_end;
-  char *last_p;
-  int last_column;
-  int piece_width;
-
   u32_possible_linebreaks_loop (s, n, encoding, cr, p);
 
-  s_end = s + n;
-  last_p = NULL;
-  last_column = start_column;
-  piece_width = 0;
+  const uint32_t *s_end = s + n;
+  char *last_p = NULL;
+  int last_column = start_column;
+  int piece_width = 0;
   while (s < s_end)
     {
       ucs4_t uc = *s;
@@ -80,8 +75,6 @@ u32_width_linebreaks_internal (const uint32_t *s, size_t n,
       else
         {
           /* uc is not a line break character.  */
-          int w;
-
           if (*p == UC_BREAK_POSSIBLE)
             {
               /* Start a new piece.  */
@@ -94,7 +87,7 @@ u32_width_linebreaks_internal (const uint32_t *s, size_t n,
 
           *p = UC_BREAK_PROHIBITED;
 
-          w = uc_width (uc, encoding);
+          int w = uc_width (uc, encoding);
           if (w >= 0) /* ignore control characters in the string */
             piece_width += w;
         }
index e895304a0fe3303de5542ac7d0ebab430c7a8591..9d1e772cd3c5227a90d8dd6c01682be879709146 100644 (file)
@@ -457,7 +457,6 @@ read_file (FILE *stream)
   char *buf = NULL;
   int alloc = 0;
   int size = 0;
-  int count;
 
   while (! feof (stream))
     {
@@ -473,7 +472,7 @@ read_file (FILE *stream)
               exit (1);
             }
         }
-      count = fread (buf + size, 1, BUFSIZE, stream);
+      int count = fread (buf + size, 1, BUFSIZE, stream);
       if (count == 0)
         {
           if (ferror (stream))
index 192f2e6583e0916357e917957ceb5059bfb6491f..1f7a91672f666ad9d0506ddabe24d224b48a6d42 100644 (file)
@@ -39,17 +39,12 @@ u8_width_linebreaks_internal (const uint8_t *s, size_t n,
                               const char *o, const char *encoding, int cr,
                               char *p)
 {
-  const uint8_t *s_end;
-  char *last_p;
-  int last_column;
-  int piece_width;
-
   u8_possible_linebreaks_loop (s, n, encoding, cr, p);
 
-  s_end = s + n;
-  last_p = NULL;
-  last_column = start_column;
-  piece_width = 0;
+  const uint8_t *s_end = s + n;
+  char *last_p = NULL;
+  int last_column = start_column;
+  int piece_width = 0;
   while (s < s_end)
     {
       ucs4_t uc;
@@ -82,8 +77,6 @@ u8_width_linebreaks_internal (const uint8_t *s, size_t n,
       else
         {
           /* uc is not a line break character.  */
-          int w;
-
           if (*p == UC_BREAK_POSSIBLE)
             {
               /* Start a new piece.  */
@@ -96,7 +89,7 @@ u8_width_linebreaks_internal (const uint8_t *s, size_t n,
 
           *p = UC_BREAK_PROHIBITED;
 
-          w = uc_width (uc, encoding);
+          int w = uc_width (uc, encoding);
           if (w >= 0) /* ignore control characters in the string */
             piece_width += w;
         }
@@ -163,7 +156,6 @@ read_file (FILE *stream)
   char *buf = NULL;
   int alloc = 0;
   int size = 0;
-  int count;
 
   while (! feof (stream))
     {
@@ -179,7 +171,7 @@ read_file (FILE *stream)
               exit (1);
             }
         }
-      count = fread (buf + size, 1, BUFSIZE, stream);
+      int count = fread (buf + size, 1, BUFSIZE, stream);
       if (count == 0)
         {
           if (ferror (stream))
index 852e8ab3cfe62fe217ffd9eb056be3ca86d3fc9b..9e212086049a1e648b8c7e72d510135eedbf99b9 100644 (file)
@@ -66,11 +66,10 @@ ulc_possible_linebreaks_internal (const char *s, size_t n, const char *encoding,
 
           if (offsets != NULL)
             {
-              uint8_t *t;
               size_t m;
-
-              t = u8_conv_from_encoding (encoding, iconveh_question_mark,
-                                         s, n, offsets, NULL, &m);
+              uint8_t *t =
+                u8_conv_from_encoding (encoding, iconveh_question_mark,
+                                       s, n, offsets, NULL, &m);
               if (t != NULL)
                 {
                   char *q = (char *) (m > 0 ? malloc (m) : NULL);
@@ -167,7 +166,6 @@ read_file (FILE *stream)
   char *buf = NULL;
   int alloc = 0;
   int size = 0;
-  int count;
 
   while (! feof (stream))
     {
@@ -183,7 +181,7 @@ read_file (FILE *stream)
               exit (1);
             }
         }
-      count = fread (buf + size, 1, BUFSIZE, stream);
+      int count = fread (buf + size, 1, BUFSIZE, stream);
       if (count == 0)
         {
           if (ferror (stream))
index dcce0c774dc79a0b9351e36afb9d4fa36a89ab6a..994192588216297ee01046851b182f70732341a6 100644 (file)
@@ -68,11 +68,10 @@ ulc_width_linebreaks_internal (const char *s, size_t n,
 
           if (offsets != NULL)
             {
-              uint8_t *t;
               size_t m;
-
-              t = u8_conv_from_encoding (encoding, iconveh_question_mark,
-                                         s, n, offsets, NULL, &m);
+              uint8_t *t =
+                u8_conv_from_encoding (encoding, iconveh_question_mark,
+                                       s, n, offsets, NULL, &m);
               if (t != NULL)
                 {
                   char *memory =
@@ -82,7 +81,6 @@ 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;
 
                       /* Translate the overrides to the UTF-8 string.  */
                       if (o != NULL)
@@ -94,7 +92,7 @@ ulc_width_linebreaks_internal (const char *s, size_t n,
                         }
 
                       /* Determine the line breaks of the UTF-8 string.  */
-                      res_column =
+                      int res_column =
                         u8_width_linebreaks_internal (t, m, width, start_column, at_end_columns, o8, encoding, cr, q);
 
                       /* Translate the result back to the original string.  */
@@ -194,7 +192,6 @@ read_file (FILE *stream)
   char *buf = NULL;
   int alloc = 0;
   int size = 0;
-  int count;
 
   while (! feof (stream))
     {
@@ -210,7 +207,7 @@ read_file (FILE *stream)
               exit (1);
             }
         }
-      count = fread (buf + size, 1, BUFSIZE, stream);
+      int count = fread (buf + size, 1, BUFSIZE, stream);
       if (count == 0)
         {
           if (ferror (stream))
index 0a4157ed0cdf8cbd1d8b2fbcbc67cc224a4ef39f..f1606df8b5292e09289b1be1f4610f616ee216b4 100644 (file)
@@ -65,9 +65,6 @@
 static const char *
 unicode_name_word (unsigned int index, unsigned int *lengthp)
 {
-  unsigned int i1;
-  unsigned int i2;
-
   assert (index < UNICODE_CHARNAME_NUM_WORDS);
 
   /* Binary search for i with
@@ -76,8 +73,8 @@ unicode_name_word (unsigned int index, unsigned int *lengthp)
        index < unicode_name_by_length[i+1].ind_offset
    */
 
-  i1 = 0;
-  i2 = SIZEOF (unicode_name_by_length) - 1;
+  unsigned int i1 = 0;
+  unsigned int i2 = SIZEOF (unicode_name_by_length) - 1;
   while (i2 - i1 > 1)
     {
       unsigned int i = (i1 + i2) >> 1;
@@ -238,22 +235,17 @@ unicode_character_name (ucs4_t c, char *buf)
   if (c >= 0xAC00 && c <= 0xD7A3)
     {
       /* Special case for Hangul syllables. Keeps the tables small.  */
-      char *ptr;
-      unsigned int tmp;
-      unsigned int index1;
-      unsigned int index2;
-      unsigned int index3;
-      const char *q;
 
       /* buf needs to have at least 16 + 7 + 1 bytes here.  */
       memcpy (buf, "HANGUL SYLLABLE ", 16);
-      ptr = buf + 16;
+      char *ptr = buf + 16;
 
-      tmp = c - 0xAC00;
-      index3 = tmp % 28; tmp = tmp / 28;
-      index2 = tmp % 21; tmp = tmp / 21;
-      index1 = tmp;
+      unsigned int tmp = c - 0xAC00;
+      unsigned int index3 = tmp % 28; tmp = tmp / 28;
+      unsigned int index2 = tmp % 21; tmp = tmp / 21;
+      unsigned int index1 = tmp;
 
+      const char *q;
       q = jamo_initial_short_name[index1];
       while (*q != '\0')
         *ptr++ = *q++;
@@ -271,11 +263,10 @@ unicode_character_name (ucs4_t c, char *buf)
     {
       /* Special case for CJK compatibility ideographs. Keeps the tables
          small.  */
-      char *ptr;
 
       /* buf needs to have at least 28 + 5 + 1 bytes here.  */
       memcpy (buf, "CJK COMPATIBILITY IDEOGRAPH-", 28);
-      ptr = buf + 28;
+      char *ptr = buf + 28;
 
       for (int i = (c < 0x10000 ? 12 : 16); i >= 0; i -= 4)
         {
@@ -423,11 +414,10 @@ unicode_name_character (const char *name)
               for (;;)
                 {
                   {
-                    int word;
                     const char *p2 = p1;
                     while (p2 < ptr && *p2 != ' ')
                       p2++;
-                    word = unicode_name_word_lookup (p1, p2 - p1);
+                    int word = unicode_name_word_lookup (p1, p2 - p1);
                     if (word < 0)
                       break;
                     if (wordptr == &words[UNICODE_CHARNAME_MAX_WORDS])
@@ -447,11 +437,7 @@ unicode_name_character (const char *name)
                            2) [AEIOUWY]
                            3) [BCDGHIJKLMNPST]
                        */
-                      const char *p2;
-                      const char *p3;
-                      const char *p4;
-
-                      p2 = p1;
+                      const char *p2 = p1;
                       while (p2 < ptr
                              && (*p2 == 'B' || *p2 == 'C' || *p2 == 'D'
                                  || *p2 == 'G' || *p2 == 'H' || *p2 == 'J'
@@ -459,13 +445,13 @@ unicode_name_character (const char *name)
                                  || *p2 == 'P' || *p2 == 'R' || *p2 == 'S'
                                  || *p2 == 'T'))
                         p2++;
-                      p3 = p2;
+                      const char *p3 = p2;
                       while (p3 < ptr
                              && (*p3 == 'A' || *p3 == 'E' || *p3 == 'I'
                                  || *p3 == 'O' || *p3 == 'U' || *p3 == 'W'
                                  || *p3 == 'Y'))
                         p3++;
-                      p4 = p3;
+                      const char *p4 = p3;
                       while (p4 < ptr
                              && (*p4 == 'B' || *p4 == 'C' || *p4 == 'D'
                                  || *p4 == 'G' || *p4 == 'H' || *p4 == 'I'
index 628d2f12453ba8137265676bfbfeccd399d37591..dd2ca36cdc4b2fa61df6651a90363abc18690edb 100644 (file)
@@ -33,18 +33,14 @@ uc_canonical_decomposition (ucs4_t uc, ucs4_t *decomposition)
          "Hangul Syllable Decomposition",  See also the clarification at
          <https://www.unicode.org/versions/Unicode5.1.0/>, section
          "Clarification of Hangul Jamo Handling".  */
-      unsigned int t;
-
       uc -= 0xAC00;
-      t = uc % 28;
+      unsigned int t = uc % 28;
 
       if (t == 0)
         {
-          unsigned int v, l;
-
           uc = uc / 28;
-          v = uc % 21;
-          l = uc / 21;
+          unsigned int v = uc % 21;
+          unsigned int l = uc / 21;
 
           decomposition[0] = 0x1100 + l;
           decomposition[1] = 0x1161 + v;
@@ -57,11 +53,9 @@ uc_canonical_decomposition (ucs4_t uc, ucs4_t *decomposition)
           decomposition[1] = 0x11A7 + t;
           return 2;
 #else
-          unsigned int v, l;
-
           uc = uc / 28;
-          v = uc % 21;
-          l = uc / 21;
+          unsigned int v = uc % 21;
+          unsigned int l = uc / 21;
 
           decomposition[0] = 0x1100 + l;
           decomposition[1] = 0x1161 + v;
@@ -78,16 +72,12 @@ uc_canonical_decomposition (ucs4_t uc, ucs4_t *decomposition)
          is a canonical one.  */
       if (entry < 0x8000)
         {
-          const unsigned char *p;
-          unsigned int element;
-          unsigned int length;
-
-          p = &gl_uninorm_decomp_chars_table[3 * entry];
-          element = (p[0] << 16) | (p[1] << 8) | p[2];
+          const unsigned char *p = &gl_uninorm_decomp_chars_table[3 * entry];
+          unsigned int element = (p[0] << 16) | (p[1] << 8) | p[2];
           /* The first element has 5 bits for the decomposition type.  */
           if (((element >> 18) & 0x1f) != UC_DECOMP_CANONICAL)
             abort ();
-          length = 1;
+          unsigned int length = 1;
           for (;;)
             {
               /* Every element has an 18 bits wide Unicode code point.  */
index d9a302beab2365c67f9ff896d158c5617bfbc47d..5f29bc5bbc617815f66298da12defb6d3603f67e 100644 (file)
@@ -69,8 +69,6 @@ uc_composition (ucs4_t uc1, ucs4_t uc2)
             }
 #else
           char codes[6];
-          const struct composition_rule *rule;
-
           codes[0] = (uc1 >> 16) & 0xff;
           codes[1] = (uc1 >> 8) & 0xff;
           codes[2] = uc1 & 0xff;
@@ -78,7 +76,7 @@ uc_composition (ucs4_t uc1, ucs4_t uc2)
           codes[4] = (uc2 >> 8) & 0xff;
           codes[5] = uc2 & 0xff;
 
-          rule = gl_uninorm_compose_lookup (codes, 6);
+          const struct composition_rule *rule = gl_uninorm_compose_lookup (codes, 6);
           if (rule != NULL)
             return rule->combined;
 #endif
index b8deeed4a3edf0cb97dfce32f9e6ef83bdfa74c4..34109702c8167f1f448568472a47ea395a09cfc5 100644 (file)
@@ -39,19 +39,15 @@ uc_decomposition (ucs4_t uc, int *decomp_tag, ucs4_t *decomposition)
          "Hangul Syllable Decomposition",  See also the clarification at
          <https://www.unicode.org/versions/Unicode5.1.0/>, section
          "Clarification of Hangul Jamo Handling".  */
-      unsigned int t;
-
       uc -= 0xAC00;
-      t = uc % 28;
+      unsigned int t = uc % 28;
 
       *decomp_tag = UC_DECOMP_CANONICAL;
       if (t == 0)
         {
-          unsigned int v, l;
-
           uc = uc / 28;
-          v = uc % 21;
-          l = uc / 21;
+          unsigned int v = uc % 21;
+          unsigned int l = uc / 21;
 
           decomposition[0] = 0x1100 + l;
           decomposition[1] = 0x1161 + v;
@@ -64,11 +60,9 @@ uc_decomposition (ucs4_t uc, int *decomp_tag, ucs4_t *decomposition)
           decomposition[1] = 0x11A7 + t;
           return 2;
 #else
-          unsigned int v, l;
-
           uc = uc / 28;
-          v = uc % 21;
-          l = uc / 21;
+          unsigned int v = uc % 21;
+          unsigned int l = uc / 21;
 
           decomposition[0] = 0x1100 + l;
           decomposition[1] = 0x1161 + v;
@@ -82,15 +76,11 @@ uc_decomposition (ucs4_t uc, int *decomp_tag, ucs4_t *decomposition)
       unsigned short entry = decomp_index (uc);
       if (entry != (unsigned short)(-1))
         {
-          const unsigned char *p;
-          unsigned int element;
-          unsigned int length;
-
-          p = &gl_uninorm_decomp_chars_table[3 * (entry & 0x7FFF)];
-          element = (p[0] << 16) | (p[1] << 8) | p[2];
+          const unsigned char *p = &gl_uninorm_decomp_chars_table[3 * (entry & 0x7FFF)];
+          unsigned int element = (p[0] << 16) | (p[1] << 8) | p[2];
           /* The first element has 5 bits for the decomposition type.  */
           *decomp_tag = (element >> 18) & 0x1f;
-          length = 1;
+          unsigned int length = 1;
           for (;;)
             {
               /* Every element has an 18 bits wide Unicode code point.  */
index 23b36f4295e5cd18ade1b7d9f951ae4f14ff9890..494662d720be34309282bc9631281d24fd7c4828 100644 (file)
@@ -24,16 +24,7 @@ FUNC (uninorm_t nf, const UNIT *s, size_t n,
 
   /* The result being accumulated.  */
   UNIT *result;
-  size_t length;
   size_t allocated;
-  /* The buffer for sorting.  */
-  #define SORTBUF_PREALLOCATED 64
-  struct ucs4_with_ccc sortbuf_preallocated[2 * SORTBUF_PREALLOCATED];
-  struct ucs4_with_ccc *sortbuf; /* array of size 2 * sortbuf_allocated */
-  size_t sortbuf_allocated;
-  size_t sortbuf_count;
-
-  /* Initialize the accumulator.  */
   if (resultbuf == NULL)
     {
       result = NULL;
@@ -44,12 +35,15 @@ FUNC (uninorm_t nf, const UNIT *s, size_t n,
       result = resultbuf;
       allocated = *lengthp;
     }
-  length = 0;
+  size_t length = 0;
 
-  /* Initialize the buffer for sorting.  */
-  sortbuf = sortbuf_preallocated;
-  sortbuf_allocated = SORTBUF_PREALLOCATED;
-  sortbuf_count = 0;
+  /* The buffer for sorting.  */
+  #define SORTBUF_PREALLOCATED 64
+  struct ucs4_with_ccc sortbuf_preallocated[2 * SORTBUF_PREALLOCATED];
+  struct ucs4_with_ccc *sortbuf = /* array of size 2 * sortbuf_allocated */
+    sortbuf_preallocated;
+  size_t sortbuf_allocated = SORTBUF_PREALLOCATED;
+  size_t sortbuf_count = 0;
 
   {
     const UNIT *s_end = s + n;
@@ -59,7 +53,6 @@ FUNC (uninorm_t nf, const UNIT *s, size_t n,
         int count;
         ucs4_t decomposed[UC_DECOMPOSITION_MAX_LENGTH];
         int decomposed_count;
-        int i;
 
         if (s < s_end)
           {
@@ -114,7 +107,7 @@ FUNC (uninorm_t nf, const UNIT *s, size_t n,
             decomposed_count = 0;
           }
 
-        i = 0;
+        int i = 0;
         for (;;)
           {
             ucs4_t uc;
@@ -293,12 +286,10 @@ FUNC (uninorm_t nf, const UNIT *s, size_t n,
             /* Append (uc, ccc) to sortbuf.  */
             if (sortbuf_count == sortbuf_allocated)
               {
-                struct ucs4_with_ccc *new_sortbuf;
-
                 sortbuf_allocated = 2 * sortbuf_allocated;
                 if (sortbuf_allocated < sortbuf_count) /* integer overflow? */
                   abort ();
-                new_sortbuf =
+                struct ucs4_with_ccc *new_sortbuf =
                   (struct ucs4_with_ccc *) malloc (2 * sortbuf_allocated * sizeof (struct ucs4_with_ccc));
                 if (new_sortbuf == NULL)
                   {
@@ -342,9 +333,7 @@ FUNC (uninorm_t nf, const UNIT *s, size_t n,
   else if (result != resultbuf && length < allocated)
     {
       /* Shrink the allocated memory if possible.  */
-      UNIT *memory;
-
-      memory = (UNIT *) realloc (result, length * sizeof (UNIT));
+      UNIT *memory = (UNIT *) realloc (result, length * sizeof (UNIT));
       if (memory != NULL)
         result = memory;
     }
index 12f89d2bd4caf5fddef8e01ba931bf8cede67a05..16a00cb3104027848d2b3e0dd0fd52d25afa680e 100644 (file)
@@ -27,24 +27,18 @@ int
 FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2,
       uninorm_t nf, int *resultp)
 {
-  UNIT buf1[2048 / sizeof (UNIT)];
-  UNIT buf2[2048 / sizeof (UNIT)];
-  UNIT *norms1;
-  size_t norms1_length;
-  UNIT *norms2;
-  size_t norms2_length;
-  int cmp;
-
   /* Normalize S1.  */
-  norms1_length = sizeof (buf1) / sizeof (UNIT);
-  norms1 = U_NORMALIZE (nf, s1, n1, buf1, &norms1_length);
+  UNIT buf1[2048 / sizeof (UNIT)];
+  size_t norms1_length = sizeof (buf1) / sizeof (UNIT);
+  UNIT *norms1 = U_NORMALIZE (nf, s1, n1, buf1, &norms1_length);
   if (norms1 == NULL)
     /* errno is set here.  */
     return -1;
 
   /* Normalize S2.  */
-  norms2_length = sizeof (buf2) / sizeof (UNIT);
-  norms2 = U_NORMALIZE (nf, s2, n2, buf2, &norms2_length);
+  UNIT buf2[2048 / sizeof (UNIT)];
+  size_t norms2_length = sizeof (buf2) / sizeof (UNIT);
+  UNIT *norms2 = U_NORMALIZE (nf, s2, n2, buf2, &norms2_length);
   if (norms2 == NULL)
     {
       if (norms1 != buf1)
@@ -57,7 +51,7 @@ FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2,
     }
 
   /* Compare the normalized strings.  */
-  cmp = U_CMP2 (norms1, norms1_length, norms2, norms2_length);
+  int cmp = U_CMP2 (norms1, norms1_length, norms2, norms2_length);
   if (cmp > 0)
     cmp = 1;
   else if (cmp < 0)
index 948462c02ab07f436000920d144f406d6849ed17..f0d8de44309d7d1b5f3d30fe0e22ba8e9e22bec6 100644 (file)
@@ -27,24 +27,18 @@ int
 FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2,
       uninorm_t nf, int *resultp)
 {
-  char buf1[2048];
-  char buf2[2048];
-  char *transformed1;
-  size_t transformed1_length;
-  char *transformed2;
-  size_t transformed2_length;
-  int cmp;
-
   /* Normalize and transform S1.  */
-  transformed1_length = sizeof (buf1);
-  transformed1 = U_NORMXFRM (s1, n1, nf, buf1, &transformed1_length);
+  char buf1[2048];
+  size_t transformed1_length = sizeof (buf1);
+  char *transformed1 = U_NORMXFRM (s1, n1, nf, buf1, &transformed1_length);
   if (transformed1 == NULL)
     /* errno is set here.  */
     return -1;
 
   /* Normalize and transform S2.  */
-  transformed2_length = sizeof (buf2);
-  transformed2 = U_NORMXFRM (s2, n2, nf, buf2, &transformed2_length);
+  char buf2[2048];
+  size_t transformed2_length = sizeof (buf2);
+  char *transformed2 = U_NORMXFRM (s2, n2, nf, buf2, &transformed2_length);
   if (transformed2 == NULL)
     {
       if (transformed1 != buf1)
@@ -57,8 +51,8 @@ FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2,
     }
 
   /* Compare the transformed strings.  */
-  cmp = memcmp2 (transformed1, transformed1_length,
-                 transformed2, transformed2_length);
+  int cmp = memcmp2 (transformed1, transformed1_length,
+                     transformed2, transformed2_length);
   if (cmp < 0)
     cmp = -1;
   else if (cmp > 0)
index 92bf051e2bf35d031e9e2741fe86f0a032844c55..f09b5b452118942493bab3689124cc51cdfa6b16 100644 (file)
@@ -27,24 +27,18 @@ char *
 FUNC (const UNIT *s, size_t n, uninorm_t nf,
       char *resultbuf, size_t *lengthp)
 {
-  UNIT normsbuf[2048 / sizeof (UNIT)];
-  UNIT *norms;
-  size_t norms_length;
-  char convsbuf[2048];
-  char *convs;
-  size_t convs_length;
-  char *result;
-
   /* Normalize the Unicode string.  */
-  norms_length = sizeof (normsbuf) / sizeof (UNIT);
-  norms = U_NORMALIZE (nf, s, n, normsbuf, &norms_length);
+  UNIT normsbuf[2048 / sizeof (UNIT)];
+  size_t norms_length = sizeof (normsbuf) / sizeof (UNIT);
+  UNIT *norms = U_NORMALIZE (nf, s, n, normsbuf, &norms_length);
   if (norms == NULL)
     /* errno is set here.  */
     return NULL;
 
   /* Convert it to locale encoding.  */
-  convs_length = sizeof (convsbuf) - 1;
-  convs = U_CONV_TO_ENCODING (locale_charset (),
+  char convsbuf[2048];
+  size_t convs_length = sizeof (convsbuf) - 1;
+  char *convs = U_CONV_TO_ENCODING (locale_charset (),
                               iconveh_error,
                               norms, norms_length,
                               NULL,
@@ -77,7 +71,7 @@ FUNC (const UNIT *s, size_t n, uninorm_t nf,
     }
 
   /* Apply locale dependent transformations for comparison.  */
-  result = amemxfrm (convs, convs_length, resultbuf, lengthp);
+  char *result = amemxfrm (convs, convs_length, resultbuf, lengthp);
   if (result == NULL)
     {
       if (convs != convsbuf)
index 4d39019d8eb17400b33e30bc6d9a0a2b897fe675..09ea0fd7473143a7ddd96ea755adf96de914bd90 100644 (file)
@@ -100,9 +100,7 @@ uninorm_filter_write (struct uninorm_filter *filter, ucs4_t uc_arg)
       /* 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 =
+      int curr_decomposed_count =
         filter->decomposer (decomposed[curr], curr_decomposed);
       if (curr_decomposed_count >= 0)
         {
@@ -230,12 +228,10 @@ uninorm_filter_write (struct uninorm_filter *filter, ucs4_t uc_arg)
         /* Append (uc, ccc) to sortbuf.  */
         if (sortbuf_count == filter->sortbuf_allocated)
           {
-            struct ucs4_with_ccc *new_sortbuf;
-
             filter->sortbuf_allocated = 2 * filter->sortbuf_allocated;
             if (filter->sortbuf_allocated < sortbuf_count) /* integer overflow? */
               abort ();
-            new_sortbuf =
+            struct ucs4_with_ccc *new_sortbuf =
               (struct ucs4_with_ccc *)
               malloc (2 * filter->sortbuf_allocated * sizeof (struct ucs4_with_ccc));
             if (new_sortbuf == NULL)
index a6b9e390ef7743c4375b8a473c18a9733439473f..54e55939ac5e0eb12c5b872b62ad13fe93b0088c 100644 (file)
@@ -27,10 +27,8 @@ DCHAR_T *
 ASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, const FCHAR_T *format, ...)
 {
   va_list args;
-  DCHAR_T *result;
-
   va_start (args, format);
-  result = VASNPRINTF (resultbuf, lengthp, format, args);
+  DCHAR_T *result = VASNPRINTF (resultbuf, lengthp, format, args);
   va_end (args);
   return result;
 }
index 3f0a3aec41cc7ddcfb099cd7f3e0839130793448..d8ccd2c04213969facf57bba0ad61a7e681f0a61 100644 (file)
@@ -27,10 +27,8 @@ int
 ASPRINTF (DCHAR_T **resultp, const FCHAR_T *format, ...)
 {
   va_list args;
-  int result;
-
   va_start (args, format);
-  result = VASPRINTF (resultp, format, args);
+  int result = VASPRINTF (resultp, format, args);
   va_end (args);
   return result;
 }
index 749707c92f54f2420aeb17f741483cc915b8f26a..7381cace2d323af26f06da1ecfae0ceeab3aff06 100644 (file)
@@ -27,10 +27,8 @@ int
 SNPRINTF (DCHAR_T *buf, size_t size, const FCHAR_T *format, ...)
 {
   va_list args;
-  int result;
-
   va_start (args, format);
-  result = VSNPRINTF (buf, size, format, args);
+  int result = VSNPRINTF (buf, size, format, args);
   va_end (args);
   return result;
 }
index 726172c1b44243e6ea59d0737c05d3944bda539c..be7f0832d19e11411a4ba106588f9c7a5a02a75f 100644 (file)
@@ -27,10 +27,8 @@ int
 SPRINTF (DCHAR_T *buf, const FCHAR_T *format, ...)
 {
   va_list args;
-  int result;
-
   va_start (args, format);
-  result = VSPRINTF (buf, format, args);
+  int result = VSPRINTF (buf, format, args);
   va_end (args);
   return result;
 }
index 85b77f43b27af33810ed8566341db77d7125d314..6ea3f23fe27d9358e8335f8f41f30fbaa305c74f 100644 (file)
@@ -26,13 +26,12 @@ int
 VSNPRINTF (DCHAR_T *buf, size_t size, const FCHAR_T *format, va_list args)
 {
   size_t length;
-  DCHAR_T *result;
 
   if (size == 0)
     buf = NULL;
   else
     length = size;
-  result = VASNPRINTF (buf, &length, format, args);
+  DCHAR_T *result = VASNPRINTF (buf, &length, format, args);
   if (result == NULL)
     return -1;
 
index d1604034cd9293ed56548065a425d9f6634eae4c..8105cc0625998fb6b150b11490620d7dbf4b3734 100644 (file)
@@ -34,15 +34,13 @@ VSPRINTF (DCHAR_T *buf, const FCHAR_T *format, va_list args)
      Also note that glibc's iconv fails with E2BIG when we pass a length that
      is so large that buf + length wraps around, i.e.
      (uintptr_t) (buf + length) < (uintptr_t) buf.  */
-  size_t length;
-  DCHAR_T *result;
 
   /* Set length = min (SIZE_MAX, INT_MAX, - (uintptr_t) buf - 1).  */
-  length = (SIZE_MAX < INT_MAX ? SIZE_MAX : INT_MAX);
+  size_t length = (SIZE_MAX < INT_MAX ? SIZE_MAX : INT_MAX);
   if (length > (~ (uintptr_t) buf) / sizeof (DCHAR_T))
     length = (~ (uintptr_t) buf) / sizeof (DCHAR_T);
 
-  result = VASNPRINTF (buf, &length, format, args);
+  DCHAR_T *result = VASNPRINTF (buf, &length, format, args);
   if (result == NULL)
     return -1;
 
index 01e4117b1afc152922a5d00fddf5afdcd1a22b55..efa4464ee8334363794edf9a7cea0113ac78d064 100644 (file)
 int
 ulc_fprintf (FILE *fp, const char *format, ...)
 {
+  va_list args;
+  va_start (args, format);
+
   char buf[2000];
-  char *output;
-  size_t len;
   size_t lenbuf = sizeof (buf);
-  va_list args;
+  char *output = ulc_vasnprintf (buf, &lenbuf, format, args);
+  size_t len = lenbuf;
 
-  va_start (args, format);
-  output = ulc_vasnprintf (buf, &lenbuf, format, args);
-  len = lenbuf;
   va_end (args);
 
   if (!output)
index e511534316b063f18e749250aff2a3c6fb628ffd..7cd690f082105c8b261142bb81cd5356226f6d52 100644 (file)
@@ -44,12 +44,9 @@ int
 ulc_vfprintf (FILE *fp, const char *format, va_list args)
 {
   char buf[2000];
-  char *output;
-  size_t len;
   size_t lenbuf = sizeof (buf);
-
-  output = ulc_vasnprintf (buf, &lenbuf, format, args);
-  len = lenbuf;
+  char *output = ulc_vasnprintf (buf, &lenbuf, format, args);
+  size_t len = lenbuf;
 
   if (!output)
     {
index 6c7999ad339f5d163a09653e491f6152403443e5..017fc2e54b3e855152c6a01091119a293f79d30f 100644 (file)
@@ -35,8 +35,6 @@
 uint16_t *
 u16_chr (const uint16_t *s, size_t n, ucs4_t uc)
 {
-  uint16_t c[2];
-
   if (uc < 0x10000)
     {
       uint16_t c0 = uc;
@@ -48,21 +46,25 @@ u16_chr (const uint16_t *s, size_t n, ucs4_t uc)
         }
     }
   else
-    switch (u16_uctomb_aux (c, uc, 2))
-      {
-      case 2:
-        if (n > 1)
-          {
-            uint16_t c0 = c[0];
-            uint16_t c1 = c[1];
+    {
+      uint16_t c[2];
+
+      switch (u16_uctomb_aux (c, uc, 2))
+        {
+        case 2:
+          if (n > 1)
+            {
+              uint16_t c0 = c[0];
+              uint16_t c1 = c[1];
 
-            for (n--; n > 0; s++, n--)
-              {
-                if (*s == c0 && s[1] == c1)
-                  return (uint16_t *) s;
-              }
-          }
-        break;
-      }
+              for (n--; n > 0; s++, n--)
+                {
+                  if (*s == c0 && s[1] == c1)
+                    return (uint16_t *) s;
+                }
+            }
+          break;
+        }
+    }
   return NULL;
 }
index 43f23c5b9c9a2e4a39c8f881fc12286bf557c525..959ed19c66f40b46ff590ac124d35a71fffef9f9 100644 (file)
@@ -31,9 +31,7 @@
 size_t
 u16_mbsnlen (const uint16_t *s, size_t n)
 {
-  size_t characters;
-
-  characters = 0;
+  size_t characters = 0;
   while (n > 0)
     {
       ucs4_t uc;
index d74ae22492067ac2708d34119a5a6c214e0971e2..aad8eff8983a8a89ee540a5c47c08d94cdbc37fc 100644 (file)
@@ -34,9 +34,7 @@
 const uint16_t *
 u16_next (ucs4_t *puc, const uint16_t *s)
 {
-  int count;
-
-  count = u16_strmbtouc (puc, s);
+  int count = u16_strmbtouc (puc, s);
   if (count > 0)
     return s + count;
   else
index 832c0e8ffed50846bc29368f8e76cbc1f01687db..d2ec0d8000d0946f8a92ff00f2951c7f20c2f1d9 100644 (file)
@@ -35,8 +35,6 @@
 uint16_t *
 u16_strchr (const uint16_t *s, ucs4_t uc)
 {
-  uint16_t c[2];
-
   if (uc < 0x10000)
     {
       uint16_t c0 = uc;
@@ -51,25 +49,29 @@ u16_strchr (const uint16_t *s, ucs4_t uc)
       return (uint16_t *) s;
     }
   else
-    switch (u16_uctomb_aux (c, uc, 2))
-      {
-      case 2:
-        if (*s == 0)
-          goto notfound;
+    {
+      uint16_t c[2];
+
+      switch (u16_uctomb_aux (c, uc, 2))
         {
-          uint16_t c0 = c[0];
-          uint16_t c1 = c[1];
+        case 2:
+          if (*s == 0)
+            goto notfound;
+          {
+            uint16_t c0 = c[0];
+            uint16_t c1 = c[1];
 
-          for (;; s++)
-            {
-              if (s[1] == 0)
-                goto notfound;
-              if (*s == c0 && s[1] == c1)
-                break;
-            }
-          return (uint16_t *) s;
+            for (;; s++)
+              {
+                if (s[1] == 0)
+                  goto notfound;
+                if (*s == c0 && s[1] == c1)
+                  break;
+              }
+            return (uint16_t *) s;
+          }
         }
-      }
+    }
 notfound:
   return NULL;
 }
index 6aa7c407cf349fad18131373cc4c0a368df39170..9c08639b50e9b67da8fa860ae807258fd4b897f7 100644 (file)
@@ -38,7 +38,6 @@ u16_strrchr (const uint16_t *s, ucs4_t uc)
   /* Calling u16_strlen and then searching from the other end would cause more
      memory accesses. Avoid that, at the cost of a few more comparisons.  */
   uint16_t *result = NULL;
-  uint16_t c[2];
 
   if (uc < 0x10000)
     {
@@ -53,24 +52,28 @@ u16_strrchr (const uint16_t *s, ucs4_t uc)
         }
     }
   else
-    switch (u16_uctomb_aux (c, uc, 2))
-      {
-      case 2:
-        if (*s)
-          {
-            uint16_t c0 = c[0];
-            uint16_t c1 = c[1];
+    {
+      uint16_t c[2];
+
+      switch (u16_uctomb_aux (c, uc, 2))
+        {
+        case 2:
+          if (*s)
+            {
+              uint16_t c0 = c[0];
+              uint16_t c1 = c[1];
 
-            /* FIXME: Maybe walking the string via u16_mblen is a win?  */
-            for (;; s++)
-              {
-                if (s[1] == 0)
-                  break;
-                if (*s == c0 && s[1] == c1)
-                  result = (uint16_t *) s;
-              }
-          }
-        break;
-      }
+              /* FIXME: Maybe walking the string via u16_mblen is a win?  */
+              for (;; s++)
+                {
+                  if (s[1] == 0)
+                    break;
+                  if (*s == c0 && s[1] == c1)
+                    result = (uint16_t *) s;
+                }
+            }
+          break;
+        }
+    }
   return result;
 }
index 51e422627f54029c58d66ed361d2c6161a33f9a2..a3cd86c29ce6088ea25df65823217a439d25c257 100644 (file)
@@ -32,11 +32,10 @@ DST_UNIT *
 FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
 {
   const SRC_UNIT *s_end = s + n;
+
   /* Output string accumulator.  */
   DST_UNIT *result;
   size_t allocated;
-  size_t length;
-
   if (resultbuf != NULL)
     {
       result = resultbuf;
@@ -47,18 +46,16 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
       result = NULL;
       allocated = 0;
     }
-  length = 0;
+  size_t length = 0;
   /* Invariants:
      result is either == resultbuf or == NULL or malloc-allocated.
      If length > 0, then result != NULL.  */
 
   while (s < s_end)
     {
-      ucs4_t uc;
-      int count;
-
       /* Fetch a Unicode character from the input string.  */
-      count = u16_mbtoucr (&uc, s, s_end - s);
+      ucs4_t uc;
+      int count = u16_mbtoucr (&uc, s, s_end - s);
       if (count < 0)
         {
           if (!(result == resultbuf || result == NULL))
@@ -71,11 +68,11 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
       /* Store it in the output string.  */
       if (length + 1 > allocated)
         {
-          DST_UNIT *memory;
-
           allocated = (allocated > 0 ? 2 * allocated : 12);
           if (length + 1 > allocated)
             allocated = length + 1;
+
+          DST_UNIT *memory;
           if (result == resultbuf || result == NULL)
             memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT));
           else
@@ -113,9 +110,8 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
   else if (result != resultbuf && length < allocated)
     {
       /* Shrink the allocated memory if possible.  */
-      DST_UNIT *memory;
-
-      memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT));
+      DST_UNIT *memory =
+        (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT));
       if (memory != NULL)
         result = memory;
     }
index d9f092c48cbb5a767383729be3d9d8eb164c9de1..51f30596933783548e09db7b4f743a3e0aad50db 100644 (file)
@@ -40,11 +40,10 @@ DST_UNIT *
 FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
 {
   const SRC_UNIT *s_end = s + n;
+
   /* Output string accumulator.  */
   DST_UNIT *result;
   size_t allocated;
-  size_t length;
-
   if (resultbuf != NULL)
     {
       result = resultbuf;
@@ -55,18 +54,16 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
       result = NULL;
       allocated = 0;
     }
-  length = 0;
+  size_t length = 0;
   /* Invariants:
      result is either == resultbuf or == NULL or malloc-allocated.
      If length > 0, then result != NULL.  */
 
   while (s < s_end)
     {
-      ucs4_t uc;
-      int count;
-
       /* Fetch a Unicode character from the input string.  */
-      count = u16_mbtoucr (&uc, s, s_end - s);
+      ucs4_t uc;
+      int count = u16_mbtoucr (&uc, s, s_end - s);
       if (count < 0)
         {
           if (!(result == resultbuf || result == NULL))
@@ -87,11 +84,11 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
         }
       if (count == -2)
         {
-          DST_UNIT *memory;
-
           allocated = (allocated > 0 ? 2 * allocated : 12);
           if (length + 6 > allocated)
             allocated = length + 6;
+
+          DST_UNIT *memory;
           if (result == resultbuf || result == NULL)
             memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT));
           else
@@ -132,9 +129,8 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
   else if (result != resultbuf && length < allocated)
     {
       /* Shrink the allocated memory if possible.  */
-      DST_UNIT *memory;
-
-      memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT));
+      DST_UNIT *memory =
+        (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT));
       if (memory != NULL)
         result = memory;
     }
index 9ed2ef134c5ab1039b58b4efce6e6f60e594e096..9e75332b453d9f6cde726596965b9214247c2cac 100644 (file)
@@ -34,9 +34,7 @@
 const uint32_t *
 u32_next (ucs4_t *puc, const uint32_t *s)
 {
-  int count;
-
-  count = u32_strmbtouc (puc, s);
+  int count = u32_strmbtouc (puc, s);
   if (count > 0)
     return s + count;
   else
index 94530e2b1f423988f3905693b6335e3980955323..257e3a9c5ecbe6d706fd5e0ca32f4bb6c05b57b0 100644 (file)
@@ -40,11 +40,10 @@ DST_UNIT *
 FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
 {
   const SRC_UNIT *s_end = s + n;
+
   /* Output string accumulator.  */
   DST_UNIT *result;
   size_t allocated;
-  size_t length;
-
   if (resultbuf != NULL)
     {
       result = resultbuf;
@@ -55,23 +54,20 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
       result = NULL;
       allocated = 0;
     }
-  length = 0;
+  size_t length = 0;
   /* Invariants:
      result is either == resultbuf or == NULL or malloc-allocated.
      If length > 0, then result != NULL.  */
 
   while (s < s_end)
     {
-      ucs4_t uc;
-      int count;
-
       /* Fetch a Unicode character from the input string.  */
-      uc = *s++;
+      ucs4_t uc = *s++;
       /* No need to call the safe variant u32_mbtouc, because
          u16_uctomb will verify uc anyway.  */
 
       /* Store it in the output string.  */
-      count = u16_uctomb (result + length, uc, allocated - length);
+      int count = u16_uctomb (result + length, uc, allocated - length);
       if (count == -1)
         {
           if (!(result == resultbuf || result == NULL))
@@ -81,11 +77,11 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
         }
       if (count == -2)
         {
-          DST_UNIT *memory;
-
           allocated = (allocated > 0 ? 2 * allocated : 12);
           if (length + 2 > allocated)
             allocated = length + 2;
+
+          DST_UNIT *memory;
           if (result == resultbuf || result == NULL)
             memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT));
           else
@@ -126,9 +122,8 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
   else if (result != resultbuf && length < allocated)
     {
       /* Shrink the allocated memory if possible.  */
-      DST_UNIT *memory;
-
-      memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT));
+      DST_UNIT *memory =
+        (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT));
       if (memory != NULL)
         result = memory;
     }
index 0c4f0bc3cc4daa5adbc6c0fa70cd6165e22bf2ae..51771239ea1f592c353e0473cbdbf79d42b5eaa9 100644 (file)
@@ -32,11 +32,10 @@ DST_UNIT *
 FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
 {
   const SRC_UNIT *s_end = s + n;
+
   /* Output string accumulator.  */
   DST_UNIT *result;
   size_t allocated;
-  size_t length;
-
   if (resultbuf != NULL)
     {
       result = resultbuf;
@@ -47,23 +46,20 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
       result = NULL;
       allocated = 0;
     }
-  length = 0;
+  size_t length = 0;
   /* Invariants:
      result is either == resultbuf or == NULL or malloc-allocated.
      If length > 0, then result != NULL.  */
 
   while (s < s_end)
     {
-      ucs4_t uc;
-      int count;
-
       /* Fetch a Unicode character from the input string.  */
-      uc = *s++;
+      ucs4_t uc = *s++;
       /* No need to call the safe variant u32_mbtouc, because
          u8_uctomb will verify uc anyway.  */
 
       /* Store it in the output string.  */
-      count = u8_uctomb (result + length, uc, allocated - length);
+      int count = u8_uctomb (result + length, uc, allocated - length);
       if (count == -1)
         {
           if (!(result == resultbuf || result == NULL))
@@ -73,11 +69,11 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
         }
       if (count == -2)
         {
-          DST_UNIT *memory;
-
           allocated = (allocated > 0 ? 2 * allocated : 12);
           if (length + 6 > allocated)
             allocated = length + 6;
+
+          DST_UNIT *memory;
           if (result == resultbuf || result == NULL)
             memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT));
           else
@@ -118,9 +114,8 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
   else if (result != resultbuf && length < allocated)
     {
       /* Shrink the allocated memory if possible.  */
-      DST_UNIT *memory;
-
-      memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT));
+      DST_UNIT *memory =
+        (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT));
       if (memory != NULL)
         result = memory;
     }
index c34e1fe3e8e480c3c18044f7216535c8db86af98..28922bfef8a03f128a138ef242ab0244c1e2e21c 100644 (file)
@@ -46,8 +46,7 @@ u8_chr (const uint8_t *s, size_t n, ucs4_t uc)
 
   {
     uint8_t c[6];
-    size_t uc_size;
-    uc_size = u8_uctomb_aux (c, uc, 6);
+    size_t uc_size = u8_uctomb_aux (c, uc, 6);
 
     if (n < uc_size)
       return NULL;
index d7043779d584da3251426b9d68f82c3520bcaf46..8660c7dc4914ba8769f48464f7e8b6f505f41040 100644 (file)
@@ -31,9 +31,7 @@
 size_t
 u8_mbsnlen (const uint8_t *s, size_t n)
 {
-  size_t characters;
-
-  characters = 0;
+  size_t characters = 0;
   while (n > 0)
     {
       ucs4_t uc;
index 3701701a5a1dc19345e48a87de840b06a6ceff84..28b46a39c8cbf101fb013a241b5796936bd7c1d1 100644 (file)
@@ -34,9 +34,7 @@
 const uint8_t *
 u8_next (ucs4_t *puc, const uint8_t *s)
 {
-  int count;
-
-  count = u8_strmbtouc (puc, s);
+  int count = u8_strmbtouc (puc, s);
   if (count > 0)
     return s + count;
   else
index 3ccf051646e193e4387396c8e96ca91c82b5ce31..00e5904c04ddd2ba0f2933cfbf88564769851725 100644 (file)
@@ -37,8 +37,6 @@
 uint8_t *
 u8_strchr (const uint8_t *s, ucs4_t uc)
 {
-  uint8_t c[6];
-
   if (uc < 0x80)
     {
       uint8_t c0 = uc;
@@ -65,187 +63,191 @@ u8_strchr (const uint8_t *s, ucs4_t uc)
         }
     }
   else
+    {
       /* Loops equivalent to strstr, optimized for a specific length (2, 3, 4)
          of the needle.  We use an algorithm similar to Boyer-Moore which
          is documented in lib/unistr/u8-chr.c.  There is additional
          complication because we need to check after every byte for
          a NUL byte, but the idea is the same. */
-    switch (u8_uctomb_aux (c, uc, 6))
-      {
-      case 2:
-        if (*s == 0 || s[1] == 0)
-          break;
-        {
-          uint8_t c0 = c[0];
-          uint8_t c1 = c[1];
-          /* Search for { c0, c1 }.  */
-          uint8_t s1 = s[1];
-
-          for (;;)
-            {
-              /* Here s[0] != 0, s[1] != 0.
-                 Test whether s[0..1] == { c0, c1 }.  */
-              if (s1 == c1)
-                {
-                  if (*s == c0)
-                    return (uint8_t *) s;
-                  else
-                    /* Skip the search at s + 1, because s[1] = c1 < c0.  */
-                    goto case2_skip2;
-                }
-              else
-                {
-                  if (s1 == c0)
-                    goto case2_skip1;
-                  else
-                    /* Skip the search at s + 1, because s[1] != c0.  */
-                    goto case2_skip2;
-                }
-             case2_skip2:
-              s++;
-              s1 = s[1];
-              if (s[1] == 0)
-                break;
-             case2_skip1:
-              s++;
-              s1 = s[1];
-              if (s[1] == 0)
-                break;
-            }
-        }
-        break;
+      uint8_t c[6];
 
-      case 3:
-        if (*s == 0 || s[1] == 0 || s[2] == 0)
-          break;
+      switch (u8_uctomb_aux (c, uc, 6))
         {
-          uint8_t c0 = c[0];
-          uint8_t c1 = c[1];
-          uint8_t c2 = c[2];
-          /* Search for { c0, c1, c2 }.  */
-          uint8_t s2 = s[2];
+        case 2:
+          if (*s == 0 || s[1] == 0)
+            break;
+          {
+            uint8_t c0 = c[0];
+            uint8_t c1 = c[1];
+            /* Search for { c0, c1 }.  */
+            uint8_t s1 = s[1];
+
+            for (;;)
+              {
+                /* Here s[0] != 0, s[1] != 0.
+                   Test whether s[0..1] == { c0, c1 }.  */
+                if (s1 == c1)
+                  {
+                    if (*s == c0)
+                      return (uint8_t *) s;
+                    else
+                      /* Skip the search at s + 1, because s[1] = c1 < c0.  */
+                      goto case2_skip2;
+                  }
+                else
+                  {
+                    if (s1 == c0)
+                      goto case2_skip1;
+                    else
+                      /* Skip the search at s + 1, because s[1] != c0.  */
+                      goto case2_skip2;
+                  }
+               case2_skip2:
+                s++;
+                s1 = s[1];
+                if (s[1] == 0)
+                  break;
+               case2_skip1:
+                s++;
+                s1 = s[1];
+                if (s[1] == 0)
+                  break;
+              }
+          }
+          break;
 
-          for (;;)
-            {
-              /* Here s[0] != 0, s[1] != 0, s[2] != 0.
-                 Test whether s[0..2] == { c0, c1, c2 }.  */
-              if (s2 == c2)
-                {
-                  if (s[1] == c1 && *s == c0)
-                    return (uint8_t *) s;
-                  else
-                    /* If c2 != c1:
-                         Skip the search at s + 1, because s[2] == c2 != c1.
-                       Skip the search at s + 2, because s[2] == c2 < c0.  */
-                    if (c2 == c1)
+        case 3:
+          if (*s == 0 || s[1] == 0 || s[2] == 0)
+            break;
+          {
+            uint8_t c0 = c[0];
+            uint8_t c1 = c[1];
+            uint8_t c2 = c[2];
+            /* Search for { c0, c1, c2 }.  */
+            uint8_t s2 = s[2];
+
+            for (;;)
+              {
+                /* Here s[0] != 0, s[1] != 0, s[2] != 0.
+                   Test whether s[0..2] == { c0, c1, c2 }.  */
+                if (s2 == c2)
+                  {
+                    if (s[1] == c1 && *s == c0)
+                      return (uint8_t *) s;
+                    else
+                      /* If c2 != c1:
+                           Skip the search at s + 1, because s[2] == c2 != c1.
+                         Skip the search at s + 2, because s[2] == c2 < c0.  */
+                      if (c2 == c1)
+                        goto case3_skip1;
+                      else
+                        goto case3_skip3;
+                  }
+                else
+                  {
+                    if (s2 == c1)
                       goto case3_skip1;
+                    else if (s2 == c0)
+                      /* Skip the search at s + 1, because s[2] != c1.  */
+                      goto case3_skip2;
                     else
+                      /* Skip the search at s + 1, because s[2] != c1.
+                         Skip the search at s + 2, because s[2] != c0.  */
                       goto case3_skip3;
-                }
-              else
-                {
-                  if (s2 == c1)
-                    goto case3_skip1;
-                  else if (s2 == c0)
-                    /* Skip the search at s + 1, because s[2] != c1.  */
-                    goto case3_skip2;
-                  else
-                    /* Skip the search at s + 1, because s[2] != c1.
-                       Skip the search at s + 2, because s[2] != c0.  */
-                    goto case3_skip3;
-                }
-             case3_skip3:
-              s++;
-              s2 = s[2];
-              if (s[2] == 0)
-                break;
-             case3_skip2:
-              s++;
-              s2 = s[2];
-              if (s[2] == 0)
-                break;
-             case3_skip1:
-              s++;
-              s2 = s[2];
-              if (s[2] == 0)
-                break;
-            }
-        }
-        break;
-
-      case 4:
-        if (*s == 0 || s[1] == 0 || s[2] == 0 || s[3] == 0)
+                  }
+               case3_skip3:
+                s++;
+                s2 = s[2];
+                if (s[2] == 0)
+                  break;
+               case3_skip2:
+                s++;
+                s2 = s[2];
+                if (s[2] == 0)
+                  break;
+               case3_skip1:
+                s++;
+                s2 = s[2];
+                if (s[2] == 0)
+                  break;
+              }
+          }
           break;
-        {
-          uint8_t c0 = c[0];
-          uint8_t c1 = c[1];
-          uint8_t c2 = c[2];
-          uint8_t c3 = c[3];
-          /* Search for { c0, c1, c2, c3 }.  */
-          uint8_t s3 = s[3];
 
-          for (;;)
-            {
-              /* Here s[0] != 0, s[1] != 0, s[2] != 0, s[3] != 0.
-                 Test whether s[0..3] == { c0, c1, c2, c3 }.  */
-              if (s3 == c3)
-                {
-                  if (s[2] == c2 && s[1] == c1 && *s == c0)
-                    return (uint8_t *) s;
-                  else
-                    /* If c3 != c2:
-                         Skip the search at s + 1, because s[3] == c3 != c2.
-                       If c3 != c1:
-                         Skip the search at s + 2, because s[3] == c3 != c1.
-                       Skip the search at s + 3, because s[3] == c3 < c0.  */
-                    if (c3 == c2)
+        case 4:
+          if (*s == 0 || s[1] == 0 || s[2] == 0 || s[3] == 0)
+            break;
+          {
+            uint8_t c0 = c[0];
+            uint8_t c1 = c[1];
+            uint8_t c2 = c[2];
+            uint8_t c3 = c[3];
+            /* Search for { c0, c1, c2, c3 }.  */
+            uint8_t s3 = s[3];
+
+            for (;;)
+              {
+                /* Here s[0] != 0, s[1] != 0, s[2] != 0, s[3] != 0.
+                   Test whether s[0..3] == { c0, c1, c2, c3 }.  */
+                if (s3 == c3)
+                  {
+                    if (s[2] == c2 && s[1] == c1 && *s == c0)
+                      return (uint8_t *) s;
+                    else
+                      /* If c3 != c2:
+                           Skip the search at s + 1, because s[3] == c3 != c2.
+                         If c3 != c1:
+                           Skip the search at s + 2, because s[3] == c3 != c1.
+                         Skip the search at s + 3, because s[3] == c3 < c0.  */
+                      if (c3 == c2)
+                        goto case4_skip1;
+                      else if (c3 == c1)
+                        goto case4_skip2;
+                      else
+                        goto case4_skip4;
+                  }
+                else
+                  {
+                    if (s3 == c2)
                       goto case4_skip1;
-                    else if (c3 == c1)
+                    else if (s3 == c1)
+                      /* Skip the search at s + 1, because s[3] != c2.  */
                       goto case4_skip2;
+                    else if (s3 == c0)
+                      /* Skip the search at s + 1, because s[3] != c2.
+                         Skip the search at s + 2, because s[3] != c1.  */
+                      goto case4_skip3;
                     else
+                      /* Skip the search at s + 1, because s[3] != c2.
+                         Skip the search at s + 2, because s[3] != c1.
+                         Skip the search at s + 3, because s[3] != c0.  */
                       goto case4_skip4;
-                }
-              else
-                {
-                  if (s3 == c2)
-                    goto case4_skip1;
-                  else if (s3 == c1)
-                    /* Skip the search at s + 1, because s[3] != c2.  */
-                    goto case4_skip2;
-                  else if (s3 == c0)
-                    /* Skip the search at s + 1, because s[3] != c2.
-                       Skip the search at s + 2, because s[3] != c1.  */
-                    goto case4_skip3;
-                  else
-                    /* Skip the search at s + 1, because s[3] != c2.
-                       Skip the search at s + 2, because s[3] != c1.
-                       Skip the search at s + 3, because s[3] != c0.  */
-                    goto case4_skip4;
-                }
-             case4_skip4:
-              s++;
-              s3 = s[3];
-              if (s[3] == 0)
-                break;
-             case4_skip3:
-              s++;
-              s3 = s[3];
-              if (s[3] == 0)
-                break;
-             case4_skip2:
-              s++;
-              s3 = s[3];
-              if (s[3] == 0)
-                break;
-             case4_skip1:
-              s++;
-              s3 = s[3];
-              if (s[3] == 0)
-                break;
-            }
+                  }
+               case4_skip4:
+                s++;
+                s3 = s[3];
+                if (s[3] == 0)
+                  break;
+               case4_skip3:
+                s++;
+                s3 = s[3];
+                if (s[3] == 0)
+                  break;
+               case4_skip2:
+                s++;
+                s3 = s[3];
+                if (s[3] == 0)
+                  break;
+               case4_skip1:
+                s++;
+                s3 = s[3];
+                if (s[3] == 0)
+                  break;
+              }
+          }
+          break;
         }
-        break;
-      }
+    }
 
   return NULL;
 }
index 4f364fa6823a585896cb42697e227bff43976ad7..176b53ce12fdfbdda842a52fb69ea47738626825 100644 (file)
@@ -38,7 +38,6 @@ u8_strrchr (const uint8_t *s, ucs4_t uc)
   /* Calling u8_strlen and then searching from the other end would cause more
      memory accesses. Avoid that, at the cost of a few more comparisons.  */
   uint8_t *result = NULL;
-  uint8_t c[6];
 
   if (uc < 0x80)
     {
@@ -53,61 +52,65 @@ u8_strrchr (const uint8_t *s, ucs4_t uc)
         }
     }
   else
-    switch (u8_uctomb_aux (c, uc, 6))
-      {
-      case 2:
-        if (*s)
-          {
-            uint8_t c0 = c[0];
-            uint8_t c1 = c[1];
+    {
+      uint8_t c[6];
+
+      switch (u8_uctomb_aux (c, uc, 6))
+        {
+        case 2:
+          if (*s)
+            {
+              uint8_t c0 = c[0];
+              uint8_t c1 = c[1];
 
-            /* FIXME: Maybe walking the string via u8_mblen is a win?  */
-            for (;; s++)
-              {
-                if (s[1] == 0)
-                  break;
-                if (*s == c0 && s[1] == c1)
-                  result = (uint8_t *) s;
-              }
-          }
-        break;
+              /* FIXME: Maybe walking the string via u8_mblen is a win?  */
+              for (;; s++)
+                {
+                  if (s[1] == 0)
+                    break;
+                  if (*s == c0 && s[1] == c1)
+                    result = (uint8_t *) s;
+                }
+            }
+          break;
 
-      case 3:
-        if (*s && s[1])
-          {
-            uint8_t c0 = c[0];
-            uint8_t c1 = c[1];
-            uint8_t c2 = c[2];
+        case 3:
+          if (*s && s[1])
+            {
+              uint8_t c0 = c[0];
+              uint8_t c1 = c[1];
+              uint8_t c2 = c[2];
 
-            /* FIXME: Maybe walking the string via u8_mblen is a win?  */
-            for (;; s++)
-              {
-                if (s[2] == 0)
-                  break;
-                if (*s == c0 && s[1] == c1 && s[2] == c2)
-                  result = (uint8_t *) s;
-              }
-          }
-        break;
+              /* FIXME: Maybe walking the string via u8_mblen is a win?  */
+              for (;; s++)
+                {
+                  if (s[2] == 0)
+                    break;
+                  if (*s == c0 && s[1] == c1 && s[2] == c2)
+                    result = (uint8_t *) s;
+                }
+            }
+          break;
 
-      case 4:
-        if (*s && s[1] && s[2])
-          {
-            uint8_t c0 = c[0];
-            uint8_t c1 = c[1];
-            uint8_t c2 = c[2];
-            uint8_t c3 = c[3];
+        case 4:
+          if (*s && s[1] && s[2])
+            {
+              uint8_t c0 = c[0];
+              uint8_t c1 = c[1];
+              uint8_t c2 = c[2];
+              uint8_t c3 = c[3];
 
-            /* FIXME: Maybe walking the string via u8_mblen is a win?  */
-            for (;; s++)
-              {
-                if (s[3] == 0)
-                  break;
-                if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3)
-                  result = (uint8_t *) s;
-              }
-          }
-        break;
-      }
+              /* FIXME: Maybe walking the string via u8_mblen is a win?  */
+              for (;; s++)
+                {
+                  if (s[3] == 0)
+                    break;
+                  if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3)
+                    result = (uint8_t *) s;
+                }
+            }
+          break;
+        }
+    }
   return result;
 }
index 64bd7a695e85dd13f2869a04b1e5b8656dfc7ef0..a23c65329dc64489bd1c562301859b97a79c9dba 100644 (file)
@@ -40,11 +40,10 @@ DST_UNIT *
 FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
 {
   const SRC_UNIT *s_end = s + n;
+
   /* Output string accumulator.  */
   DST_UNIT *result;
   size_t allocated;
-  size_t length;
-
   if (resultbuf != NULL)
     {
       result = resultbuf;
@@ -55,18 +54,16 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
       result = NULL;
       allocated = 0;
     }
-  length = 0;
+  size_t length = 0;
   /* Invariants:
      result is either == resultbuf or == NULL or malloc-allocated.
      If length > 0, then result != NULL.  */
 
   while (s < s_end)
     {
-      ucs4_t uc;
-      int count;
-
       /* Fetch a Unicode character from the input string.  */
-      count = u8_mbtoucr (&uc, s, s_end - s);
+      ucs4_t uc;
+      int count = u8_mbtoucr (&uc, s, s_end - s);
       if (count < 0)
         {
           if (!(result == resultbuf || result == NULL))
@@ -87,11 +84,11 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
         }
       if (count == -2)
         {
-          DST_UNIT *memory;
-
           allocated = (allocated > 0 ? 2 * allocated : 12);
           if (length + 2 > allocated)
             allocated = length + 2;
+
+          DST_UNIT *memory;
           if (result == resultbuf || result == NULL)
             memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT));
           else
@@ -132,9 +129,8 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
   else if (result != resultbuf && length < allocated)
     {
       /* Shrink the allocated memory if possible.  */
-      DST_UNIT *memory;
-
-      memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT));
+      DST_UNIT *memory =
+        (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT));
       if (memory != NULL)
         result = memory;
     }
index 1f029ead4ee61cc1c1db568eb831d9184272907d..41fa130d2e84e3b230fa6e437763f47c90e59d7b 100644 (file)
@@ -32,11 +32,10 @@ DST_UNIT *
 FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
 {
   const SRC_UNIT *s_end = s + n;
+
   /* Output string accumulator.  */
   DST_UNIT *result;
   size_t allocated;
-  size_t length;
-
   if (resultbuf != NULL)
     {
       result = resultbuf;
@@ -47,18 +46,16 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
       result = NULL;
       allocated = 0;
     }
-  length = 0;
+  size_t length = 0;
   /* Invariants:
      result is either == resultbuf or == NULL or malloc-allocated.
      If length > 0, then result != NULL.  */
 
   while (s < s_end)
     {
-      ucs4_t uc;
-      int count;
-
       /* Fetch a Unicode character from the input string.  */
-      count = u8_mbtoucr (&uc, s, s_end - s);
+      ucs4_t uc;
+      int count = u8_mbtoucr (&uc, s, s_end - s);
       if (count < 0)
         {
           if (!(result == resultbuf || result == NULL))
@@ -71,11 +68,11 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
       /* Store it in the output string.  */
       if (length + 1 > allocated)
         {
-          DST_UNIT *memory;
-
           allocated = (allocated > 0 ? 2 * allocated : 12);
           if (length + 1 > allocated)
             allocated = length + 1;
+
+          DST_UNIT *memory;
           if (result == resultbuf || result == NULL)
             memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT));
           else
@@ -113,9 +110,8 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
   else if (result != resultbuf && length < allocated)
     {
       /* Shrink the allocated memory if possible.  */
-      DST_UNIT *memory;
-
-      memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT));
+      DST_UNIT *memory =
+        (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT));
       if (memory != NULL)
         result = memory;
     }
index 5d8d04084ffee22f457c04330d945c68428c635d..5cd2b9fc2008cb2098c2a246306ce325033364eb 100644 (file)
@@ -54,7 +54,6 @@ read_file (FILE *stream)
   char *buf = NULL;
   int alloc = 0;
   int size = 0;
-  int count;
 
   while (! feof (stream))
     {
@@ -70,7 +69,7 @@ read_file (FILE *stream)
               exit (1);
             }
         }
-      count = fread (buf + size, 1, BUFSIZE, stream);
+      int count = fread (buf + size, 1, BUFSIZE, stream);
       if (count == 0)
         {
           if (ferror (stream))
index 006bea067d6b75fc6a23516e917e26bd4f9b314c..fc7a0c23961dcd91adae1dab3bffd39c147bd071 100644 (file)
@@ -66,11 +66,10 @@ ulc_wordbreaks (const char *s, size_t n, char *p)
 
           if (offsets != NULL)
             {
-              uint8_t *t;
               size_t m;
-
-              t = u8_conv_from_encoding (encoding, iconveh_question_mark,
-                                         s, n, offsets, NULL, &m);
+              uint8_t *t =
+                u8_conv_from_encoding (encoding, iconveh_question_mark,
+                                       s, n, offsets, NULL, &m);
               if (t != NULL)
                 {
                   char *q = (char *) (m > 0 ? malloc (m) : NULL);
@@ -128,7 +127,6 @@ read_file (FILE *stream)
   char *buf = NULL;
   int alloc = 0;
   int size = 0;
-  int count;
 
   while (! feof (stream))
     {
@@ -144,7 +142,7 @@ read_file (FILE *stream)
               exit (1);
             }
         }
-      count = fread (buf + size, 1, BUFSIZE, stream);
+      int count = fread (buf + size, 1, BUFSIZE, stream);
       if (count == 0)
         {
           if (ferror (stream))
index 32d47edb8e5be1278b4504029175fc3c4d632ba1..2e151ff23704c0216aea3484307ce620fd35c446 100644 (file)
@@ -39,14 +39,12 @@ u16_width (const uint16_t *s, size_t n, const char *encoding)
   while (s < s_end)
     {
       ucs4_t uc;
-      int w;
-
       s += u16_mbtouc_unsafe (&uc, s, s_end - s);
 
       if (uc == 0)
         break; /* end of string reached */
 
-      w = uc_width (uc, encoding);
+      int w = uc_width (uc, encoding);
       if (w >= 0) /* ignore control characters in the string */
         width += w;
     }
index bb4c04a8b034a1cf5704814cde4c8bc10be1be6c..e69c0b754a2877ab1fb23e800871cb808af2f5c9 100644 (file)
@@ -37,12 +37,11 @@ u32_width (const uint32_t *s, size_t n, const char *encoding)
   while (s < s_end)
     {
       ucs4_t uc = *s++;
-      int w;
 
       if (uc == 0)
         break; /* end of string reached */
 
-      w = uc_width (uc, encoding);
+      int w = uc_width (uc, encoding);
       if (w >= 0) /* ignore control characters in the string */
         width += w;
     }
index a4df4c1365f3d3b48f728214acae6159e806ae82..799c3d0dac750ffb57a937e13e13db2b8d05a320 100644 (file)
@@ -39,14 +39,12 @@ u8_width (const uint8_t *s, size_t n, const char *encoding)
   while (s < s_end)
     {
       ucs4_t uc;
-      int w;
-
       s += u8_mbtouc_unsafe (&uc, s, s_end - s);
 
       if (uc == 0)
         break; /* end of string reached */
 
-      w = uc_width (uc, encoding);
+      int w = uc_width (uc, encoding);
       if (w >= 0) /* ignore control characters in the string */
         width += w;
     }
index be4a8c2b6346fa951c389625f13e939bac69b67f..bbeaffb1d37f1aff63912df81bbf2ba13705b1c8 100644 (file)
 int
 rpl_unlinkat (int fd, char const *name, int flag)
 {
-  size_t len;
-  int result = 0;
   /* rmdir behavior has no problems with trailing slash.  */
   if (flag & AT_REMOVEDIR)
     return unlinkat (fd, name, flag);
 
-  len = strlen (name);
+  size_t len = strlen (name);
+  int result = 0;
   if (len && ISSLASH (name[len - 1]))
     {
       /* See the lengthy comment in unlink.c why we disobey the POSIX
index d38ed37ac6c1cbe0f0063b509767e179035f4a7f..92025e224a921394080f6ed354423e0d11ffea69 100644 (file)
@@ -56,15 +56,13 @@ __libc_lock_define_initialized (static, envlock)
 int
 unsetenv (const char *name)
 {
-  size_t len;
-
   if (name == NULL || *name == '\0' || strchr (name, '=') != NULL)
     {
       __set_errno (EINVAL);
       return -1;
     }
 
-  len = strlen (name);
+  size_t len = strlen (name);
 
 #if HAVE_DECL__PUTENV /* native Windows */
   /* The Microsoft documentation
@@ -79,14 +77,13 @@ unsetenv (const char *name)
      of the form "NAME=".  (NB: This is a different convention than with glibc
      putenv, which expects a string of the form "NAME"!)  */
   {
-    int putenv_result;
     char *name_ = malloc (len + 2);
     if (name_ == NULL)
       return -1;
     memcpy (name_, name, len);
     name_[len] = '=';
     name_[len + 1] = 0;
-    putenv_result = _putenv (name_);
+    int putenv_result = _putenv (name_);
     /* In this particular case it is OK to free() the argument passed to
        _putenv.  */
     free (name_);
@@ -138,12 +135,12 @@ extern int unsetenv (const char *);
 int
 rpl_unsetenv (const char *name)
 {
-  int result = 0;
   if (!name || !*name || strchr (name, '='))
     {
       errno = EINVAL;
       return -1;
     }
+  int result = 0;
   while (getenv (name))
 # if !VOID_UNSETENV
     result =
index 79ac0cf2b856a28d2620b18c14950ae787021961..b8f9a29a07f2a5e4c8381a843dc5fc45104b2d89 100644 (file)
@@ -102,16 +102,7 @@ parse_with_separator (char const *spec, char const *separator,
                       uid_t *uid, gid_t *gid,
                       char **username, char **groupname)
 {
-  const char *error_msg;
-  struct passwd *pwd;
-  struct group *grp;
-  char *u;
-  char const *g;
-  char *gname = NULL;
-  uid_t unum = *uid;
-  gid_t gnum = gid ? *gid : -1;
-
-  error_msg = NULL;
+  const char *error_msg = NULL;
   if (username)
     *username = NULL;
   if (groupname)
@@ -121,7 +112,7 @@ parse_with_separator (char const *spec, char const *separator,
      group specifiers or to NULL.  If U is not NULL, it is a newly
      allocated string.  */
 
-  u = NULL;
+  char *u = NULL;
   if (separator == NULL)
     {
       if (*spec)
@@ -137,9 +128,9 @@ parse_with_separator (char const *spec, char const *separator,
         }
     }
 
-  g = (separator == NULL || *(separator + 1) == '\0'
-       ? NULL
-       : separator + 1);
+  char const *g = (separator == NULL || *(separator + 1) == '\0'
+                   ? NULL
+                   : separator + 1);
 
 #ifdef __DJGPP__
   /* Pretend that we are the user U whose group is G.  This makes
@@ -150,10 +141,14 @@ parse_with_separator (char const *spec, char const *separator,
     setenv ("GROUP", g, 1);
 #endif
 
+  char *gname = NULL;
+  uid_t unum = *uid;
+  gid_t gnum = gid ? *gid : -1;
+
   if (u != NULL)
     {
       /* If it starts with "+", skip the look-up.  */
-      pwd = (*u == '+' ? NULL : getpwnam (u));
+      struct passwd *pwd = (*u == '+' ? NULL : getpwnam (u));
       if (pwd == NULL)
         {
           username = NULL;
@@ -183,7 +178,7 @@ parse_with_separator (char const *spec, char const *separator,
                  so get the login group.  */
               char buf[INT_BUFSIZE_BOUND (uintmax_t)];
               gnum = pwd->pw_gid;
-              grp = getgrgid (gnum);
+              struct group *grp = getgrgid (gnum);
               gname = xstrdup (grp ? grp->gr_name : umaxtostr (gnum, buf));
               endgrent ();
             }
@@ -195,7 +190,7 @@ parse_with_separator (char const *spec, char const *separator,
     {
       /* Explicit group.  */
       /* If it starts with "+", skip the look-up.  */
-      grp = (*g == '+' ? NULL : getgrnam (g));
+      struct group *grp = (*g == '+' ? NULL : getgrnam (g));
       if (grp == NULL)
         {
           groupname = NULL;
@@ -303,15 +298,16 @@ main (int argc, char **argv)
 {
   for (int i = 1; i < argc; i++)
     {
-      const char *e;
-      char *username, *groupname;
+      char *tmp = strdup (argv[i]);
+
       uid_t uid;
       gid_t gid;
-      char *tmp;
+      char *username;
+      char *groupname;
+      const char *e = parse_user_spec (tmp, &uid, &gid, &username, &groupname);
 
-      tmp = strdup (argv[i]);
-      e = parse_user_spec (tmp, &uid, &gid, &username, &groupname);
       free (tmp);
+
       printf ("%s: %lu %lu %s %s %s\n",
               argv[i],
               (unsigned long int) uid,
index 22f5531a0a549faf74c03270181790008f4468a6..e57a8d2ad30d406df2c01e7f1333eceb7d093c1d 100644 (file)
@@ -52,10 +52,8 @@ _gl_utimens_windows (const char *name, struct timespec ts[2])
 
   /* Remove trailing slashes (except the very first one, at position
      drive_prefix_len), but remember their presence.  */
-  size_t rlen;
+  size_t rlen = len;
   bool check_dir = false;
-
-  rlen = len;
   while (rlen > drive_prefix_len && ISSLASH (name[rlen-1]))
     {
       check_dir = true;
index 22e1f25fc5b70c9b56f002b822fecbe255708155..30ad335b08c520ded810fab767512c5cd1729a0e 100644 (file)
@@ -173,7 +173,6 @@ utimecmpat (int dfd, char const *dst_name,
       /* Information about the destination file system.  */
       static struct fs_res *new_dst_res;
       struct fs_res *dst_res = NULL;
-      struct fs_res tmp_dst_res;
 
       /* timestamp resolution in nanoseconds.  */
       int res;
@@ -216,7 +215,8 @@ utimecmpat (int dfd, char const *dst_name,
         }
       else
         {
-        low_memory:
+        low_memory: ;
+          struct fs_res tmp_dst_res;
           if (ht)
             {
               tmp_dst_res.dev = dst_stat->st_dev;
@@ -318,8 +318,6 @@ utimecmpat (int dfd, char const *dst_name,
 
           if (SYSCALL_RESOLUTION < res)
             {
-              struct stat dst_status;
-
               /* Ignore source timestamp information that must necessarily
                  be lost when filtered through utimens.  */
               src_ns -= src_ns % SYSCALL_RESOLUTION;
@@ -352,6 +350,8 @@ utimecmpat (int dfd, char const *dst_name,
               if (utimensat (dfd, dst_name, timespec, AT_SYMLINK_NOFOLLOW))
                 return -2;
 
+              struct stat dst_status;
+
               /* Read the modification time that was set.  */
               {
                 int stat_result
index 0387e9f10e99575861e5b31cd9dfec811fd37575..b2c88028c7f619b2df9e33b0587590b98e23d4c9 100644 (file)
@@ -105,13 +105,13 @@ is_valid_timespecs (struct timespec const timespec[2])
 static int
 validate_timespec (struct timespec timespec[2])
 {
-  int result = 0;
-  int utime_omit_count = 0;
   if (!is_valid_timespecs (timespec))
     {
       errno = EINVAL;
       return -1;
     }
+  int result = 0;
+  int utime_omit_count = 0;
   /* Work around Linux kernel 2.6.25 bug, where utimensat fails with
      EINVAL if tv_sec is not 0 when using the flag values of tv_nsec.
      Flag a Linux kernel 2.6.32 bug, where an mtime of UTIME_OMIT
@@ -184,7 +184,6 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2])
   struct timespec adjusted_timespec[2];
   struct timespec *ts = timespec ? adjusted_timespec : NULL;
   int adjustment_needed = 0;
-  struct stat st;
 
   if (ts)
     {
@@ -221,6 +220,8 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2])
     fsync (fd);
 #endif
 
+  struct stat st;
+
   /* POSIX 2008 added two interfaces to set file timestamps with
      nanosecond resolution; newer Linux implements both functions via
      a single syscall.  We provide a fallback for ENOSYS (for example,
@@ -319,18 +320,14 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2])
      <https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-filetime>  */
   if (0 <= fd)
     {
-      HANDLE handle;
-      FILETIME current_time;
-      FILETIME last_access_time;
-      FILETIME last_write_time;
-
-      handle = (HANDLE) _get_osfhandle (fd);
+      HANDLE handle = (HANDLE) _get_osfhandle (fd);
       if (handle == INVALID_HANDLE_VALUE)
         {
           errno = EBADF;
           return -1;
         }
 
+      FILETIME current_time;
       if (ts == NULL || ts[0].tv_nsec == UTIME_NOW || ts[1].tv_nsec == UTIME_NOW)
         {
           /* GetSystemTimeAsFileTime
@@ -341,6 +338,7 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2])
           GetSystemTimeAsFileTime (&current_time);
         }
 
+      FILETIME last_access_time;
       if (ts == NULL || ts[0].tv_nsec == UTIME_NOW)
         {
           last_access_time = current_time;
@@ -358,6 +356,7 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2])
           last_access_time.dwHighDateTime = time_since_16010101 >> 32;
         }
 
+      FILETIME last_write_time;
       if (ts == NULL || ts[1].tv_nsec == UTIME_NOW)
         {
           last_write_time = current_time;
@@ -468,10 +467,11 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2])
                     time_t adiff = st.st_atime - t[0].tv_sec;
                     time_t mdiff = st.st_mtime - t[1].tv_sec;
 
-                    struct timeval *tt = NULL;
                     struct timeval truncated_timeval[2];
                     truncated_timeval[0] = t[0];
                     truncated_timeval[1] = t[1];
+
+                    struct timeval *tt = NULL;
                     if (abig && adiff == 1 && get_stat_atime_ns (&st) == 0)
                       {
                         tt = truncated_timeval;
@@ -567,7 +567,6 @@ lutimens (char const *file, struct timespec const timespec[2])
   struct timespec adjusted_timespec[2];
   struct timespec *ts = timespec ? adjusted_timespec : NULL;
   int adjustment_needed = 0;
-  struct stat st;
 
   if (ts)
     {
@@ -578,6 +577,8 @@ lutimens (char const *file, struct timespec const timespec[2])
   if (adjustment_needed < 0)
     return -1;
 
+  struct stat st;
+
   /* The Linux kernel did not support symlink timestamps until
      utimensat, in version 2.6.22, so we don't need to mimic
      fdutimens' worry about buggy NFS clients.  But we do have to
@@ -653,7 +654,6 @@ lutimens (char const *file, struct timespec const timespec[2])
   {
     struct timeval timeval[2];
     struct timeval *t;
-    int result;
     if (ts)
       {
         timeval[0] = (struct timeval) { .tv_sec = ts[0].tv_sec,
@@ -665,7 +665,7 @@ lutimens (char const *file, struct timespec const timespec[2])
     else
       t = NULL;
 
-    result = lutimes (file, t);
+    int result = lutimes (file, t);
     if (result == 0 || errno != ENOSYS)
       return result;
   }
index fcf2d27eb3eb98e509a384f27630cd1d84864a5a..6830c58fa640528584e793f4d2ed200066a0156a 100644 (file)
@@ -85,7 +85,6 @@ rpl_utimensat (int fd, char const *file, struct timespec const times[2],
   static int utimensat_works_really; /* 0 = unknown, 1 = yes, -1 = no.  */
   if (0 <= utimensat_works_really)
     {
-      int result;
 #  if defined __linux__ || defined __sun || defined __NetBSD__
       struct stat st;
       /* As recently as Linux kernel 2.6.32 (Dec 2009), several file
@@ -167,7 +166,7 @@ rpl_utimensat (int fd, char const *file, struct timespec const times[2],
         }
 #   endif
 #  endif
-      result = utimensat (fd, file, times, flag);
+      int result = utimensat (fd, file, times, flag);
       /* Linux kernel 2.6.25 has a bug where it returns EINVAL for
          UTIME_NOW or UTIME_OMIT with non-zero tv_sec, which
          local_utimensat works around.  Meanwhile, EINVAL for a bad
index 2b77f077c711c742bf488e09c267a154f5de2adc..37368100a2da473c46fa6f554fb2979a264524dc 100644 (file)
@@ -834,7 +834,6 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
   size_t a_len = a.nlimbs;
   const mp_limb_t *b_ptr = b.limbs;
   size_t b_len = b.nlimbs;
-  mp_limb_t *roomptr;
   mp_limb_t *tmp_roomptr = NULL;
   mp_limb_t *q_ptr;
   size_t q_len;
@@ -844,7 +843,7 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
   /* Allocate room for a_len+2 digits.
      (Need a_len+1 digits for the real division and 1 more digit for the
      final rounding of q.)  */
-  roomptr = (mp_limb_t *) malloc ((a_len + 2) * sizeof (mp_limb_t));
+  mp_limb_t *roomptr = (mp_limb_t *) malloc ((a_len + 2) * sizeof (mp_limb_t));
   if (roomptr == NULL)
     return NOMEM_PTR;
 
@@ -1267,17 +1266,15 @@ convert_to_decimal (mpn_t a, size_t extra_zeroes)
 static void *
 decode_long_double (long double x, int *ep, mpn_t *mp)
 {
-  mpn_t m;
-  int exp;
-  long double y;
-
   /* Allocate memory for result.  */
+  mpn_t m;
   m.nlimbs = (LDBL_MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS;
   m.limbs = (mp_limb_t *) malloc (m.nlimbs * sizeof (mp_limb_t));
   if (m.limbs == NULL)
     return NULL;
   /* Split into exponential part and mantissa.  */
-  y = safe_frexpl (x, &exp);
+  int exp;
+  long double y = safe_frexpl (x, &exp);
   if (!(y >= 0.0L && y < 1.0L))
     abort ();
   /* x = 2^exp * y = 2^(exp - LDBL_MANT_BIT) * (y * 2^LDBL_MANT_BIT), and the
@@ -1354,17 +1351,15 @@ decode_long_double (long double x, int *ep, mpn_t *mp)
 static void *
 decode_double (double x, int *ep, mpn_t *mp)
 {
-  mpn_t m;
-  int exp;
-  double y;
-
   /* Allocate memory for result.  */
+  mpn_t m;
   m.nlimbs = (DBL_MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS;
   m.limbs = (mp_limb_t *) malloc (m.nlimbs * sizeof (mp_limb_t));
   if (m.limbs == NULL)
     return NULL;
   /* Split into exponential part and mantissa.  */
-  y = frexp (x, &exp);
+  int exp;
+  double y = frexp (x, &exp);
   if (!(y >= 0.0 && y < 1.0))
     abort ();
   /* x = 2^exp * y = 2^(exp - DBL_MANT_BIT) * (y * 2^DBL_MANT_BIT), and the
@@ -1437,24 +1432,11 @@ decode_double (double x, int *ep, mpn_t *mp)
 static char *
 scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
 {
-  int s;
-  size_t extra_zeroes;
-  unsigned int abs_n;
-  unsigned int abs_s;
-  mp_limb_t *pow5_ptr;
-  size_t pow5_len;
-  unsigned int s_limbs;
-  unsigned int s_bits;
-  mpn_t pow5;
-  mpn_t z;
-  void *z_memory;
-  char *digits;
-
   /* x = 2^e * m, hence
      y = round (2^e * 10^n * m) = round (2^(e+n) * 5^n * m)
        = round (2^s * 5^n * m).  */
-  s = e + n;
-  extra_zeroes = 0;
+  int s = e + n;
+  size_t extra_zeroes = 0;
   /* Factor out a common power of 10 if possible.  */
   if (s > 0 && n > 0)
     {
@@ -1467,11 +1449,12 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
      z = round (2^s * 5^n * m).  */
   /* Compute 5^|n|, possibly shifted by |s| bits if n and s have the same
      sign.  2.322 is slightly larger than log(5)/log(2).  */
-  abs_n = (n >= 0 ? n : -n);
-  abs_s = (s >= 0 ? s : -s);
-  pow5_ptr = (mp_limb_t *) malloc (((int)(abs_n * (2.322f / GMP_LIMB_BITS)) + 1
-                                    + abs_s / GMP_LIMB_BITS + 1)
-                                   * sizeof (mp_limb_t));
+  unsigned int abs_n = (n >= 0 ? n : -n);
+  unsigned int abs_s = (s >= 0 ? s : -s);
+  mp_limb_t *pow5_ptr =
+    (mp_limb_t *) malloc (((int)(abs_n * (2.322f / GMP_LIMB_BITS)) + 1
+                           + abs_s / GMP_LIMB_BITS + 1)
+                          * sizeof (mp_limb_t));
   if (pow5_ptr == NULL)
     {
       free (memory);
@@ -1479,7 +1462,7 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
     }
   /* Initialize with 1.  */
   pow5_ptr[0] = 1;
-  pow5_len = 1;
+  size_t pow5_len = 1;
   /* Multiply with 5^|n|.  */
   if (abs_n > 0)
     {
@@ -1503,8 +1486,11 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
             pow5_ptr[pow5_len++] = (mp_limb_t) carry;
         }
     }
-  s_limbs = abs_s / GMP_LIMB_BITS;
-  s_bits = abs_s % GMP_LIMB_BITS;
+  unsigned int s_limbs = abs_s / GMP_LIMB_BITS;
+  unsigned int s_bits = abs_s % GMP_LIMB_BITS;
+  mpn_t pow5;
+  mpn_t z;
+  void *z_memory;
   if (n >= 0 ? s >= 0 : s <= 0)
     {
       /* Multiply with 2^|s|.  */
@@ -1632,7 +1618,7 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
 
   if (z_memory == NOMEM_PTR)
     return NULL;
-  digits = convert_to_decimal (z, extra_zeroes);
+  char *digits = convert_to_decimal (z, extra_zeroes);
   free (z_memory);
   return digits;
 }
@@ -1687,13 +1673,9 @@ scale10_round_decimal_double (double x, int n)
 static int
 floorlog10l (long double x)
 {
-  int exp;
-  long double y;
-  double z;
-  double l;
-
   /* Split into exponential part and mantissa.  */
-  y = safe_frexpl (x, &exp);
+  int exp;
+  long double y = safe_frexpl (x, &exp);
   if (!(y >= 0.0L && y < 1.0L))
     abort ();
   if (y == 0.0L)
@@ -1734,8 +1716,8 @@ floorlog10l (long double x)
   if (!(y >= 0.5L && y < 1.0L))
     abort ();
   /* Compute an approximation for l = log2(x) = exp + log2(y).  */
-  l = exp;
-  z = y;
+  double l = exp;
+  double z = y;
   if (z < 0.70710678118654752444)
     {
       z *= 1.4142135623730950488;
@@ -1778,13 +1760,9 @@ floorlog10l (long double x)
 static int
 floorlog10 (double x)
 {
-  int exp;
-  double y;
-  double z;
-  double l;
-
   /* Split into exponential part and mantissa.  */
-  y = frexp (x, &exp);
+  int exp;
+  double y = frexp (x, &exp);
   if (!(y >= 0.0 && y < 1.0))
     abort ();
   if (y == 0.0)
@@ -1825,8 +1803,8 @@ floorlog10 (double x)
   if (!(y >= 0.5 && y < 1.0))
     abort ();
   /* Compute an approximation for l = log2(x) = exp + log2(y).  */
-  l = exp;
-  z = y;
+  double l = exp;
+  double z = y;
   if (z < 0.70710678118654752444)
     {
       z *= 1.4142135623730950488;
@@ -2489,21 +2467,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
     goto fail_1_with_EINVAL;
 
   {
-    size_t buf_neededlength;
-    TCHAR_T *buf;
-    TCHAR_T *buf_malloced;
-    const FCHAR_T *cp;
-    size_t di;
-    DIRECTIVE *dp;
-    /* Output string accumulator.  */
-    DCHAR_T *result;
-    size_t allocated;
-    size_t length;
-
     /* Allocate a small buffer that will hold a directive passed to
        sprintf or snprintf.  */
-    buf_neededlength =
+    size_t buf_neededlength =
       xsum4 (7, d.max_width_length, d.max_precision_length, 6);
+    TCHAR_T *buf;
+    TCHAR_T *buf_malloced;
 #if HAVE_ALLOCA
     if (buf_neededlength < 4000 / sizeof (TCHAR_T))
       {
@@ -2522,9 +2491,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
         buf_malloced = buf;
       }
 
-    result = resultbuf;
-    allocated = (resultbuf != NULL ? *lengthp : 0);
-    length = 0;
+    /* Output string accumulator.  */
+    DCHAR_T *result = resultbuf;
+    size_t allocated = (resultbuf != NULL ? *lengthp : 0);
+    size_t length = 0;
+
     /* Invariants:
        result is either == resultbuf or malloc-allocated.
        If result == NULL, resultbuf is == NULL as well.
@@ -2535,15 +2506,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 #define ENSURE_ALLOCATION_ELSE(needed, oom_statement) \
     if ((needed) > allocated)                                                \
       {                                                                      \
-        size_t memory_size;                                                  \
-        DCHAR_T *memory;                                                     \
-                                                                             \
         allocated = (allocated > 0 ? xtimes (allocated, 2) : 12);            \
         if ((needed) > allocated)                                            \
           allocated = (needed);                                              \
-        memory_size = xtimes (allocated, sizeof (DCHAR_T));                  \
+        size_t memory_size = xtimes (allocated, sizeof (DCHAR_T));           \
         if (size_overflow_p (memory_size))                                   \
           oom_statement                                                      \
+        DCHAR_T *memory;                                                     \
         if (result == resultbuf)                                             \
           memory = (DCHAR_T *) malloc (memory_size);                         \
         else                                                                 \
@@ -2557,6 +2526,9 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 #define ENSURE_ALLOCATION(needed) \
   ENSURE_ALLOCATION_ELSE((needed), goto out_of_memory; )
 
+    const FCHAR_T *cp;
+    size_t di;
+    DIRECTIVE *dp;
     for (cp = format, di = 0, dp = &d.dir[0]; ; cp = dp->dir_end, di++, dp++)
       {
         if (cp != dp->dir_start)
@@ -2657,22 +2629,16 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
               {
                 arg_type type = a.arg[dp->arg_index].type;
                 int flags = dp->flags;
-                int has_width;
-                size_t width;
-                int has_precision;
-                size_t precision;
 
-                has_width = 0;
-                width = 0;
+                int has_width = 0;
+                size_t width = 0;
                 if (dp->width_start != dp->width_end)
                   {
                     if (dp->width_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->width_arg_index].a.a_int;
+                        int arg = a.arg[dp->width_arg_index].a.a_int;
                         width = arg;
                         if (arg < 0)
                           {
@@ -2695,17 +2661,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                     has_width = 1;
                   }
 
-                has_precision = 0;
-                precision = 0;
+                int has_precision = 0;
+                size_t precision = 0;
                 if (dp->precision_start != dp->precision_end)
                   {
                     if (dp->precision_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->precision_arg_index].a.a_int;
+                        int arg = a.arg[dp->precision_arg_index].a.a_int;
                         /* "A negative precision is taken as if the precision
                             were omitted."  */
                         if (arg >= 0)
@@ -3050,22 +3014,16 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                    than INT_MAX characters, whence snprintf or sprintf would
                    fail to process it.  */
                 int flags = dp->flags;
-                int has_width;
-                size_t width;
-                int has_precision;
-                size_t precision;
 
-                has_width = 0;
-                width = 0;
+                int has_width = 0;
+                size_t width = 0;
                 if (dp->width_start != dp->width_end)
                   {
                     if (dp->width_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->width_arg_index].a.a_int;
+                        int arg = a.arg[dp->width_arg_index].a.a_int;
                         width = arg;
                         if (arg < 0)
                           {
@@ -3088,17 +3046,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                     has_width = 1;
                   }
 
-                has_precision = 0;
-                precision = 6;
+                int has_precision = 0;
+                size_t precision = 6;
                 if (dp->precision_start != dp->precision_end)
                   {
                     if (dp->precision_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->precision_arg_index].a.a_int;
+                        int arg = a.arg[dp->precision_arg_index].a.a_int;
                         /* "A negative precision is taken as if the precision
                             were omitted."  */
                         if (arg >= 0)
@@ -3120,18 +3076,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 
                 {
                   const char *arg = a.arg[dp->arg_index].a.a_string;
-                  size_t bytes;
-# if ENABLE_UNISTDIO && DCHAR_IS_TCHAR
-                  size_t characters;
-# endif
-# if !DCHAR_IS_TCHAR
-                  /* This code assumes that TCHAR_T is 'char'.  */
-                  static_assert (sizeof (TCHAR_T) == 1);
-                  DCHAR_T *tmpdst;
-                  size_t tmpdst_len;
-# endif
-                  size_t w;
 
+                  size_t bytes;
                   if (has_precision)
                     {
                       /* Use only at most PRECISION bytes, from the left.  */
@@ -3145,6 +3091,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                     }
 
 # if ENABLE_UNISTDIO && DCHAR_IS_TCHAR
+                  size_t characters;
                   if (has_width)
                     characters = mbsnlen (arg, bytes);
                   else
@@ -3156,6 +3103,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 # endif
 
 # if !DCHAR_IS_TCHAR
+                  /* This code assumes that TCHAR_T is 'char'.  */
+                  static_assert (sizeof (TCHAR_T) == 1);
+                  DCHAR_T *tmpdst;
+                  size_t tmpdst_len;
                   /* Convert from TCHAR_T[] to DCHAR_T[].  */
                   tmpdst =
                     DCHAR_CONV_FROM_ENCODING (locale_charset (),
@@ -3167,6 +3118,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                     goto fail_with_errno;
 # endif
 
+                  size_t w;
                   if (has_width)
                     {
 # if ENABLE_UNISTDIO
@@ -3236,18 +3188,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                    convert back the result from a char[] to a wchar_t[].
                    Instead, just copy the argument wchar_t[] to the result.  */
                 int flags = dp->flags;
-                size_t width;
 
-                width = 0;
+                size_t width = 0;
                 if (dp->width_start != dp->width_end)
                   {
                     if (dp->width_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->width_arg_index].a.a_int;
+                        int arg = a.arg[dp->width_arg_index].a.a_int;
                         width = arg;
                         if (arg < 0)
                           {
@@ -3276,20 +3225,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 
                   if (dp->conversion == 's')
                     {
-                      int has_precision;
-                      size_t precision;
-
-                      has_precision = 0;
-                      precision = 6;
+                      int has_precision = 0;
+                      size_t precision = 6;
                       if (dp->precision_start != dp->precision_end)
                         {
                           if (dp->precision_arg_index != ARG_NONE)
                             {
-                              int arg;
-
                               if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
                                 abort ();
-                              arg = a.arg[dp->precision_arg_index].a.a_int;
+                              int arg = a.arg[dp->precision_arg_index].a.a_int;
                               /* "A negative precision is taken as if the precision
                                   were omitted."  */
                               if (arg >= 0)
@@ -3315,9 +3259,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                         {
                           /* Use only at most PRECISION wide characters, from
                              the left.  */
-                          const wchar_t *ls_arg_end;
-
-                          ls_arg_end = ls_arg;
+                          const wchar_t *ls_arg_end = ls_arg;
                           characters = 0;
                           for (; precision > 0; precision--)
                             {
@@ -3389,22 +3331,16 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                    such bugs, we implement the entire processing of the 's'
                    directive ourselves.  */
                 int flags = dp->flags;
-                int has_width;
-                size_t width;
-                int has_precision;
-                size_t precision;
 
-                has_width = 0;
-                width = 0;
+                int has_width = 0;
+                size_t width = 0;
                 if (dp->width_start != dp->width_end)
                   {
                     if (dp->width_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->width_arg_index].a.a_int;
+                        int arg = a.arg[dp->width_arg_index].a.a_int;
                         width = arg;
                         if (arg < 0)
                           {
@@ -3427,17 +3363,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                     has_width = 1;
                   }
 
-                has_precision = 0;
-                precision = 6;
+                int has_precision = 0;
+                size_t precision = 6;
                 if (dp->precision_start != dp->precision_end)
                   {
                     if (dp->precision_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->precision_arg_index].a.a_int;
+                        int arg = a.arg[dp->precision_arg_index].a.a_int;
                         /* "A negative precision is taken as if the precision
                             were omitted."  */
                         if (arg >= 0)
@@ -3630,13 +3564,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 #  endif
                       while (precision > 0)
                         {
-                          char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
-                          int count;
-
                           if (*arg_end == 0)
                             /* Found the terminating null wide character.  */
                             break;
-                          count = local_wcrtomb (cbuf, *arg_end, &state);
+                          char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
+                          int count = local_wcrtomb (cbuf, *arg_end, &state);
                           if (count < 0)
                             /* Cannot convert.  */
                             goto fail_with_EILSEQ;
@@ -3669,13 +3601,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 #  endif
                       for (;;)
                         {
-                          char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
-                          int count;
-
                           if (*arg_end == 0)
                             /* Found the terminating null wide character.  */
                             break;
-                          count = local_wcrtomb (cbuf, *arg_end, &state);
+                          char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
+                          int count = local_wcrtomb (cbuf, *arg_end, &state);
                           if (count < 0)
                             /* Cannot convert.  */
                             goto fail_with_EILSEQ;
@@ -3702,10 +3632,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 
 #  if !DCHAR_IS_TCHAR
                   {
-                    TCHAR_T *tmpsrc;
-
                     /* Convert the string into a piece of temporary memory.  */
-                    tmpsrc = (TCHAR_T *) malloc (bytes * sizeof (TCHAR_T));
+                    TCHAR_T *tmpsrc = (TCHAR_T *) malloc (bytes * sizeof (TCHAR_T));
                     if (tmpsrc == NULL)
                       goto out_of_memory;
                     {
@@ -3716,12 +3644,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 #   endif
                       for (size_t remaining = bytes; remaining > 0; )
                         {
-                          char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
-                          int count;
-
                           if (*arg == 0)
                             abort ();
-                          count = local_wcrtomb (cbuf, *arg, &state);
+                          char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
+                          int count = local_wcrtomb (cbuf, *arg, &state);
                           if (count <= 0)
                             /* Inconsistency.  */
                             abort ();
@@ -3795,12 +3721,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       ENSURE_ALLOCATION (xsum (length, bytes));
                       for (size_t remaining = bytes; remaining > 0; )
                         {
-                          char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
-                          int count;
-
                           if (*arg == 0)
                             abort ();
-                          count = local_wcrtomb (cbuf, *arg, &state);
+                          char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
+                          int count = local_wcrtomb (cbuf, *arg, &state);
                           if (count <= 0)
                             /* Inconsistency.  */
                             abort ();
@@ -3820,12 +3744,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 #   endif
                       while (arg < arg_end)
                         {
-                          char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
-                          int count;
-
                           if (*arg == 0)
                             abort ();
-                          count = local_wcrtomb (cbuf, *arg, &state);
+                          char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
+                          int count = local_wcrtomb (cbuf, *arg, &state);
                           if (count <= 0)
                             /* Cannot convert.  */
                             goto fail_with_EILSEQ;
@@ -3862,20 +3784,16 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                    a correct behaviour for the null wint_t argument and/or the
                    fallback that avoids EILSEQ.  */
                 int flags = dp->flags;
-                int has_width;
-                size_t width;
 
-                has_width = 0;
-                width = 0;
+                int has_width = 0;
+                size_t width = 0;
                 if (dp->width_start != dp->width_end)
                   {
                     if (dp->width_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->width_arg_index].a.a_int;
+                        int arg = a.arg[dp->width_arg_index].a.a_int;
                         width = arg;
                         if (arg < 0)
                           {
@@ -3918,14 +3836,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 # endif
                     {
                       /* Count the number of bytes.  */
-                      char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
-                      int count;
 # if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
                       mbstate_t state;
                       mbszero (&state);
 # endif
 
-                      count = local_wcrtomb (cbuf, arg, &state);
+                      char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
+                      int count = local_wcrtomb (cbuf, arg, &state);
                       if (count < 0)
                         /* Cannot convert.  */
                         goto fail_with_EILSEQ;
@@ -3953,14 +3870,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                     /* Convert the string into a piece of temporary memory.  */
                     if (bytes > 0)
                       {
-                        char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
-                        int count;
 #  if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
                         mbstate_t state;
                         mbszero (&state);
 #  endif
 
-                        count = local_wcrtomb (cbuf, arg, &state);
+                        char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
+                        int count = local_wcrtomb (cbuf, arg, &state);
                         if (count <= 0)
                           /* Inconsistency.  */
                           abort ();
@@ -4020,13 +3936,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       ENSURE_ALLOCATION (xsum (length, bytes));
                       if (bytes > 0)
                         {
-                          int count;
 #  if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
                           mbstate_t state;
                           mbszero (&state);
 #  endif
 
-                          count = local_wcrtomb (result + length, arg, &state);
+                          int count = local_wcrtomb (result + length, arg, &state);
                           if (count <= 0)
                             /* Inconsistency.  */
                             abort ();
@@ -4035,14 +3950,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                     }
                   else
                     {
-                      char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
-                      int count;
 #  if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
                       mbstate_t state;
                       mbszero (&state);
 #  endif
 
-                      count = local_wcrtomb (cbuf, arg, &state);
+                      char cbuf[64]; /* Assume MB_CUR_MAX <= 64.  */
+                      int count = local_wcrtomb (cbuf, arg, &state);
                       if (count < 0)
                         /* Cannot convert.  */
                         goto fail_with_EILSEQ;
@@ -4075,18 +3989,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                 /* Implement the 'c' directive ourselves, in order to avoid
                    EILSEQ in the "C" locale.  */
                 int flags = dp->flags;
-                size_t width;
 
-                width = 0;
+                size_t width = 0;
                 if (dp->width_start != dp->width_end)
                   {
                     if (dp->width_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->width_arg_index].a.a_int;
+                        int arg = a.arg[dp->width_arg_index].a.a_int;
                         width = arg;
                         if (arg < 0)
                           {
@@ -4112,9 +4023,9 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                 {
                   char arg = (char) a.arg[dp->arg_index].a.a_char;
                   mbstate_t state;
-                  wchar_t wc;
-
                   mbszero (&state);
+
+                  wchar_t wc;
                   int count = mbrtowc (&wc, &arg, 1, &state);
                   if (count < 0)
                     /* Invalid or incomplete multibyte character.  */
@@ -4155,30 +4066,16 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
               {
                 arg_type type = a.arg[dp->arg_index].type;
                 int flags = dp->flags;
-                int has_width;
-                size_t width;
-                int has_precision;
-                size_t precision;
-                size_t tmp_length;
-                size_t count;
-                DCHAR_T tmpbuf[700];
-                DCHAR_T *tmp;
-                DCHAR_T *tmp_end;
-                DCHAR_T *tmp_start;
-                DCHAR_T *pad_ptr;
-                DCHAR_T *p;
 
-                has_width = 0;
-                width = 0;
+                int has_width = 0;
+                size_t width = 0;
                 if (dp->width_start != dp->width_end)
                   {
                     if (dp->width_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->width_arg_index].a.a_int;
+                        int arg = a.arg[dp->width_arg_index].a.a_int;
                         width = arg;
                         if (arg < 0)
                           {
@@ -4201,17 +4098,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                     has_width = 1;
                   }
 
-                has_precision = 0;
-                precision = 1;
+                int has_precision = 0;
+                size_t precision = 1;
                 if (dp->precision_start != dp->precision_end)
                   {
                     if (dp->precision_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->precision_arg_index].a.a_int;
+                        int arg = a.arg[dp->precision_arg_index].a.a_int;
                         /* "A negative precision is taken as if the precision
                             were omitted."  */
                         if (arg >= 0)
@@ -4232,6 +4127,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                   }
 
                 /* Allocate a temporary buffer of sufficient size.  */
+                size_t tmp_length;
                 switch (type)
                   {
                   default:
@@ -4298,6 +4194,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                 if (tmp_length < width)
                   tmp_length = width;
 
+                DCHAR_T tmpbuf[700];
+                DCHAR_T *tmp;
                 if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T))
                   tmp = tmpbuf;
                 else
@@ -4313,7 +4211,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       goto out_of_memory;
                   }
 
-                tmp_end = tmp + tmp_length;
+                DCHAR_T *tmp_end = tmp + tmp_length;
 
                 unsigned long long arg;
                 switch (type)
@@ -4362,7 +4260,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                   }
                 int need_prefix = ((flags & FLAG_ALT) && arg != 0);
 
-                p = tmp_end;
+                DCHAR_T *p = tmp_end;
                 /* "The result of converting a zero value with a precision
                    of zero is no characters."  */
                 if (!(has_precision && precision == 0 && arg == 0))
@@ -4382,7 +4280,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       *--p = '0';
                   }
 
-                pad_ptr = p;
+                DCHAR_T *pad_ptr = p;
 
                 if (need_prefix)
                   {
@@ -4395,12 +4293,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 # endif
                     *--p = '0';
                   }
-                tmp_start = p;
+                DCHAR_T *tmp_start = p;
 
                 /* The generated string now extends from tmp_start to tmp_end,
                    with the zero padding insertion point being at pad_ptr,
                    tmp_start <= pad_ptr <= tmp_end.  */
-                count = tmp_end - tmp_start;
+                size_t count = tmp_end - tmp_start;
 
                 if (count < width)
                   {
@@ -4476,26 +4374,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
               {
                 arg_type type = a.arg[dp->arg_index].type;
                 int flags = dp->flags;
-                size_t width;
-                int has_precision;
-                size_t precision;
-                size_t tmp_length;
-                size_t count;
-                DCHAR_T tmpbuf[700];
-                DCHAR_T *tmp;
-                DCHAR_T *pad_ptr;
-                DCHAR_T *p;
 
-                width = 0;
+                size_t width = 0;
                 if (dp->width_start != dp->width_end)
                   {
                     if (dp->width_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->width_arg_index].a.a_int;
+                        int arg = a.arg[dp->width_arg_index].a.a_int;
                         width = arg;
                         if (arg < 0)
                           {
@@ -4517,17 +4404,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       goto overflow;
                   }
 
-                has_precision = 0;
-                precision = 0;
+                int has_precision = 0;
+                size_t precision = 0;
                 if (dp->precision_start != dp->precision_end)
                   {
                     if (dp->precision_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->precision_arg_index].a.a_int;
+                        int arg = a.arg[dp->precision_arg_index].a.a_int;
                         /* "A negative precision is taken as if the precision
                             were omitted."  */
                         if (arg >= 0)
@@ -4548,6 +4433,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                   }
 
                 /* Allocate a temporary buffer of sufficient size.  */
+                size_t tmp_length;
                 if (type == TYPE_LONGDOUBLE)
                   tmp_length =
                     (unsigned int) ((LDBL_DIG + 1)
@@ -4570,6 +4456,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 
                 tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */
 
+                DCHAR_T tmpbuf[700];
+                DCHAR_T *tmp;
                 if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T))
                   tmp = tmpbuf;
                 else
@@ -4585,8 +4473,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       goto out_of_memory;
                   }
 
-                pad_ptr = NULL;
-                p = tmp;
+                DCHAR_T *pad_ptr = NULL;
+                DCHAR_T *p = tmp;
                 if (type == TYPE_LONGDOUBLE)
                   {
 # if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || (NEED_WPRINTF_DIRECTIVE_LA && WIDE_CHAR_VERSION)
@@ -4605,11 +4493,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       }
                     else
                       {
-                        int sign = 0;
                         DECL_LONG_DOUBLE_ROUNDING
 
                         BEGIN_LONG_DOUBLE_ROUNDING ();
 
+                        int sign = 0;
                         if (signbit (arg)) /* arg < 0.0L or negative zero */
                           {
                             sign = -1;
@@ -4638,7 +4526,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                           {
                             int exponent;
                             long double mantissa;
-
                             if (arg > 0.0L)
                               mantissa = printf_frexpl (arg, &exponent);
                             else
@@ -4677,9 +4564,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                             *p++ = dp->conversion - 'A' + 'X';
                             pad_ptr = p;
                             {
-                              int digit;
-
-                              digit = (int) mantissa;
+                              int digit = (int) mantissa;
                               mantissa -= digit;
                               *p++ = '0' + digit;
                               if ((flags & FLAG_ALT)
@@ -4758,7 +4643,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                     else
                       {
                         int sign = 0;
-
                         if (signbit (arg)) /* arg < 0.0 or negative zero */
                           {
                             sign = -1;
@@ -4787,7 +4671,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                           {
                             int exponent;
                             double mantissa;
-
                             if (arg > 0.0)
                               mantissa = printf_frexp (arg, &exponent);
                             else
@@ -4826,9 +4709,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                             *p++ = dp->conversion - 'A' + 'X';
                             pad_ptr = p;
                             {
-                              int digit;
-
-                              digit = (int) mantissa;
+                              int digit = (int) mantissa;
                               mantissa -= digit;
                               *p++ = '0' + digit;
                               if ((flags & FLAG_ALT)
@@ -4889,7 +4770,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 
                 /* The generated string now extends from tmp to p, with the
                    zero padding insertion point being at pad_ptr.  */
-                count = p - tmp;
+                size_t count = p - tmp;
 
                 if (count < width)
                   {
@@ -4980,26 +4861,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                 arg_type type = a.arg[dp->arg_index].type;
 # endif
                 int flags = dp->flags;
-                size_t width;
-                size_t count;
-                int has_precision;
-                size_t precision;
-                size_t tmp_length;
-                DCHAR_T tmpbuf[700];
-                DCHAR_T *tmp;
-                DCHAR_T *pad_ptr;
-                DCHAR_T *p;
 
-                width = 0;
+                size_t width = 0;
                 if (dp->width_start != dp->width_end)
                   {
                     if (dp->width_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->width_arg_index].a.a_int;
+                        int arg = a.arg[dp->width_arg_index].a.a_int;
                         width = arg;
                         if (arg < 0)
                           {
@@ -5021,17 +4891,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       goto overflow;
                   }
 
-                has_precision = 0;
-                precision = 0;
+                int has_precision = 0;
+                size_t precision = 0;
                 if (dp->precision_start != dp->precision_end)
                   {
                     if (dp->precision_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->precision_arg_index].a.a_int;
+                        int arg = a.arg[dp->precision_arg_index].a.a_int;
                         /* "A negative precision is taken as if the precision
                             were omitted."  */
                         if (arg >= 0)
@@ -5060,6 +4928,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                     precision = 6;
 
                 /* Allocate a temporary buffer of sufficient size.  */
+                size_t tmp_length;
 # if NEED_PRINTF_DOUBLE && NEED_PRINTF_LONG_DOUBLE
                 tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : DBL_DIG + 1);
 # elif NEED_PRINTF_INFINITE_DOUBLE && NEED_PRINTF_LONG_DOUBLE
@@ -5124,6 +4993,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 
                 tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */
 
+                DCHAR_T tmpbuf[700];
+                DCHAR_T *tmp;
                 if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T))
                   tmp = tmpbuf;
                 else
@@ -5139,8 +5010,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       goto out_of_memory;
                   }
 
-                pad_ptr = NULL;
-                p = tmp;
+                DCHAR_T *pad_ptr = NULL;
+                DCHAR_T *p = tmp;
 
 # if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE
 #  if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
@@ -5162,11 +5033,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       }
                     else
                       {
-                        int sign = 0;
                         DECL_LONG_DOUBLE_ROUNDING
 
                         BEGIN_LONG_DOUBLE_ROUNDING ();
 
+                        int sign = 0;
                         if (signbit (arg)) /* arg < 0.0L or negative zero */
                           {
                             sign = -1;
@@ -5198,17 +5069,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 
                             if (dp->conversion == 'f' || dp->conversion == 'F')
                               {
-                                char *digits;
-                                size_t ndigits;
-
-                                digits =
+                                char *digits =
                                   scale10_round_decimal_long_double (arg, precision);
                                 if (digits == NULL)
                                   {
                                     END_LONG_DOUBLE_ROUNDING ();
                                     goto out_of_memory;
                                   }
-                                ndigits = strlen (digits);
+                                size_t ndigits = strlen (digits);
 
                                 if (ndigits > precision)
                                   {
@@ -5324,12 +5192,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                                 else
                                   {
                                     /* arg > 0.0L.  */
-                                    int adjusted;
+                                    exponent = floorlog10l (arg);
+                                    int adjusted = 0;
                                     char *digits;
                                     size_t ndigits;
-
-                                    exponent = floorlog10l (arg);
-                                    adjusted = 0;
                                     for (;;)
                                       {
                                         digits =
@@ -5457,14 +5323,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                                 else
                                   {
                                     /* arg > 0.0L.  */
-                                    int exponent;
-                                    int adjusted;
+                                    int exponent = floorlog10l (arg);
+                                    int adjusted = 0;
                                     char *digits;
                                     size_t ndigits;
-                                    size_t nzeroes;
-
-                                    exponent = floorlog10l (arg);
-                                    adjusted = 0;
                                     for (;;)
                                       {
                                         digits =
@@ -5524,7 +5386,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 
                                     /* Determine the number of trailing zeroes
                                        that have to be dropped.  */
-                                    nzeroes = 0;
+                                    size_t nzeroes = 0;
                                     if ((flags & FLAG_ALT) == 0)
                                       while (nzeroes < ndigits
                                              && digits[nzeroes] == '0')
@@ -5775,7 +5637,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                     else
                       {
                         int sign = 0;
-
                         if (signbit (arg)) /* arg < 0.0 or negative zero */
                           {
                             sign = -1;
@@ -5807,14 +5668,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 
                             if (dp->conversion == 'f' || dp->conversion == 'F')
                               {
-                                char *digits;
-                                size_t ndigits;
-
-                                digits =
+                                char *digits =
                                   scale10_round_decimal_double (arg, precision);
                                 if (digits == NULL)
                                   goto out_of_memory;
-                                ndigits = strlen (digits);
+                                size_t ndigits = strlen (digits);
 
                                 if (ndigits > precision)
                                   {
@@ -5930,12 +5788,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                                 else
                                   {
                                     /* arg > 0.0.  */
-                                    int adjusted;
+                                    exponent = floorlog10 (arg);
+                                    int adjusted = 0;
                                     char *digits;
                                     size_t ndigits;
-
-                                    exponent = floorlog10 (arg);
-                                    adjusted = 0;
                                     for (;;)
                                       {
                                         digits =
@@ -6075,14 +5931,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                                 else
                                   {
                                     /* arg > 0.0.  */
-                                    int exponent;
-                                    int adjusted;
+                                    int exponent = floorlog10 (arg);
+                                    int adjusted = 0;
                                     char *digits;
                                     size_t ndigits;
-                                    size_t nzeroes;
-
-                                    exponent = floorlog10 (arg);
-                                    adjusted = 0;
                                     for (;;)
                                       {
                                         digits =
@@ -6138,7 +5990,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 
                                     /* Determine the number of trailing zeroes
                                        that have to be dropped.  */
-                                    nzeroes = 0;
+                                    size_t nzeroes = 0;
                                     if ((flags & FLAG_ALT) == 0)
                                       while (nzeroes < ndigits
                                              && digits[nzeroes] == '0')
@@ -6374,7 +6226,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 
                 /* The generated string now extends from tmp to p, with the
                    zero padding insertion point being at pad_ptr.  */
-                count = p - tmp;
+                size_t count = p - tmp;
 
                 if (count < width)
                   {
@@ -6438,16 +6290,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
               {
                 arg_type type = a.arg[dp->arg_index].type;
                 int flags = dp->flags;
-#if (WIDE_CHAR_VERSION && MUSL_LIBC) || NEED_PRINTF_FLAG_LEFTADJUST || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION || NEED_PRINTF_FLAG_GROUPING || NEED_PRINTF_FLAG_GROUPING_INT
-                int has_width;
-#endif
-#if !USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_FLAG_LEFTADJUST || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION || NEED_PRINTF_FLAG_GROUPING || NEED_PRINTF_FLAG_GROUPING_INT
-                size_t width;
-#endif
-#if !USE_SNPRINTF || (WIDE_CHAR_VERSION && DCHAR_IS_TCHAR) || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (WIDE_CHAR_VERSION && MUSL_LIBC) || NEED_PRINTF_FLAG_LEFTADJUST || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION || NEED_PRINTF_FLAG_GROUPING || NEED_PRINTF_FLAG_GROUPING_INT
-                int has_precision;
-                size_t precision;
-#endif
 #if NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
                 int prec_ourselves;
 #else
@@ -6476,19 +6318,17 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 #endif
 
 #if (WIDE_CHAR_VERSION && MUSL_LIBC) || NEED_PRINTF_FLAG_LEFTADJUST || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION || NEED_PRINTF_FLAG_GROUPING || NEED_PRINTF_FLAG_GROUPING_INT
-                has_width = 0;
+                int has_width = 0;
 #endif
 #if !USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_FLAG_LEFTADJUST || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION || NEED_PRINTF_FLAG_GROUPING || NEED_PRINTF_FLAG_GROUPING_INT
-                width = 0;
+                size_t width = 0;
                 if (dp->width_start != dp->width_end)
                   {
                     if (dp->width_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->width_arg_index].a.a_int;
+                        int arg = a.arg[dp->width_arg_index].a.a_int;
                         width = arg;
                         if (arg < 0)
                           {
@@ -6516,17 +6356,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 #endif
 
 #if !USE_SNPRINTF || (WIDE_CHAR_VERSION && DCHAR_IS_TCHAR) || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (WIDE_CHAR_VERSION && MUSL_LIBC) || NEED_PRINTF_FLAG_LEFTADJUST || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION || NEED_PRINTF_FLAG_GROUPING || NEED_PRINTF_FLAG_GROUPING_INT
-                has_precision = 0;
-                precision = 6;
+                int has_precision = 0;
+                size_t precision = 6;
                 if (dp->precision_start != dp->precision_end)
                   {
                     if (dp->precision_arg_index != ARG_NONE)
                       {
-                        int arg;
-
                         if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
                           abort ();
-                        arg = a.arg[dp->precision_arg_index].a.a_int;
+                        int arg = a.arg[dp->precision_arg_index].a.a_int;
                         /* "A negative precision is taken as if the precision
                             were omitted."  */
                         if (arg >= 0)
@@ -6695,11 +6533,9 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                            quick check anyway.  */
                         if (dp->width_arg_index != ARG_NONE)
                           {
-                            int arg;
-
                             if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
                               abort ();
-                            arg = a.arg[dp->width_arg_index].a.a_int;
+                            int arg = a.arg[dp->width_arg_index].a.a_int;
                             width = arg;
                             if (arg < 0)
                               {
@@ -7624,16 +7460,16 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                        )
                       {
                         /* The result string is not guaranteed to be ASCII.  */
-                        const TCHAR_T *tmpsrc;
-                        DCHAR_T *tmpdst;
-                        size_t tmpdst_len;
                         /* This code assumes that TCHAR_T is 'char'.  */
                         static_assert (sizeof (TCHAR_T) == 1);
+                        const TCHAR_T *tmpsrc;
 # if USE_SNPRINTF
                         tmpsrc = (TCHAR_T *) (result + length);
 # else
                         tmpsrc = tmp;
 # endif
+                        DCHAR_T *tmpdst;
+                        size_t tmpdst_len;
 # if WIDE_CHAR_VERSION
                         /* Convert tmpsrc[0..count-1] to a freshly allocated
                            wide character array.  */
@@ -7711,8 +7547,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 # endif
                           {
                             const TCHAR_T *tmpsrc;
-                            DCHAR_T *tmpdst;
-
 # if USE_SNPRINTF
                             if (result == resultbuf)
                               {
@@ -7732,7 +7566,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                             tmpsrc = tmp;
                             ENSURE_ALLOCATION (xsum (length, count));
 # endif
-                            tmpdst = result + length;
+                            DCHAR_T *tmpdst = result + length;
                             /* Copy backwards, because of overlapping.  */
                             tmpsrc += count;
                             tmpdst += count;
@@ -7944,9 +7778,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
     if (result != resultbuf && length + 1 < allocated)
       {
         /* Shrink the allocated memory if possible.  */
-        DCHAR_T *memory;
-
-        memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T));
+        DCHAR_T *memory =
+          (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T));
         if (memory != NULL)
           result = memory;
       }
index 5db654fbcc342c0d01aacf1a1658cb521bce76b1..c9a888bcae1ca0757a81634e50d30a1882346747 100644 (file)
@@ -68,14 +68,13 @@ is_git_present (void)
       /* Test for presence of git:
          "git --version 2>/dev/null"  */
       const char *argv[3];
-      pid_t child;
-      int fd[1];
-
       argv[0] = "git";
       argv[1] = "--version";
       argv[2] = NULL;
-      child = create_pipe_in ("git", "git", argv, NULL, NULL,
-                              DEV_NULL, true, true, false, fd);
+
+      int fd[1];
+      pid_t child = create_pipe_in ("git", "git", argv, NULL, NULL,
+                                    DEV_NULL, true, true, false, fd);
       if (child == -1)
         git_present = false;
       else
@@ -140,15 +139,14 @@ git_vc_controlled (const char *filename)
   /* Run "git ls-files FILENAME" and return true if the exit code is 0
      and the output is non-empty.  */
   const char *argv[4];
-  pid_t child;
-  int fd[1];
-
   argv[0] = "git";
   argv[1] = "ls-files";
   argv[2] = filename;
   argv[3] = NULL;
-  child = create_pipe_in ("git", "git", argv, NULL, NULL,
-                          DEV_NULL, true, true, false, fd);
+
+  int fd[1];
+  pid_t child = create_pipe_in ("git", "git", argv, NULL, NULL,
+                                DEV_NULL, true, true, false, fd);
   if (child == -1)
     return false;
 
@@ -183,8 +181,6 @@ git_unmodified (const char *filename)
      and return true if the exit code is 0.
      The '--' option is for the case that the specified file was removed.  */
   const char *argv[7];
-  int exitstatus;
-
   argv[0] = "git";
   argv[1] = "diff";
   argv[2] = "--quiet";
@@ -192,9 +188,10 @@ git_unmodified (const char *filename)
   argv[4] = "HEAD";
   argv[5] = filename;
   argv[6] = NULL;
-  exitstatus = execute ("git", "git", argv, NULL, NULL,
-                        false, false, true, true,
-                        true, false, NULL);
+
+  int exitstatus = execute ("git", "git", argv, NULL, NULL,
+                            false, false, true, true,
+                            true, false, NULL);
   return (exitstatus == 0);
 }
 
@@ -210,9 +207,6 @@ git_mtime (struct timespec *mtime, const char *filename)
      of the change), as the number of seconds since the Epoch.
      The '--' option is for the case that the specified file was removed.  */
   const char *argv[7];
-  pid_t child;
-  int fd[1];
-
   argv[0] = "git";
   argv[1] = "log";
   argv[2] = "-1";
@@ -220,23 +214,21 @@ git_mtime (struct timespec *mtime, const char *filename)
   argv[4] = "--";
   argv[5] = filename;
   argv[6] = NULL;
-  child = create_pipe_in ("git", "git", argv, NULL, NULL,
-                          DEV_NULL, true, true, false, fd);
+
+  int fd[1];
+  pid_t child = create_pipe_in ("git", "git", argv, NULL, NULL,
+                                DEV_NULL, true, true, false, fd);
   if (child == -1)
     return -1;
 
   /* Retrieve its result.  */
-  FILE *fp;
-  char *line;
-  size_t linesize;
-  size_t linelen;
-
-  fp = fdopen (fd[0], "r");
+  FILE *fp = fdopen (fd[0], "r");
   if (fp == NULL)
     error (EXIT_FAILURE, errno, _("fdopen() failed"));
 
-  line = NULL; linesize = 0;
-  linelen = getline (&line, &linesize, fp);
+  char *line = NULL;
+  size_t linesize = 0;
+  size_t linelen = getline (&line, &linesize, fp);
   if (linelen == (size_t)(-1))
     {
       error (0, 0, _("%s subprocess I/O error"), "git");
@@ -245,15 +237,13 @@ git_mtime (struct timespec *mtime, const char *filename)
     }
   else
     {
-      int exitstatus;
-
       if (linelen > 0 && line[linelen - 1] == '\n')
         line[linelen - 1] = '\0';
 
       fclose (fp);
 
       /* Remove zombie process from process list, and retrieve exit status.  */
-      exitstatus =
+      int exitstatus =
         wait_subprocess (child, "git", true, false, true, false, NULL);
       if (exitstatus == 0)
         {
@@ -321,15 +311,14 @@ abs_git_checkout (void)
   /* Run "git rev-parse --show-toplevel 2>/dev/null" and return its output,
      without the trailing newline.  */
   const char *argv[4];
-  pid_t child;
-  int fd[1];
-
   argv[0] = "git";
   argv[1] = "rev-parse";
   argv[2] = "--show-toplevel";
   argv[3] = NULL;
-  child = create_pipe_in ("git", "git", argv, NULL, NULL,
-                          DEV_NULL, true, true, false, fd);
+
+  int fd[1];
+  pid_t child = create_pipe_in ("git", "git", argv, NULL, NULL,
+                                DEV_NULL, true, true, false, fd);
 
   if (child == -1)
     return NULL;
@@ -350,8 +339,6 @@ abs_git_checkout (void)
     }
   else
     {
-      int exitstatus;
-
       if (linelen > 0 && line[linelen - 1] == '\n')
         line[linelen - 1] = '\0';
 
@@ -362,7 +349,7 @@ abs_git_checkout (void)
       fclose (fp);
 
       /* Remove zombie process from process list, and retrieve exit status.  */
-      exitstatus =
+      int exitstatus =
         wait_subprocess (child, "git", true, true, true, false, NULL);
       if (exitstatus == 0)
         {
@@ -636,12 +623,10 @@ max_vc_mtime (struct timespec *max_of_mtimes,
                             }
                         if (i > i0)
                           {
-                            pid_t child;
-                            int fd[1];
-
                             argv[i] = NULL;
-                            child = create_pipe_in ("git", "git", argv, NULL, NULL,
-                                                    DEV_NULL, true, true, false, fd);
+                            int fd[1];
+                            pid_t child = create_pipe_in ("git", "git", argv, NULL, NULL,
+                                                          DEV_NULL, true, true, false, fd);
                             if (child == -1)
                               break;
 
@@ -761,12 +746,10 @@ max_vc_mtime (struct timespec *max_of_mtimes,
                             }
                         if (i > i0)
                           {
-                            pid_t child;
-                            int fd[1];
-
                             argv[i] = NULL;
-                            child = create_pipe_in ("git", "git", argv, NULL, NULL,
-                                                    DEV_NULL, true, true, false, fd);
+                            int fd[1];
+                            pid_t child = create_pipe_in ("git", "git", argv, NULL, NULL,
+                                                          DEV_NULL, true, true, false, fd);
                             if (child == -1)
                               break;
 
@@ -854,12 +837,10 @@ max_vc_mtime (struct timespec *max_of_mtimes,
                             }
                         if (i > i0)
                           {
-                            pid_t child;
-                            int fd[1];
-
                             argv[i] = NULL;
-                            child = create_pipe_in ("git", "git", argv, NULL, NULL,
-                                                    DEV_NULL, true, true, false, fd);
+                            int fd[1];
+                            pid_t child = create_pipe_in ("git", "git", argv, NULL, NULL,
+                                                          DEV_NULL, true, true, false, fd);
                             if (child == -1)
                               break;
 
index 8d790745dc9a178e2bcc6727428daac04dedceb4..621458c9030219040590c947333fb65207403d06 100644 (file)
@@ -33,12 +33,9 @@ off64_t
 vdzprintf (int fd, const char *format, va_list args)
 {
   char buf[2000];
-  char *output;
-  size_t len;
   size_t lenbuf = sizeof (buf);
-
-  output = vasnprintf (buf, &lenbuf, format, args);
-  len = lenbuf;
+  char *output = vasnprintf (buf, &lenbuf, format, args);
+  size_t len = lenbuf;
 
   if (!output)
     return -1;
index bb108ffd2f2112c553002709f33e616e5d5430a4..1b652ae56b2e0f58b97f1cb95ed3fbfab4dbea1d 100644 (file)
@@ -232,7 +232,6 @@ version_etc (FILE *stream,
              const char *version, /* const char *author1, ...*/ ...)
 {
   va_list authors;
-
   va_start (authors, version);
   version_etc_va (stream, command_name, package, version, authors);
   va_end (authors);
index ceac4a1961522b2c6d220931533179b4255b8da8..e6f3fa0af546d4c7dbe5595f5592fe40a79a094e 100644 (file)
@@ -33,12 +33,9 @@ off64_t
 vfzprintf (FILE *fp, const char *format, va_list args)
 {
   char buf[2000];
-  char *output;
-  size_t len;
   size_t lenbuf = sizeof (buf);
-
-  output = vasnprintf (buf, &lenbuf, format, args);
-  len = lenbuf;
+  char *output = vasnprintf (buf, &lenbuf, format, args);
+  size_t len = lenbuf;
 
   if (!output)
     {
index 9b59f50ec37c46cfa1d61e6b8932fc09a2282591..bc4a22066f289735a49bf9b97bc8536aac22dc4c 100644 (file)
@@ -177,19 +177,15 @@ struct rofile
 static int
 rof_open (struct rofile *rof, const char *filename)
 {
-  int fd;
-  unsigned long pagesize;
-  size_t size;
-
-  fd = open (filename, O_RDONLY | O_CLOEXEC);
+  int fd = open (filename, O_RDONLY | O_CLOEXEC);
   if (fd < 0)
     return -1;
   rof->position = 0;
   rof->eof_seen = 0;
   /* Try the static buffer first.  */
-  pagesize = 0;
+  unsigned long pagesize = 0;
   rof->buffer = rof->stack_allocated_buffer;
-  size = sizeof (rof->stack_allocated_buffer);
+  size_t size = sizeof (rof->stack_allocated_buffer);
   rof->auxmap = NULL;
   rof->auxmap_start = 0;
   rof->auxmap_end = 0;
@@ -366,30 +362,31 @@ vma_iterate_proc (vma_iterate_callback_fn callback, void *data)
 
       for (;;)
         {
-          unsigned long start, end;
-          unsigned int flags;
-          int c;
-
           /* Parse one line.  First start and end.  */
+          unsigned long start, end;
           if (!(rof_scanf_lx (&rof, &start) >= 0
                 && rof_getchar (&rof) == '-'
                 && rof_scanf_lx (&rof, &end) >= 0))
             break;
           /* Then the flags.  */
-          do
+          unsigned int flags;
+          {
+            int c;
+            do
+              c = rof_getchar (&rof);
+            while (c == ' ');
+            flags = 0;
+            if (c == 'r')
+              flags |= VMA_PROT_READ;
+            c = rof_getchar (&rof);
+            if (c == 'w')
+              flags |= VMA_PROT_WRITE;
             c = rof_getchar (&rof);
-          while (c == ' ');
-          flags = 0;
-          if (c == 'r')
-            flags |= VMA_PROT_READ;
-          c = rof_getchar (&rof);
-          if (c == 'w')
-            flags |= VMA_PROT_WRITE;
-          c = rof_getchar (&rof);
-          if (c == 'x')
-            flags |= VMA_PROT_EXECUTE;
-          while (c = rof_getchar (&rof), c != -1 && c != '\n')
-            ;
+            if (c == 'x')
+              flags |= VMA_PROT_EXECUTE;
+            while (c = rof_getchar (&rof), c != -1 && c != '\n')
+              ;
+          }
 
           if (start <= auxmap_start && auxmap_end - 1 <= end - 1)
             {
@@ -430,60 +427,68 @@ vma_iterate_proc (vma_iterate_callback_fn callback, void *data)
 
       for (;;)
         {
-          unsigned long start, end;
-          unsigned int flags;
-          int c;
-
           /* Parse one line.  First start.  */
+          unsigned long start;
           if (!(rof_getchar (&rof) == '0'
                 && rof_getchar (&rof) == 'x'
                 && rof_scanf_lx (&rof, &start) >= 0))
             break;
-          while (c = rof_peekchar (&rof), c == ' ' || c == '\t')
-            rof_getchar (&rof);
+          {
+            int c;
+            while (c = rof_peekchar (&rof), c == ' ' || c == '\t')
+              rof_getchar (&rof);
+          }
           /* Then end.  */
+          unsigned long end;
           if (!(rof_getchar (&rof) == '0'
                 && rof_getchar (&rof) == 'x'
                 && rof_scanf_lx (&rof, &end) >= 0))
             break;
 # if defined __FreeBSD__ || defined __DragonFly__
-          /* Then the resident pages count.  */
-          do
-            c = rof_getchar (&rof);
-          while (c == ' ');
-          do
-            c = rof_getchar (&rof);
-          while (c != -1 && c != '\n' && c != ' ');
-          /* Then the private resident pages count.  */
-          do
-            c = rof_getchar (&rof);
-          while (c == ' ');
-          do
-            c = rof_getchar (&rof);
-          while (c != -1 && c != '\n' && c != ' ');
-          /* Then some kernel address.  */
-          do
-            c = rof_getchar (&rof);
-          while (c == ' ');
-          do
-            c = rof_getchar (&rof);
-          while (c != -1 && c != '\n' && c != ' ');
+          {
+            int c;
+            /* Then the resident pages count.  */
+            do
+              c = rof_getchar (&rof);
+            while (c == ' ');
+            do
+              c = rof_getchar (&rof);
+            while (c != -1 && c != '\n' && c != ' ');
+            /* Then the private resident pages count.  */
+            do
+              c = rof_getchar (&rof);
+            while (c == ' ');
+            do
+              c = rof_getchar (&rof);
+            while (c != -1 && c != '\n' && c != ' ');
+            /* Then some kernel address.  */
+            do
+              c = rof_getchar (&rof);
+            while (c == ' ');
+            do
+              c = rof_getchar (&rof);
+            while (c != -1 && c != '\n' && c != ' ');
+          }
 # endif
           /* Then the flags.  */
-          do
+          unsigned int flags;
+          {
+            int c;
+            do
+              c = rof_getchar (&rof);
+            while (c == ' ');
+            flags = 0;
+            if (c == 'r')
+              flags |= VMA_PROT_READ;
+            c = rof_getchar (&rof);
+            if (c == 'w')
+              flags |= VMA_PROT_WRITE;
             c = rof_getchar (&rof);
-          while (c == ' ');
-          flags = 0;
-          if (c == 'r')
-            flags |= VMA_PROT_READ;
-          c = rof_getchar (&rof);
-          if (c == 'w')
-            flags |= VMA_PROT_WRITE;
-          c = rof_getchar (&rof);
-          if (c == 'x')
-            flags |= VMA_PROT_EXECUTE;
-          while (c = rof_getchar (&rof), c != -1 && c != '\n')
-            ;
+            if (c == 'x')
+              flags |= VMA_PROT_EXECUTE;
+            while (c = rof_getchar (&rof), c != -1 && c != '\n')
+              ;
+          }
 
           if (start <= auxmap_start && auxmap_end - 1 <= end - 1)
             {
@@ -515,11 +520,8 @@ static int
 vma_iterate_proc (vma_iterate_callback_fn callback, void *data)
 {
   char fnamebuf[6+10+4+1];
-  char *fname;
-  struct rofile rof;
-
   /* Construct fname = sprintf (fnamebuf+i, "/proc/%u/map", getpid ()).  */
-  fname = fnamebuf + sizeof (fnamebuf) - (4 + 1);
+  char *fname = fnamebuf + sizeof (fnamebuf) - (4 + 1);
   memcpy (fname, "/map", 4 + 1);
   {
     unsigned int value = getpid ();
@@ -531,6 +533,7 @@ vma_iterate_proc (vma_iterate_callback_fn callback, void *data)
   memcpy (fname, "/proc/", 6);
 
   /* Open the current process' maps file.  It describes one VMA per line.  */
+  struct rofile rof;
   if (rof_open (&rof, fname) >= 0)
     {
       unsigned long auxmap_start = rof.auxmap_start;
@@ -538,30 +541,31 @@ vma_iterate_proc (vma_iterate_callback_fn callback, void *data)
 
       for (;;)
         {
-          unsigned long start, end;
-          unsigned int flags;
-          int c;
-
           /* Parse one line.  First start and end.  */
+          unsigned long start, end;
           if (!(rof_scanf_lx (&rof, &start) >= 0
                 && rof_getchar (&rof) == '-'
                 && rof_scanf_lx (&rof, &end) >= 0))
             break;
           /* Then the flags.  */
-          do
+          unsigned int flags;
+          {
+            int c;
+            do
+              c = rof_getchar (&rof);
+            while (c == ' ');
+            flags = 0;
+            if (c == 'r')
+              flags |= VMA_PROT_READ;
+            c = rof_getchar (&rof);
+            if (c == 'w')
+              flags |= VMA_PROT_WRITE;
             c = rof_getchar (&rof);
-          while (c == ' ');
-          flags = 0;
-          if (c == 'r')
-            flags |= VMA_PROT_READ;
-          c = rof_getchar (&rof);
-          if (c == 'w')
-            flags |= VMA_PROT_WRITE;
-          c = rof_getchar (&rof);
-          if (c == 'x')
-            flags |= VMA_PROT_EXECUTE;
-          while (c = rof_getchar (&rof), c != -1 && c != '\n')
-            ;
+            if (c == 'x')
+              flags |= VMA_PROT_EXECUTE;
+            while (c = rof_getchar (&rof), c != -1 && c != '\n')
+              ;
+          }
 
           if (start <= auxmap_start && auxmap_end - 1 <= end - 1)
             {
@@ -607,17 +611,7 @@ vma_iterate_bsd (vma_iterate_callback_fn callback, void *data)
 {
   /* Documentation: https://www.freebsd.org/cgi/man.cgi?sysctl(3)  */
   int info_path[] = { CTL_KERN, KERN_PROC, KERN_PROC_VMMAP, getpid () };
-  size_t len;
-  size_t pagesize;
-  size_t memneed;
-  void *auxmap;
-  unsigned long auxmap_start;
-  unsigned long auxmap_end;
-  char *mem;
-  char *p;
-  char *p_end;
-
-  len = 0;
+  size_t len = 0;
   if (sysctl (info_path, 4, NULL, &len, NULL, 0) < 0)
     return -1;
   /* Allow for small variations over time.  In a multithreaded program
@@ -628,53 +622,55 @@ vma_iterate_bsd (vma_iterate_callback_fn callback, void *data)
      We also cannot use malloc here, because a malloc() call may call mmap()
      and thus pre-allocate available memory.
      So use mmap(), and ignore the resulting VMA.  */
-  pagesize = getpagesize ();
-  memneed = len;
+  size_t pagesize = getpagesize ();
+  size_t memneed = len;
   memneed = ((memneed - 1) / pagesize + 1) * pagesize;
-  auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
-                          MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+  void *auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
+                                MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
   if (auxmap == (void *) -1)
     return -1;
-  auxmap_start = (unsigned long) auxmap;
-  auxmap_end = auxmap_start + memneed;
-  mem = (char *) auxmap;
+  unsigned long auxmap_start = (unsigned long) auxmap;
+  unsigned long auxmap_end = auxmap_start + memneed;
+  char *mem = (char *) auxmap;
   if (sysctl (info_path, 4, mem, &len, NULL, 0) < 0)
     {
       munmap (auxmap, memneed);
       return -1;
     }
-  p = mem;
-  p_end = mem + len;
-  while (p < p_end)
-    {
-      struct kinfo_vmentry *kve = (struct kinfo_vmentry *) p;
-      unsigned long start = kve->kve_start;
-      unsigned long end = kve->kve_end;
-      unsigned int flags = 0;
-      if (kve->kve_protection & KVME_PROT_READ)
-        flags |= VMA_PROT_READ;
-      if (kve->kve_protection & KVME_PROT_WRITE)
-        flags |= VMA_PROT_WRITE;
-      if (kve->kve_protection & KVME_PROT_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)
-            if (callback (data, start, auxmap_start, flags))
-              break;
-          if (auxmap_end - 1 < end - 1)
-            if (callback (data, auxmap_end, end, flags))
+  {
+    char *p = mem;
+    char *p_end = mem + len;
+    while (p < p_end)
+      {
+        struct kinfo_vmentry *kve = (struct kinfo_vmentry *) p;
+        unsigned long start = kve->kve_start;
+        unsigned long end = kve->kve_end;
+        unsigned int flags = 0;
+        if (kve->kve_protection & KVME_PROT_READ)
+          flags |= VMA_PROT_READ;
+        if (kve->kve_protection & KVME_PROT_WRITE)
+          flags |= VMA_PROT_WRITE;
+        if (kve->kve_protection & KVME_PROT_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)
+              if (callback (data, start, auxmap_start, flags))
+                break;
+            if (auxmap_end - 1 < end - 1)
+              if (callback (data, auxmap_end, end, flags))
+                break;
+          }
+        else
+          {
+            if (callback (data, start, end, flags))
               break;
-        }
-      else
-        {
-          if (callback (data, start, end, flags))
-            break;
-        }
-      p += kve->kve_structsize;
-    }
+          }
+        p += kve->kve_structsize;
+      }
+  }
   munmap (auxmap, memneed);
   return 0;
 }
@@ -691,17 +687,7 @@ vma_iterate_bsd (vma_iterate_callback_fn callback, void *data)
        parts of each entry.  */
     offsetof (struct kinfo_vmentry, kve_path);
   int info_path[] = { CTL_VM, VM_PROC, VM_PROC_MAP, getpid (), entry_size };
-  size_t len;
-  size_t pagesize;
-  size_t memneed;
-  void *auxmap;
-  unsigned long auxmap_start;
-  unsigned long auxmap_end;
-  char *mem;
-  char *p;
-  char *p_end;
-
-  len = 0;
+  size_t len = 0;
   if (sysctl (info_path, 5, NULL, &len, NULL, 0) < 0)
     return -1;
   /* Allow for small variations over time.  In a multithreaded program
@@ -718,16 +704,16 @@ vma_iterate_bsd (vma_iterate_callback_fn callback, void *data)
      We also cannot use malloc here, because a malloc() call may call mmap()
      and thus pre-allocate available memory.
      So use mmap(), and ignore the resulting VMA.  */
-  pagesize = getpagesize ();
-  memneed = len;
+  size_t pagesize = getpagesize ();
+  size_t memneed = len;
   memneed = ((memneed - 1) / pagesize + 1) * pagesize;
-  auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
-                          MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+  void *auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
+                                MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
   if (auxmap == (void *) -1)
     return -1;
-  auxmap_start = (unsigned long) auxmap;
-  auxmap_end = auxmap_start + memneed;
-  mem = (char *) auxmap;
+  unsigned long auxmap_start = (unsigned long) auxmap;
+  unsigned long auxmap_end = auxmap_start + memneed;
+  char *mem = (char *) auxmap;
   if (sysctl (info_path, 5, mem, &len, NULL, 0) < 0
       || len > 0x100000 - entry_size)
     {
@@ -735,38 +721,40 @@ vma_iterate_bsd (vma_iterate_callback_fn callback, void *data)
       munmap (auxmap, memneed);
       return -1;
     }
-  p = mem;
-  p_end = mem + len;
-  while (p < p_end)
-    {
-      struct kinfo_vmentry *kve = (struct kinfo_vmentry *) p;
-      unsigned long start = kve->kve_start;
-      unsigned long end = kve->kve_end;
-      unsigned int flags = 0;
-      if (kve->kve_protection & KVME_PROT_READ)
-        flags |= VMA_PROT_READ;
-      if (kve->kve_protection & KVME_PROT_WRITE)
-        flags |= VMA_PROT_WRITE;
-      if (kve->kve_protection & KVME_PROT_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)
-            if (callback (data, start, auxmap_start, flags))
-              break;
-          if (auxmap_end - 1 < end - 1)
-            if (callback (data, auxmap_end, end, flags))
+  {
+    char *p = mem;
+    char *p_end = mem + len;
+    while (p < p_end)
+      {
+        struct kinfo_vmentry *kve = (struct kinfo_vmentry *) p;
+        unsigned long start = kve->kve_start;
+        unsigned long end = kve->kve_end;
+        unsigned int flags = 0;
+        if (kve->kve_protection & KVME_PROT_READ)
+          flags |= VMA_PROT_READ;
+        if (kve->kve_protection & KVME_PROT_WRITE)
+          flags |= VMA_PROT_WRITE;
+        if (kve->kve_protection & KVME_PROT_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)
+              if (callback (data, start, auxmap_start, flags))
+                break;
+            if (auxmap_end - 1 < end - 1)
+              if (callback (data, auxmap_end, end, flags))
+                break;
+          }
+        else
+          {
+            if (callback (data, start, end, flags))
               break;
-        }
-      else
-        {
-          if (callback (data, start, end, flags))
-            break;
-        }
-      p += entry_size;
-    }
+          }
+        p += entry_size;
+      }
+  }
   munmap (auxmap, memneed);
   return 0;
 }
@@ -778,15 +766,7 @@ vma_iterate_bsd (vma_iterate_callback_fn callback, void *data)
 {
   /* Documentation: https://man.openbsd.org/sysctl.2  */
   int info_path[] = { CTL_KERN, KERN_PROC_VMMAP, getpid () };
-  size_t len;
-  size_t pagesize;
-  size_t memneed;
-  void *auxmap;
-  unsigned long auxmap_start;
-  unsigned long auxmap_end;
-  char *mem;
-
-  len = 0;
+  size_t len = 0;
   if (sysctl (info_path, 3, NULL, &len, NULL, 0) < 0)
     return -1;
   /* Allow for small variations over time.  In a multithreaded program
@@ -810,23 +790,20 @@ vma_iterate_bsd (vma_iterate_callback_fn callback, void *data)
      We also cannot use malloc here, because a malloc() call may call mmap()
      and thus pre-allocate available memory.
      So use mmap(), and ignore the resulting VMA.  */
-  pagesize = getpagesize ();
-  memneed = len;
+  size_t pagesize = getpagesize ();
+  size_t memneed = len;
   memneed = ((memneed - 1) / pagesize + 1) * pagesize;
-  auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
-                          MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+  void *auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
+                                MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
   if (auxmap == (void *) -1)
     return -1;
-  auxmap_start = (unsigned long) auxmap;
-  auxmap_end = auxmap_start + memneed;
-  mem = (char *) auxmap;
+  unsigned long auxmap_start = (unsigned long) auxmap;
+  unsigned long auxmap_end = auxmap_start + memneed;
+  char *mem = (char *) auxmap;
 
   for (;;)
     {
       size_t rlen = len;
-      char *p;
-      char *p_end;
-
       if (sysctl (info_path, 3, mem, &rlen, NULL, 0) < 0)
         {
           /* sysctl failed.  */
@@ -835,39 +812,41 @@ vma_iterate_bsd (vma_iterate_callback_fn callback, void *data)
         }
       if (rlen == 0)
         break;
-      p = mem;
-      p_end = mem + rlen;
-      while (p < p_end)
-        {
-          struct kinfo_vmentry *kve = (struct kinfo_vmentry *) p;
-          unsigned long start = kve->kve_start;
-          unsigned long end = kve->kve_end;
-          unsigned int flags = 0;
-          if (kve->kve_protection & KVE_PROT_READ)
-            flags |= VMA_PROT_READ;
-          if (kve->kve_protection & KVE_PROT_WRITE)
-            flags |= VMA_PROT_WRITE;
-          if (kve->kve_protection & KVE_PROT_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)
-                if (callback (data, start, auxmap_start, flags))
-                  break;
-              if (auxmap_end - 1 < end - 1)
-                if (callback (data, auxmap_end, end, flags))
-                  break;
-            }
-          else
-            {
-              if (start != end)
-                if (callback (data, start, end, flags))
-                  break;
-            }
-          p += sizeof (struct kinfo_vmentry);
-        }
+      char *p_end = mem + rlen;
+      {
+        char *p = mem;
+        while (p < p_end)
+          {
+            struct kinfo_vmentry *kve = (struct kinfo_vmentry *) p;
+            unsigned long start = kve->kve_start;
+            unsigned long end = kve->kve_end;
+            unsigned int flags = 0;
+            if (kve->kve_protection & KVE_PROT_READ)
+              flags |= VMA_PROT_READ;
+            if (kve->kve_protection & KVE_PROT_WRITE)
+              flags |= VMA_PROT_WRITE;
+            if (kve->kve_protection & KVE_PROT_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)
+                  if (callback (data, start, auxmap_start, flags))
+                    break;
+                if (auxmap_end - 1 < end - 1)
+                  if (callback (data, auxmap_end, end, flags))
+                    break;
+              }
+            else
+              {
+                if (start != end)
+                  if (callback (data, start, end, flags))
+                    break;
+              }
+            p += sizeof (struct kinfo_vmentry);
+          }
+      }
       if (rlen < len)
         break;
       /* sysctl returned exactly len entries, which means that another sysctl
@@ -1003,16 +982,11 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
      only the virtual memory areas that are connected to a file, not the
      anonymous ones.  But at least since AIX 7.1, it is well usable.  */
 
-  size_t pagesize;
-  char fnamebuf[6+10+4+1];
-  char *fname;
-  int fd;
-  size_t memneed;
-
-  pagesize = getpagesize ();
+  size_t pagesize = getpagesize ();
 
+  char fnamebuf[6+10+4+1];
   /* Construct fname = sprintf (fnamebuf+i, "/proc/%u/map", getpid ()).  */
-  fname = fnamebuf + sizeof (fnamebuf) - (4+1);
+  char *fname = fnamebuf + sizeof (fnamebuf) - (4+1);
   memcpy (fname, "/map", 4+1);
   {
     unsigned int value = getpid ();
@@ -1023,7 +997,7 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
   fname -= 6;
   memcpy (fname, "/proc/", 6);
 
-  fd = open (fname, O_RDONLY | O_CLOEXEC);
+  int fd = open (fname, O_RDONLY | O_CLOEXEC);
   if (fd < 0)
     return -1;
 
@@ -1034,7 +1008,7 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
      We read the entire contents, but look only at the prmap_t entries and
      ignore the tail part.  */
 
-  for (memneed = 2 * pagesize; ; memneed = 2 * memneed)
+  for (size_t memneed = 2 * pagesize; ; memneed = 2 * memneed)
     {
       /* Allocate memneed bytes of memory.
          We cannot use alloca here, because not much stack space is guaranteed.
@@ -1043,25 +1017,21 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
          So use mmap(), and ignore the resulting VMA if it occurs among the
          resulting VMAs.  (Normally it doesn't, because it was allocated after
          the open() call.)  */
-      void *auxmap;
-      unsigned long auxmap_start;
-      unsigned long auxmap_end;
-      ssize_t nbytes;
-
-      auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
-                              MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+      void *auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
+                                    MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
       if (auxmap == (void *) -1)
         {
           close (fd);
           return -1;
         }
-      auxmap_start = (unsigned long) auxmap;
-      auxmap_end = auxmap_start + memneed;
+      unsigned long auxmap_start = (unsigned long) auxmap;
+      unsigned long auxmap_end = auxmap_start + memneed;
 
       /* Read the contents of /proc/<pid>/map in a single system call.
          This guarantees a consistent result (no duplicated or omitted
          entries).  */
-     retry:
+     retry: ;
+      ssize_t nbytes;
       do
         nbytes = read (fd, auxmap, memneed);
       while (nbytes < 0 && errno == EINTR);
@@ -1096,7 +1066,7 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
             }
 
           /* We now have the entire contents of /proc/<pid>/map in memory.  */
-          prmap_tmaps = (prmap_t *) auxmap;
+          prmap_t *maps = (prmap_t *) auxmap;
 
           /* The entries are not sorted by address.  Therefore
              1. Extract the relevant information into an array.
@@ -1116,17 +1086,14 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
           vma_t *vp = vmas;
           for (prmap_t *mp = maps;;)
             {
-              unsigned long start, end;
-
-              start = (unsigned long) mp->pr_vaddr;
-              end = start + mp->pr_size;
+              unsigned long start = (unsigned long) mp->pr_vaddr;
+              unsigned long 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;
+                  unsigned int flags = 0;
                   if (mp->pr_mflags & MA_READ)
                     flags |= VMA_PROT_READ;
                   if (mp->pr_mflags & MA_WRITE)
@@ -1213,21 +1180,11 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
 # if defined PIOCNMAP && defined PIOCMAP
   /* We must use the older /proc interface.  */
 
-  size_t pagesize;
-  char fnamebuf[6+10+1];
-  char *fname;
-  int fd;
-  int nmaps;
-  size_t memneed;
-  void *auxmap;
-  unsigned long auxmap_start;
-  unsigned long auxmap_end;
-  prmap_t* maps;
-
-  pagesize = getpagesize ();
+  size_t pagesize = getpagesize ();
 
+  char fnamebuf[6+10+1];
   /* Construct fname = sprintf (fnamebuf+i, "/proc/%u", getpid ()).  */
-  fname = fnamebuf + sizeof (fnamebuf) - 1;
+  char *fname = fnamebuf + sizeof (fnamebuf) - 1;
   *fname = '\0';
   {
     unsigned int value = getpid ();
@@ -1238,41 +1195,39 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
   fname -= 6;
   memcpy (fname, "/proc/", 6);
 
-  fd = open (fname, O_RDONLY | O_CLOEXEC);
+  int fd = open (fname, O_RDONLY | O_CLOEXEC);
   if (fd < 0)
     return -1;
 
+  int nmaps;
   if (ioctl (fd, PIOCNMAP, &nmaps) < 0)
     goto fail2;
 
-  memneed = (nmaps + 10) * sizeof (prmap_t);
+  size_t memneed = (nmaps + 10) * sizeof (prmap_t);
   /* Allocate memneed bytes of memory.
      We cannot use alloca here, because not much stack space is guaranteed.
      We also cannot use malloc here, because a malloc() call may call mmap()
      and thus pre-allocate available memory.
      So use mmap(), and ignore the resulting VMA.  */
   memneed = ((memneed - 1) / pagesize + 1) * pagesize;
-  auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
-                          MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+  void *auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
+                                MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
   if (auxmap == (void *) -1)
     goto fail2;
-  auxmap_start = (unsigned long) auxmap;
-  auxmap_end = auxmap_start + memneed;
-  maps = (prmap_t *) auxmap;
+  unsigned long auxmap_start = (unsigned long) auxmap;
+  unsigned long auxmap_end = auxmap_start + memneed;
+  prmap_t *maps = (prmap_t *) auxmap;
 
   if (ioctl (fd, PIOCMAP, maps) < 0)
     goto fail1;
 
   for (prmap_t *mp = maps;;)
     {
-      unsigned long start, end;
-      unsigned int flags;
-
-      start = (unsigned long) mp->pr_vaddr;
-      end = start + mp->pr_size;
+      unsigned long start = (unsigned long) mp->pr_vaddr;
+      unsigned long end = start + mp->pr_size;
       if (start == 0 && end == 0)
         break;
-      flags = 0;
+      unsigned int flags = 0;
       if (mp->pr_mflags & MA_READ)
         flags |= VMA_PROT_READ;
       if (mp->pr_mflags & MA_WRITE)
@@ -1315,22 +1270,11 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
      prmap_t.  These are different in 32-bit and 64-bit processes,
      but here we are fortunately accessing only the current process.  */
 
-  size_t pagesize;
-  char fnamebuf[6+10+4+1];
-  char *fname;
-  int fd;
-  int nmaps;
-  size_t memneed;
-  void *auxmap;
-  unsigned long auxmap_start;
-  unsigned long auxmap_end;
-  prmap_t* maps;
-  prmap_t* maps_end;
-
-  pagesize = getpagesize ();
+  size_t pagesize = getpagesize ();
 
+  char fnamebuf[6+10+4+1];
   /* Construct fname = sprintf (fnamebuf+i, "/proc/%u/map", getpid ()).  */
-  fname = fnamebuf + sizeof (fnamebuf) - 1 - 4;
+  char *fname = fnamebuf + sizeof (fnamebuf) - 1 - 4;
   memcpy (fname, "/map", 4 + 1);
   {
     unsigned int value = getpid ();
@@ -1341,10 +1285,11 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
   fname -= 6;
   memcpy (fname, "/proc/", 6);
 
-  fd = open (fname, O_RDONLY | O_CLOEXEC);
+  int fd = open (fname, O_RDONLY | O_CLOEXEC);
   if (fd < 0)
     return -1;
 
+  int nmaps;
   {
     struct stat statbuf;
     if (fstat (fd, &statbuf) < 0)
@@ -1352,22 +1297,23 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
     nmaps = statbuf.st_size / sizeof (prmap_t);
   }
 
-  memneed = (nmaps + 10) * sizeof (prmap_t);
+  size_t memneed = (nmaps + 10) * sizeof (prmap_t);
   /* Allocate memneed bytes of memory.
      We cannot use alloca here, because not much stack space is guaranteed.
      We also cannot use malloc here, because a malloc() call may call mmap()
      and thus pre-allocate available memory.
      So use mmap(), and ignore the resulting VMA.  */
   memneed = ((memneed - 1) / pagesize + 1) * pagesize;
-  auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
-                          MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+  void *auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
+                                MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
   if (auxmap == (void *) -1)
     goto fail2;
-  auxmap_start = (unsigned long) auxmap;
-  auxmap_end = auxmap_start + memneed;
-  maps = (prmap_t *) auxmap;
+  unsigned long auxmap_start = (unsigned long) auxmap;
+  unsigned long auxmap_end = auxmap_start + memneed;
+  prmap_t *maps = (prmap_t *) auxmap;
 
   /* Read up to memneed bytes from fd into maps.  */
+  prmap_t *maps_end;
   {
     size_t remaining = memneed;
     size_t total_read = 0;
@@ -1397,12 +1343,9 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
 
   for (prmap_t *mp = maps; mp < maps_end; mp++)
     {
-      unsigned long start, end;
-      unsigned int flags;
-
-      start = (unsigned long) mp->pr_vaddr;
-      end = start + mp->pr_size;
-      flags = 0;
+      unsigned long start = (unsigned long) mp->pr_vaddr;
+      unsigned long end = start + mp->pr_size;
+      unsigned int flags = 0;
       if (mp->pr_mflags & MA_READ)
         flags |= VMA_PROT_READ;
       if (mp->pr_mflags & MA_WRITE)
@@ -1475,7 +1418,6 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
     {
       int more;
       mach_port_t object_name;
-      unsigned int flags;
       /* In Mac OS X 10.5, the types vm_address_t, vm_offset_t, vm_size_t have
          32 bits in 32-bit processes and 64 bits in 64-bit processes. Whereas
          mach_vm_address_t and mach_vm_size_t are always 64 bits large.
@@ -1515,7 +1457,7 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
         mach_port_deallocate (mach_task_self (), object_name);
       if (!more)
         break;
-      flags = 0;
+      unsigned int flags = 0;
       if (info.protection & VM_PROT_READ)
         flags |= VMA_PROT_READ;
       if (info.protection & VM_PROT_WRITE)
@@ -1536,24 +1478,23 @@ 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_size_t size;
 
-  for (vm_address_t address = 0;; address += size)
+  for (vm_address_t address = 0;; )
     {
+      vm_size_t size;
       vm_prot_t protection;
       vm_prot_t max_protection;
       vm_inherit_t inheritance;
       boolean_t shared;
       memory_object_name_t object_name;
       vm_offset_t offset;
-      unsigned int flags;
 
       if (!(vm_region (task, &address, &size, &protection, &max_protection,
-                         &inheritance, &shared, &object_name, &offset)
+                       &inheritance, &shared, &object_name, &offset)
             == KERN_SUCCESS))
         break;
       mach_port_deallocate (task, object_name);
-      flags = 0;
+      unsigned int flags = 0;
       if (protection & VM_PROT_READ)
         flags |= VMA_PROT_READ;
       if (protection & VM_PROT_WRITE)
@@ -1562,15 +1503,16 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
         flags |= VMA_PROT_EXECUTE;
       if (callback (data, address, address + size, flags))
         break;
+
+      address += size;
     }
   return 0;
 
 #elif defined _WIN32 || defined __CYGWIN__
   /* Windows platform.  Use the native Windows API.  */
 
-  MEMORY_BASIC_INFORMATION info;
   uintptr_t address = 0;
-
+  MEMORY_BASIC_INFORMATION info;
   while (VirtualQuery ((void*)address, &info, sizeof(info)) == sizeof(info))
     {
       if (info.State != MEM_FREE)
@@ -1580,11 +1522,9 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
            distinguished from areas reserved for future malloc().  */
         if (info.State != MEM_RESERVE)
           {
-            uintptr_t start, end;
+            uintptr_t start = (uintptr_t)info.BaseAddress;
+            uintptr_t end = start + info.RegionSize;
             unsigned int flags;
-
-            start = (uintptr_t)info.BaseAddress;
-            end = start + info.RegionSize;
             switch (info.Protect & ~(PAGE_GUARD|PAGE_NOCACHE))
               {
               case PAGE_READONLY:
@@ -1620,18 +1560,13 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
 #elif defined __BEOS__ || defined __HAIKU__
   /* Use the BeOS specific API.  */
 
+  ssize_t cookie = 0;
   area_info info;
-  ssize_t cookie;
-
-  cookie = 0;
   while (get_next_area_info (0, &cookie, &info) == B_OK)
     {
-      unsigned long start, end;
-      unsigned int flags;
-
-      start = (unsigned long) info.address;
-      end = start + info.size;
-      flags = 0;
+      unsigned long start = (unsigned long) info.address;
+      unsigned long end = start + info.size;
+      unsigned int flags = 0;
       if (info.protection & B_READ_AREA)
         flags |= VMA_PROT_READ;
       if (info.protection & B_WRITE_AREA)
@@ -1660,15 +1595,11 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
 # endif
 
   {
-    uintptr_t pagesize;
-    uintptr_t address;
-    int /*bool*/ address_known_mapped;
-
-    pagesize = getpagesize ();
+    uintptr_t pagesize = getpagesize ();
     /* Avoid calling mquery with a NULL first argument, because this argument
        value has a specific meaning.  We know the NULL page is unmapped.  */
-    address = pagesize;
-    address_known_mapped = 0;
+    uintptr_t address = pagesize;
+    int /*bool*/ address_known_mapped = 0;
     for (;;)
       {
         /* Test whether the page at address is mapped.  */
@@ -1679,12 +1610,13 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
             /* The page at address is mapped.
                This is the start of an interval.  */
             uintptr_t start = address;
-            uintptr_t end;
 
             /* Find the end of the interval.  */
-            end = (uintptr_t) mquery ((void *) address, pagesize, 0, 0, -1, 0);
+            uintptr_t end =
+              (uintptr_t) mquery ((void *) address, pagesize, 0, 0, -1, 0);
             if (end == (uintptr_t) (void *) -1)
               end = 0; /* wrap around */
+
             address = end;
 
             /* When wrapping around, OpenBSD 7.6/x86_64 produces an interval
index f6e6b1d4d5a04452ea2410ebf80e670820bd173a..46371f47b0afc595d90a3a8f9ed632addf6b7cde 100644 (file)
 ptrdiff_t
 vsnzprintf (char *str, size_t size, const char *format, va_list args)
 {
-  char *output;
-  size_t len;
   size_t lenbuf = size;
-
-  output = vasnprintf (str, &lenbuf, format, args);
-  len = lenbuf;
+  char *output = vasnprintf (str, &lenbuf, format, args);
+  size_t len = lenbuf;
 
   if (!output)
     return -1;
index 0734b176b783ae37bb612a9991b9cb6cf4e33a8e..14f3b3a92afb44bf4e05f0a3cb1fc675908faf7f 100644 (file)
 ptrdiff_t
 vszprintf (char *str, const char *format, va_list args)
 {
-  char *output;
-  size_t len;
-  size_t lenbuf;
-
   /* Set lenbuf = min (SIZE_MAX, - (uintptr_t) str - 1).  */
-  lenbuf = SIZE_MAX;
+  size_t lenbuf = SIZE_MAX;
   if (lenbuf >= ~ (uintptr_t) str)
     lenbuf = ~ (uintptr_t) str;
 
-  output = vasnprintf (str, &lenbuf, format, args);
-  len = lenbuf;
+  char *output = vasnprintf (str, &lenbuf, format, args);
+  size_t len = lenbuf;
 
   if (!output)
     return -1;
index c2331bb522baa64f040f193556d0bf4933bc1762..efc8cd1f18640d207d938cabf11ae193d05088e2 100644 (file)
@@ -66,12 +66,10 @@ klibc_waitpid (pid_t pid, int *statusp, int options)
 
   if (waitpid_pfn == NULL)
     {
-      void *libcx_handle;
-
       /* Try to use waitpid() of LIBCx first if available because it can
          process the return value of spawn-family of kLIBC as well as spawn2()
          of LIBCx.  */
-      libcx_handle = dlopen ("libcx0", RTLD_LAZY);
+      void *libcx_handle = dlopen ("libcx0", RTLD_LAZY);
       if (libcx_handle != NULL)
         waitpid_pfn = dlsym (libcx_handle, "_waitpid");
       /* If not available, falls back to waitpid() of kLIBC.  */
@@ -239,6 +237,9 @@ wait_subprocess (pid_t child, const char *progname,
                  bool slave_process, bool exit_on_error,
                  int *termsigp)
 {
+  if (termsigp != NULL)
+    *termsigp = 0;
+
 #if HAVE_WAITID && defined WNOWAIT && 0
   /* Commented out because waitid() without WEXITED and with WNOWAIT doesn't
      work: On Solaris 7, it returns -1 and sets errno = ECHILD, and on
@@ -249,10 +250,8 @@ wait_subprocess (pid_t child, const char *progname,
      meanwhile another process acquires the same PID as child, and then - still
      before unregister_slave_subprocess() - this process gets a fatal signal,
      it would kill the other totally unrelated process.  */
-  siginfo_t info;
 
-  if (termsigp != NULL)
-    *termsigp = 0;
+  siginfo_t info;
   for (;;)
     {
       if (waitid (P_PID, child, &info, WEXITED | (slave_process ? WNOWAIT : 0))
@@ -332,11 +331,8 @@ wait_subprocess (pid_t child, const char *progname,
     }
 #else
   /* waitpid() is just as portable as wait() nowadays.  */
-  int status;
 
-  if (termsigp != NULL)
-    *termsigp = 0;
-  status = 0;
+  int status = 0;
   for (;;)
     {
       int result = waitpid (child, &status, 0);
index 4cd384aae398e14eec1575a3cb702540a2beef7d..40dab281d9d3f3cf99ce48588b9a515038e3f09f 100644 (file)
@@ -91,13 +91,6 @@ static size_t
 critical_factorization (const UNIT *needle, size_t needle_len,
                         size_t *period)
 {
-  /* Index of last character of left half, or SIZE_MAX.  */
-  size_t max_suffix, max_suffix_rev;
-  size_t j; /* Index into NEEDLE for current candidate suffix.  */
-  size_t k; /* Offset into current period.  */
-  size_t p; /* Intermediate period.  */
-  UNIT a, b; /* Current comparison characters.  */
-
   /* Special case NEEDLE_LEN of 1 or 2 (all callers already filtered
      out 0-length needles.  */
   if (needle_len < 3)
@@ -116,73 +109,83 @@ critical_factorization (const UNIT *needle, size_t needle_len,
   */
 
   /* Perform lexicographic search.  */
-  max_suffix = SIZE_MAX;
-  j = 0;
-  k = p = 1;
-  while (j + k < needle_len)
-    {
-      a = CANON_ELEMENT (needle[j + k]);
-      b = CANON_ELEMENT (needle[max_suffix + k]);
-      if (a < b)
-        {
-          /* Suffix is smaller, period is entire prefix so far.  */
-          j += k;
-          k = 1;
-          p = j - max_suffix;
-        }
-      else if (a == b)
-        {
-          /* Advance through repetition of the current period.  */
-          if (k != p)
-            ++k;
-          else
-            {
-              j += p;
-              k = 1;
-            }
-        }
-      else /* b < a */
-        {
-          /* Suffix is larger, start over from current location.  */
-          max_suffix = j++;
-          k = p = 1;
-        }
-    }
-  *period = p;
+  size_t max_suffix = /* Index of last character of left half, or SIZE_MAX.  */
+    SIZE_MAX;
+  {
+    size_t j = 0; /* Index into NEEDLE for current candidate suffix.  */
+    size_t k = 1; /* Offset into current period.  */
+    size_t p = 1; /* Intermediate period.  */
+    while (j + k < needle_len)
+      {
+        UNIT a = CANON_ELEMENT (needle[j + k]);
+        UNIT b = CANON_ELEMENT (needle[max_suffix + k]);
+        if (a < b)
+          {
+            /* Suffix is smaller, period is entire prefix so far.  */
+            j += k;
+            k = 1;
+            p = j - max_suffix;
+          }
+        else if (a == b)
+          {
+            /* Advance through repetition of the current period.  */
+            if (k != p)
+              ++k;
+            else
+              {
+                j += p;
+                k = 1;
+              }
+          }
+        else /* b < a */
+          {
+            /* Suffix is larger, start over from current location.  */
+            max_suffix = j++;
+            k = p = 1;
+          }
+      }
+    *period = p;
+  }
 
   /* Perform reverse lexicographic search.  */
-  max_suffix_rev = SIZE_MAX;
-  j = 0;
-  k = p = 1;
-  while (j + k < needle_len)
-    {
-      a = CANON_ELEMENT (needle[j + k]);
-      b = CANON_ELEMENT (needle[max_suffix_rev + k]);
-      if (b < a)
-        {
-          /* Suffix is smaller, period is entire prefix so far.  */
-          j += k;
-          k = 1;
-          p = j - max_suffix_rev;
-        }
-      else if (a == b)
-        {
-          /* Advance through repetition of the current period.  */
-          if (k != p)
-            ++k;
-          else
-            {
-              j += p;
-              k = 1;
-            }
-        }
-      else /* a < b */
-        {
-          /* Suffix is larger, start over from current location.  */
-          max_suffix_rev = j++;
-          k = p = 1;
-        }
-    }
+  size_t max_suffix_rev = /* Index of last character of left half, or SIZE_MAX.  */
+    SIZE_MAX;
+  size_t p_rev;
+  {
+    size_t j = 0; /* Index into NEEDLE for current candidate suffix.  */
+    size_t k = 1; /* Offset into current period.  */
+    size_t p = 1; /* Intermediate period.  */
+    while (j + k < needle_len)
+      {
+        UNIT a = CANON_ELEMENT (needle[j + k]);
+        UNIT b = CANON_ELEMENT (needle[max_suffix_rev + k]);
+        if (b < a)
+          {
+            /* Suffix is smaller, period is entire prefix so far.  */
+            j += k;
+            k = 1;
+            p = j - max_suffix_rev;
+          }
+        else if (a == b)
+          {
+            /* Advance through repetition of the current period.  */
+            if (k != p)
+              ++k;
+            else
+              {
+                j += p;
+                k = 1;
+              }
+          }
+        else /* a < b */
+          {
+            /* Suffix is larger, start over from current location.  */
+            max_suffix_rev = j++;
+            k = p = 1;
+          }
+      }
+    p_rev = p;
+  }
 
   /* Choose the shorter suffix.  Return the index of the first character
      of the right half, rather than the last character of the left half.
@@ -200,7 +203,7 @@ critical_factorization (const UNIT *needle, size_t needle_len,
      factorization.  */
   if (max_suffix_rev + 1 < max_suffix + 1)
     return max_suffix + 1;
-  *period = p;
+  *period = p_rev;
   return max_suffix_rev + 1;
 }
 
@@ -218,15 +221,12 @@ static RETURN_TYPE _GL_ATTRIBUTE_PURE
 two_way_short_needle (const UNIT *haystack, size_t haystack_len,
                       const UNIT *needle, size_t needle_len)
 {
-  size_t i; /* Index into current character 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.  */
-
   /* Factor the needle into two halves, such that the left half is
      smaller than the global period, and the right half is
      periodic (with a period as large as NEEDLE_LEN - suffix).  */
-  suffix = critical_factorization (needle, needle_len, &period);
+  size_t period; /* The period of the right half of needle.  */
+  size_t suffix = /* The index of the right half of needle.  */
+    critical_factorization (needle, needle_len, &period);
 
   /* Perform the search.  Each iteration compares the right half
      first.  */
@@ -236,11 +236,12 @@ two_way_short_needle (const UNIT *haystack, size_t haystack_len,
          only advance by the period, so use memory to avoid rescanning
          known occurrences of the period in the right half.  */
       size_t memory = 0;
-      j = 0;
+      size_t j = 0; /* Index into current window of HAYSTACK.  */
       while (AVAILABLE (haystack, haystack_len, j, needle_len))
         {
           /* Scan for matches in right half.  */
-          i = MAX (suffix, memory);
+          size_t i = /* Index into current character of NEEDLE.  */
+            MAX (suffix, memory);
           while (i < needle_len && (CANON_ELEMENT (needle[i])
                                     == CANON_ELEMENT (haystack[i + j])))
             ++i;
@@ -270,11 +271,12 @@ two_way_short_needle (const UNIT *haystack, size_t haystack_len,
       /* The two halves of needle are distinct; no extra memory is
          required, and any mismatch results in a maximal shift.  */
       period = MAX (suffix, needle_len - suffix) + 1;
-      j = 0;
+      size_t j = 0; /* Index into current window of HAYSTACK.  */
       while (AVAILABLE (haystack, haystack_len, j, needle_len))
         {
           /* Scan for matches in right half.  */
-          i = suffix;
+          size_t i = /* Index into current character of NEEDLE.  */
+            suffix;
           while (i < needle_len && (CANON_ELEMENT (needle[i])
                                     == CANON_ELEMENT (haystack[i + j])))
             ++i;
index 60463b4bf0b2b4d55f0d1e1b5ebe3ed934588dfb..22001156b135416303a31b2604b23344623792ca 100644 (file)
 RETURN_TYPE
 FUNC (const UNIT *haystack_start, const UNIT *needle_start)
 {
-  const UNIT *haystack = haystack_start;
   const UNIT *needle = needle_start;
-  size_t needle_len; /* Length of NEEDLE.  */
-  size_t haystack_len; /* Known minimum length of HAYSTACK.  */
-  bool ok = true; /* True if NEEDLE is prefix of HAYSTACK.  */
 
   /* Determine length of NEEDLE, and in the process, make sure
      HAYSTACK is at least as long (no point processing all of a long
      NEEDLE if HAYSTACK is too short).  */
-  while (*haystack && *needle)
-    ok &= *haystack++ == *needle++;
-  if (*needle)
-    return NULL;
-  if (ok)
-    return (RETURN_TYPE) haystack_start;
+  {
+    const UNIT *haystack = haystack_start;
+    bool ok = true; /* True if NEEDLE is prefix of HAYSTACK.  */
+    while (*haystack && *needle)
+      ok &= *haystack++ == *needle++;
+    if (*needle)
+      return NULL;
+    if (ok)
+      return (RETURN_TYPE) haystack_start;
+  }
 
   /* Reduce the size of haystack using STRCHR, since it has a smaller
      linear coefficient than the Two-Way algorithm.  */
-  needle_len = needle - needle_start;
-  haystack = STRCHR (haystack_start + 1, *needle_start);
+  size_t needle_len = /* Length of NEEDLE.  */
+    needle - needle_start;
+  const UNIT *haystack = STRCHR (haystack_start + 1, *needle_start);
   if (!haystack || __builtin_expect (needle_len == 1, 0))
     return (RETURN_TYPE) haystack;
   needle -= needle_len;
-  haystack_len = (haystack > haystack_start + needle_len ? 1
-                  : needle_len + haystack_start - haystack);
+  size_t haystack_len = /* Known minimum length of HAYSTACK.  */
+    (haystack > haystack_start + needle_len ? 1
+     : needle_len + haystack_start - haystack);
 
   /* Perform the search.  */
   return two_way_short_needle (haystack, haystack_len,
index 3f14df53b42c9d5dbc4fa4c83d2a3944546242e7..b4a74e97229b1cd979a46af1816ba79e607049ad 100644 (file)
 int
 FUNC (const UNIT *s, size_t n)
 {
-  int count = 0;
-  for (; n > 0; s++, n--)
-    {
-      UNIT c = *s;
-      if (c == (UNIT)'\0')
-        break;
+  {
+    int count = 0;
+    for (; n > 0; s++, n--)
       {
-        int width = CHARACTER_WIDTH (c);
-        if (width < 0)
-          goto found_nonprinting;
-        if (width > INT_MAX - count)
-          goto overflow;
-        count += width;
+        UNIT c = *s;
+        if (c == (UNIT)'\0')
+          break;
+        {
+          int width = CHARACTER_WIDTH (c);
+          if (width < 0)
+            goto found_nonprinting;
+          if (width > INT_MAX - count)
+            goto overflow;
+          count += width;
+        }
       }
-    }
-  return count;
+    return count;
+  }
 
   /* The total width has become > INT_MAX.
      Continue searching for a non-printing wide character.  */
index e4eb9472ee4b116801d308b53147b6d457916a7b..196a2ab0e20a539140cba83c2dd79697b9683abd 100644 (file)
 size_t
 wcsxfrm (wchar_t *s1, const wchar_t *s2, size_t n)
 {
-  char mbbuf2[1024];
-  char *mbs2;
-
   {
     int saved_errno = errno;
-    size_t result;
+    char mbbuf2[1024];
+    char *mbs2;
 
     /* Convert s2 to a multibyte string, trying to avoid malloc().  */
     {
-      size_t ret;
-
-      ret = wcstombs (mbbuf2, s2, sizeof (mbbuf2));
+      size_t ret = wcstombs (mbbuf2, s2, sizeof (mbbuf2));
       if (ret == (size_t)-1)
         goto failed;
       if (ret < sizeof (mbbuf2))
@@ -50,7 +46,7 @@ wcsxfrm (wchar_t *s1, const wchar_t *s2, size_t n)
 
     /* Transform the multibyte string.  */
     errno = 0;
-    result = strxfrm ((char *)s1, mbs2, n);
+    size_t result = strxfrm ((char *)s1, mbs2, n);
     if (errno != 0)
       {
         /* An error occurred.  */
index e24e97775aa1453ccbf49e7eb2aa7786bfa6ec85..49f5cc849ef8dc2e55296fd2b03481120317f236 100644 (file)
@@ -23,10 +23,9 @@ wctomb (char *s, wchar_t wc)
   else
     {
       mbstate_t state;
-      size_t result;
-
       mbszero (&state);
-      result = wcrtomb (s, wc, &state);
+
+      size_t result = wcrtomb (s, wc, &state);
       if (result == (size_t)-1)
         return -1;
       return result;
index 757ca03f7f9d11e95acc933e7a81ac89e800e3aa..ca3c5bb31239680037c6cabff05ba6956fcd25d9 100644 (file)
@@ -27,8 +27,6 @@
 wchar_t *
 wgetcwd (wchar_t *buf, size_t size)
 {
-  wchar_t *result;
-
   /* Uses _wgetcwd.
      Documentation:
      <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/getcwd-wgetcwd>
@@ -60,7 +58,7 @@ wgetcwd (wchar_t *buf, size_t size)
           errno = ENOMEM;
           return NULL;
         }
-      result = _wgetcwd (buf, size + 2);
+      wchar_t *result = _wgetcwd (buf, size + 2);
       if (!result)
         {
           free (buf);
@@ -88,7 +86,7 @@ wgetcwd (wchar_t *buf, size_t size)
     wchar_t *ptr = _wgetcwd (tmp, size);
     if (ptr)
       {
-        result = _wcsdup (ptr);
+        wchar_t *result = _wcsdup (ptr);
         if (!result)
           errno = ENOMEM;
         return result;
@@ -98,6 +96,7 @@ wgetcwd (wchar_t *buf, size_t size)
   }
 
   /* My what a large directory name we have.  */
+  wchar_t *result;
   do
     {
       size <<= 1;
index 327ba406cd643dd4880bcb9208d7a3060abdff02..47dfedcd37ce358f288ff873844cd962fc4f3648 100644 (file)
@@ -54,13 +54,10 @@ glwthread_waitqueue_init (glwthread_waitqueue_t *wq)
 static struct glwthread_waitqueue_element *
 glwthread_waitqueue_add (glwthread_waitqueue_t *wq)
 {
-  struct glwthread_waitqueue_element *elt;
-  HANDLE event;
-
   /* Allocate the memory for the waitqueue element on the heap, not on the
      thread's stack.  If the thread exits unexpectedly, we prefer to leak
      some memory rather than to access unavailable memory and crash.  */
-  elt =
+  struct glwthread_waitqueue_element *elt =
     (struct glwthread_waitqueue_element *)
     malloc (sizeof (struct glwthread_waitqueue_element));
   if (elt == NULL)
@@ -69,7 +66,7 @@ glwthread_waitqueue_add (glwthread_waitqueue_t *wq)
 
   /* Whether the created event is a manual-reset one or an auto-reset one,
      does not matter, since we will wait on it only once.  */
-  event = CreateEvent (NULL, TRUE, FALSE, NULL);
+  HANDLE event = CreateEvent (NULL, TRUE, FALSE, NULL);
   if (event == INVALID_HANDLE_VALUE)
     {
       /* No way to allocate an event.  */
@@ -113,12 +110,10 @@ glwthread_waitqueue_notify_first (glwthread_waitqueue_t *wq)
     {
       struct glwthread_waitqueue_element *elt =
         (struct glwthread_waitqueue_element *) wq->wq_list.wql_next;
-      struct glwthread_waitqueue_link *prev;
-      struct glwthread_waitqueue_link *next;
 
       /* Remove elt from the circular list.  */
-      prev = &wq->wq_list; /* = elt->link.wql_prev; */
-      next = elt->link.wql_next;
+      struct glwthread_waitqueue_link *prev = &wq->wq_list; /* = elt->link.wql_prev; */
+      struct glwthread_waitqueue_link *next = elt->link.wql_next;
       prev->wql_next = next;
       next->wql_prev = prev;
       elt->link.wql_next = NULL;
@@ -138,12 +133,10 @@ glwthread_waitqueue_notify_all (glwthread_waitqueue_t *wq)
     {
       struct glwthread_waitqueue_element *elt =
         (struct glwthread_waitqueue_element *) l;
-      struct glwthread_waitqueue_link *prev;
-      struct glwthread_waitqueue_link *next;
 
       /* Remove elt from the circular list.  */
-      prev = &wq->wq_list; /* = elt->link.wql_prev; */
-      next = elt->link.wql_next;
+      struct glwthread_waitqueue_link *prev = &wq->wq_list; /* = elt->link.wql_prev; */
+      struct glwthread_waitqueue_link *next = elt->link.wql_next;
       prev->wql_next = next;
       next->wql_prev = prev;
       elt->link.wql_next = NULL;
@@ -204,11 +197,9 @@ glwthread_cond_wait (glwthread_cond_t *cond,
     else
       {
         HANDLE event = elt->event;
-        int err;
-        DWORD result;
 
         /* Now release the mutex and let any other thread take it.  */
-        err = mutex_unlock (mutex);
+        int err = mutex_unlock (mutex);
         if (err != 0)
           {
             EnterCriticalSection (&cond->lock);
@@ -227,7 +218,7 @@ glwthread_cond_wait (glwthread_cond_t *cond,
            This is fulfilled here, because the thread signalling is done
            through SetEvent, not PulseEvent.  */
         /* Wait until another thread signals this event.  */
-        result = WaitForSingleObject (event, INFINITE);
+        DWORD result = WaitForSingleObject (event, INFINITE);
         if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
           abort ();
         CloseHandle (event);
@@ -263,7 +254,6 @@ glwthread_cond_timedwait (glwthread_cond_t *cond,
 
   {
     struct timeval currtime;
-
     gettimeofday (&currtime, NULL);
     if (currtime.tv_sec > abstime->tv_sec
         || (currtime.tv_sec == abstime->tv_sec
@@ -283,21 +273,20 @@ glwthread_cond_timedwait (glwthread_cond_t *cond,
       else
         {
           HANDLE event = elt->event;
-          int err;
-          DWORD timeout;
-          DWORD result;
 
           /* Now release the mutex and let any other thread take it.  */
-          err = mutex_unlock (mutex);
-          if (err != 0)
-            {
-              EnterCriticalSection (&cond->lock);
-              glwthread_waitqueue_remove (&cond->waiters, elt);
-              LeaveCriticalSection (&cond->lock);
-              CloseHandle (event);
-              free (elt);
-              return err;
-            }
+          {
+            int err = mutex_unlock (mutex);
+            if (err != 0)
+              {
+                EnterCriticalSection (&cond->lock);
+                glwthread_waitqueue_remove (&cond->waiters, elt);
+                LeaveCriticalSection (&cond->lock);
+                CloseHandle (event);
+                free (elt);
+                return err;
+              }
+          }
           /* POSIX says:
               "If another thread is able to acquire the mutex after the
                about-to-block thread has released it, then a subsequent call to
@@ -309,6 +298,7 @@ glwthread_cond_timedwait (glwthread_cond_t *cond,
           /* Wait until another thread signals this event or until the abstime
              passes.  */
           gettimeofday (&currtime, NULL);
+          DWORD timeout;
           if (currtime.tv_sec > abstime->tv_sec)
             timeout = 0;
           else
@@ -336,7 +326,7 @@ glwthread_cond_timedwait (glwthread_cond_t *cond,
                     }
                 }
             }
-          result = WaitForSingleObject (event, timeout);
+          DWORD result = WaitForSingleObject (event, timeout);
           if (result == WAIT_FAILED)
             abort ();
           if (result == WAIT_TIMEOUT)
@@ -369,7 +359,7 @@ glwthread_cond_timedwait (glwthread_cond_t *cond,
           free (elt);
           /* Take the mutex again.  It does not matter whether this is done
              before or after the bookkeeping for WAIT_TIMEOUT.  */
-          err = mutex_lock (mutex);
+          int err = mutex_lock (mutex);
           return (err ? err :
                   result == WAIT_OBJECT_0 ? 0 :
                   result == WAIT_TIMEOUT ? ETIMEDOUT :
index 6ac145819642d47211e3b7c28830adc00c96a03d..83cc385ea13d6d25c9240dbc57ab80f77cf2db9f 100644 (file)
@@ -52,27 +52,22 @@ static char *
 execute_and_read_line (const char *progname,
                        const char *prog_path, const char * const *prog_argv)
 {
-  pid_t child;
-  int fd[1];
-  FILE *fp;
-  char *line;
-  size_t linesize;
-  size_t linelen;
-
   /* Open a pipe to the program.  */
-  child = create_pipe_in (progname, prog_path, prog_argv, NULL, NULL,
-                          DEV_NULL, false, true, false, fd);
+  int fd[1];
+  pid_t child = create_pipe_in (progname, prog_path, prog_argv, NULL, NULL,
+                                DEV_NULL, false, true, false, fd);
 
   if (child == -1)
     return NULL;
 
   /* Retrieve its result.  */
-  fp = fdopen (fd[0], "r");
+  FILE *fp = fdopen (fd[0], "r");
   if (fp == NULL)
     error (EXIT_FAILURE, errno, _("fdopen() failed"));
 
-  line = NULL; linesize = 0;
-  linelen = getline (&line, &linesize, fp);
+  char *line = NULL;
+  size_t linesize = 0;
+  size_t linelen = getline (&line, &linesize, fp);
   if (linelen == (size_t)(-1))
     {
       error (0, 0, _("%s subprocess I/O error"), progname);
@@ -81,8 +76,6 @@ execute_and_read_line (const char *progname,
     }
   else
     {
-      int exitstatus;
-
       if (linelen > 0 && line[linelen - 1] == '\n')
         line[linelen - 1] = '\0';
 
@@ -93,7 +86,7 @@ execute_and_read_line (const char *progname,
       fclose (fp);
 
       /* Remove zombie process from process list, and retrieve exit status.  */
-      exitstatus =
+      int exitstatus =
         wait_subprocess (child, progname, true, false, true, false, NULL);
       if (exitstatus == 0)
         return line;
@@ -109,7 +102,6 @@ windows_cygpath_w (const char *filename)
     {
       /* It's an absolute POSIX-style file name.  */
       const char *argv[4];
-
       argv[0] = "cygpath";
       argv[1] = "-w";
       argv[2] = filename;
index 0ac90657aa4a235bba8bcacb7e299c207071c2de..5eac81216623f8cc6a36edee0b431d34bd0781d4 100644 (file)
@@ -46,9 +46,6 @@ glwthread_waitqueue_init (glwthread_waitqueue_t *wq)
 static HANDLE
 glwthread_waitqueue_add (glwthread_waitqueue_t *wq)
 {
-  HANDLE event;
-  unsigned int index;
-
   if (wq->count == wq->alloc)
     {
       unsigned int new_alloc = 2 * wq->alloc + 1;
@@ -79,11 +76,11 @@ glwthread_waitqueue_add (glwthread_waitqueue_t *wq)
     }
   /* Whether the created event is a manual-reset one or an auto-reset one,
      does not matter, since we will wait on it only once.  */
-  event = CreateEvent (NULL, TRUE, FALSE, NULL);
+  HANDLE event = CreateEvent (NULL, TRUE, FALSE, NULL);
   if (event == INVALID_HANDLE_VALUE)
     /* No way to allocate an event.  */
     return INVALID_HANDLE_VALUE;
-  index = wq->offset + wq->count;
+  unsigned int index = wq->offset + wq->count;
   if (index >= wq->alloc)
     index -= wq->alloc;
   wq->array[index] = event;
@@ -157,10 +154,9 @@ glwthread_rwlock_rdlock (glwthread_rwlock_t *lock)
       HANDLE event = glwthread_waitqueue_add (&lock->waiting_readers);
       if (event != INVALID_HANDLE_VALUE)
         {
-          DWORD result;
           LeaveCriticalSection (&lock->lock);
           /* Wait until another thread signals this event.  */
-          result = WaitForSingleObject (event, INFINITE);
+          DWORD result = WaitForSingleObject (event, INFINITE);
           if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
             abort ();
           CloseHandle (event);
@@ -214,10 +210,9 @@ glwthread_rwlock_wrlock (glwthread_rwlock_t *lock)
       HANDLE event = glwthread_waitqueue_add (&lock->waiting_writers);
       if (event != INVALID_HANDLE_VALUE)
         {
-          DWORD result;
           LeaveCriticalSection (&lock->lock);
           /* Wait until another thread signals this event.  */
-          result = WaitForSingleObject (event, INFINITE);
+          DWORD result = WaitForSingleObject (event, INFINITE);
           if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
             abort ();
           CloseHandle (event);
index 0d752d636091a066a8f70498470b567af007deef..25bc86c955c59e981e877faa79f91c8c9e4305e1 100644 (file)
@@ -54,11 +54,9 @@ static size_t
 quoted_arg_length (const char *string)
 {
   bool quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
-  size_t length;
-  unsigned int backslashes;
 
-  length = 0;
-  backslashes = 0;
+  size_t length = 0;
+  unsigned int backslashes = 0;
   if (quote_around)
     length++;
   for (const char *s = string; *s != '\0'; s++)
@@ -86,11 +84,9 @@ static char *
 quoted_arg_string (const char *string, char *mem)
 {
   bool quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
-  char *p;
-  unsigned int backslashes;
 
-  p = mem;
-  backslashes = 0;
+  char *p = mem;
+  unsigned int backslashes = 0;
   if (quote_around)
     *p++ = '"';
   for (const char *s = string; *s != '\0'; s++)
@@ -119,15 +115,14 @@ quoted_arg_string (const char *string, char *mem)
 const char **
 prepare_spawn (const char * const *argv, char **mem_to_free)
 {
-  size_t argc;
-  const char **new_argv;
-
   /* Count number of arguments.  */
+  size_t argc;
   for (argc = 0; argv[argc] != NULL; argc++)
     ;
 
   /* Allocate new argument vector.  */
-  new_argv = (const char **) malloc ((1 + argc + 1) * sizeof (const char *));
+  const char **new_argv =
+    (const char **) malloc ((1 + argc + 1) * sizeof (const char *));
 
   /* Add an element upfront that can be used when argv[0] turns out to be a
      script, not a program.
@@ -142,14 +137,15 @@ prepare_spawn (const char * const *argv, char **mem_to_free)
   for (size_t i = 0; i < argc; i++)
     {
       const char *string = argv[i];
-      size_t length;
 
+      size_t length;
       if (string[0] == '\0')
         length = strlen ("\"\"");
       else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
         length = quoted_arg_length (string);
       else
         length = strlen (string);
+
       needed_size += length + 1;
     }
 
@@ -200,17 +196,18 @@ char *
 compose_command (const char * const *argv)
 {
   /* Just concatenate the argv[] strings, separated by spaces.  */
-  char *command;
 
   /* Determine the size of the needed block of memory.  */
   size_t total_size = 0;
-  const char *p;
-  for (const char * const *ap = argv; (p = *ap) != NULL; ap++)
-    total_size += strlen (p) + 1;
+  {
+    const char *p;
+    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);
 
   /* Allocate the block of memory.  */
-  command = (char *) malloc (command_size);
+  char *command = (char *) malloc (command_size);
   if (command == NULL)
     {
       errno = ENOMEM;
@@ -221,6 +218,7 @@ compose_command (const char * const *argv)
   if (total_size > 0)
     {
       char *cp = command;
+      const char *p;
       for (const char * const *ap = argv; (p = *ap) != NULL; ap++)
         {
           size_t size = strlen (p) + 1;
@@ -248,12 +246,14 @@ 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 *p;
     if (new_PATH != NULL)
       total_size += strlen (new_PATH) + 1;
-    for (const char * const *ep = envp; (p = *ep) != NULL; ep++)
-      if (!(new_PATH != NULL && strncmp (p, "PATH=", 5) == 0))
-        total_size += strlen (p) + 1;
+    {
+      const char *p;
+      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;
 
     /* Allocate the block of memory.  */
@@ -270,36 +270,39 @@ compose_envblock (const char * const *envp, const char *new_PATH)
         memcpy (envblock + envblock_used, new_PATH, size);
         envblock_used += size;
       }
-    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;
-          if (envblock_used + size > envblock_size)
-            {
-              /* Other threads did modifications.  Need more memory.  */
-              envblock_size += envblock_size / 2;
-              if (envblock_used + size > envblock_size)
-                envblock_size = envblock_used + size;
-
-              char *new_envblock =
-                (char *) realloc (envblock, envblock_size + 1);
-              if (new_envblock == NULL)
-                {
-                  free (envblock);
-                  errno = ENOMEM;
-                  return NULL;
-                }
+    {
+      const char *p;
+      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;
+            if (envblock_used + size > envblock_size)
+              {
+                /* Other threads did modifications.  Need more memory.  */
+                envblock_size += envblock_size / 2;
+                if (envblock_used + size > envblock_size)
+                  envblock_size = envblock_used + size;
+
+                char *new_envblock =
+                  (char *) realloc (envblock, envblock_size + 1);
+                if (new_envblock == NULL)
+                  {
+                    free (envblock);
+                    errno = ENOMEM;
+                    return NULL;
+                  }
               envblock = new_envblock;
             }
-          memcpy (envblock + envblock_used, p, size);
-          envblock_used += size;
-          if (envblock[envblock_used - 1] != '\0')
-            {
-              /* Other threads did modifications.  Restart.  */
-              free (envblock);
-              goto retry;
-            }
-        }
+            memcpy (envblock + envblock_used, p, size);
+            envblock_used += size;
+            if (envblock[envblock_used - 1] != '\0')
+              {
+                /* Other threads did modifications.  Restart.  */
+                free (envblock);
+                goto retry;
+              }
+          }
+    }
     envblock[envblock_used] = '\0';
     return envblock;
   }
index 9f6fd8b606aaba66cc6a1c51ccad54a22a304f2d..d7a93501d77f1a5265c7f62a3645389149d8549e 100644 (file)
@@ -84,11 +84,9 @@ get_current_thread_handle (void)
 glwthread_thread_t
 glwthread_thread_self (void)
 {
-  glwthread_thread_t thread;
-
   if (self_key == (DWORD)-1)
     init_self_key ();
-  thread = TlsGetValue (self_key);
+  glwthread_thread_t thread = TlsGetValue (self_key);
   if (thread == NULL)
     {
       /* This happens only in threads that have not been created through
@@ -169,9 +167,7 @@ glwthread_thread_create (glwthread_thread_t *threadp, unsigned int attr,
 
   {
     unsigned int thread_id;
-    HANDLE thread_handle;
-
-    thread_handle = (HANDLE)
+    HANDLE thread_handle = (HANDLE)
       _beginthreadex (NULL, 100000, wrapper_func, thread, 0, &thread_id);
       /* calls CreateThread with the same arguments */
     if (thread_handle == NULL)
index 6ee6edbf325ae8139e3db5f0c29b462a4291d659..db4ada809f7f50bc503d3255f8f21dc3e8dbc371 100644 (file)
@@ -171,13 +171,11 @@ glwthread_timedmutex_timedlock (glwthread_timedmutex_t *mutex,
 
       {
         struct timeval currtime;
-        DWORD timeout;
-        DWORD result;
-
         gettimeofday (&currtime, NULL);
 
         /* Wait until another thread signals the event or until the
            abstime passes.  */
+        DWORD timeout;
         if (currtime.tv_sec > abstime->tv_sec)
           timeout = 0;
         else
@@ -210,7 +208,7 @@ glwthread_timedmutex_timedlock (glwthread_timedmutex_t *mutex,
 
         /* WaitForSingleObject
            <https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject> */
-        result = WaitForSingleObject (mutex->event, timeout);
+        DWORD result = WaitForSingleObject (mutex->event, timeout);
         if (result == WAIT_FAILED)
           abort ();
         if (result == WAIT_TIMEOUT)
index 5bc6ecfda9d5591aa1d1021c9d227911bb557d20..051dac7a912a40e2aa04dddcbd6b2c560bdb042c 100644 (file)
@@ -179,13 +179,11 @@ glwthread_timedrecmutex_timedlock (glwthread_timedrecmutex_t *mutex,
 
             {
               struct timeval currtime;
-              DWORD timeout;
-              DWORD result;
-
               gettimeofday (&currtime, NULL);
 
               /* Wait until another thread signals the event or until the
                  abstime passes.  */
+              DWORD timeout;
               if (currtime.tv_sec > abstime->tv_sec)
                 timeout = 0;
               else
@@ -218,7 +216,7 @@ glwthread_timedrecmutex_timedlock (glwthread_timedrecmutex_t *mutex,
 
               /* WaitForSingleObject
                  <https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject> */
-              result = WaitForSingleObject (mutex->event, timeout);
+              DWORD result = WaitForSingleObject (mutex->event, timeout);
               if (result == WAIT_FAILED)
                 abort ();
               if (result == WAIT_TIMEOUT)
index 418eb9f37b99aebcddf05510c6de1c1c4f298b09..de4346041c07d2cdebfa2ba1ea5267eebce8b9b2 100644 (file)
@@ -54,13 +54,10 @@ glwthread_waitqueue_init (glwthread_waitqueue_t *wq)
 static struct glwthread_waitqueue_element *
 glwthread_waitqueue_add (glwthread_waitqueue_t *wq)
 {
-  struct glwthread_waitqueue_element *elt;
-  HANDLE event;
-
   /* Allocate the memory for the waitqueue element on the heap, not on the
      thread's stack.  If the thread exits unexpectedly, we prefer to leak
      some memory rather than to access unavailable memory and crash.  */
-  elt =
+  struct glwthread_waitqueue_element *elt =
     (struct glwthread_waitqueue_element *)
     malloc (sizeof (struct glwthread_waitqueue_element));
   if (elt == NULL)
@@ -69,7 +66,7 @@ glwthread_waitqueue_add (glwthread_waitqueue_t *wq)
 
   /* Whether the created event is a manual-reset one or an auto-reset one,
      does not matter, since we will wait on it only once.  */
-  event = CreateEvent (NULL, TRUE, FALSE, NULL);
+  HANDLE event = CreateEvent (NULL, TRUE, FALSE, NULL);
   if (event == INVALID_HANDLE_VALUE)
     {
       /* No way to allocate an event.  */
@@ -115,12 +112,10 @@ glwthread_waitqueue_notify_first (glwthread_waitqueue_t *wq)
     {
       struct glwthread_waitqueue_element *elt =
         (struct glwthread_waitqueue_element *) wq->wq_list.wql_next;
-      struct glwthread_waitqueue_link *prev;
-      struct glwthread_waitqueue_link *next;
 
       /* Remove elt from the circular list.  */
-      prev = &wq->wq_list; /* = elt->link.wql_prev; */
-      next = elt->link.wql_next;
+      struct glwthread_waitqueue_link *prev = &wq->wq_list; /* = elt->link.wql_prev; */
+      struct glwthread_waitqueue_link *next = elt->link.wql_next;
       prev->wql_next = next;
       next->wql_prev = prev;
       elt->link.wql_next = NULL;
@@ -141,12 +136,10 @@ glwthread_waitqueue_notify_all (glwthread_waitqueue_t *wq)
     {
       struct glwthread_waitqueue_element *elt =
         (struct glwthread_waitqueue_element *) l;
-      struct glwthread_waitqueue_link *prev;
-      struct glwthread_waitqueue_link *next;
 
       /* Remove elt from the circular list.  */
-      prev = &wq->wq_list; /* = elt->link.wql_prev; */
-      next = elt->link.wql_next;
+      struct glwthread_waitqueue_link *prev = &wq->wq_list; /* = elt->link.wql_prev; */
+      struct glwthread_waitqueue_link *next = elt->link.wql_next;
       prev->wql_next = next;
       next->wql_prev = prev;
       elt->link.wql_next = NULL;
@@ -207,10 +200,9 @@ glwthread_timedrwlock_rdlock (glwthread_timedrwlock_t *lock)
       if (elt != NULL)
         {
           HANDLE event = elt->event;
-          DWORD result;
           LeaveCriticalSection (&lock->lock);
           /* Wait until another thread signals this event.  */
-          result = WaitForSingleObject (event, INFINITE);
+          DWORD result = WaitForSingleObject (event, INFINITE);
           if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
             abort ();
           CloseHandle (event);
@@ -267,10 +259,9 @@ glwthread_timedrwlock_wrlock (glwthread_timedrwlock_t *lock)
       if (elt != NULL)
         {
           HANDLE event = elt->event;
-          DWORD result;
           LeaveCriticalSection (&lock->lock);
           /* Wait until another thread signals this event.  */
-          result = WaitForSingleObject (event, INFINITE);
+          DWORD result = WaitForSingleObject (event, INFINITE);
           if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
             abort ();
           CloseHandle (event);
@@ -400,17 +391,15 @@ glwthread_timedrwlock_timedrdlock (glwthread_timedrwlock_t *lock,
       if (elt != NULL)
         {
           HANDLE event = elt->event;
-          struct timeval currtime;
-          DWORD timeout;
-          DWORD result;
-          int retval;
 
           LeaveCriticalSection (&lock->lock);
 
+          struct timeval currtime;
           gettimeofday (&currtime, NULL);
 
           /* Wait until another thread signals this event or until the
              abstime passes.  */
+          DWORD timeout;
           if (currtime.tv_sec > abstime->tv_sec)
             timeout = 0;
           else
@@ -442,7 +431,7 @@ glwthread_timedrwlock_timedrdlock (glwthread_timedrwlock_t *lock,
             {
               /* WaitForSingleObject
                  <https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject> */
-              result = WaitForSingleObject (event, timeout);
+              DWORD result = WaitForSingleObject (event, timeout);
               if (result == WAIT_FAILED)
                 abort ();
               if (result != WAIT_TIMEOUT)
@@ -459,6 +448,7 @@ glwthread_timedrwlock_timedrdlock (glwthread_timedrwlock_t *lock,
             }
           EnterCriticalSection (&lock->lock);
           /* Remove ourselves from the waiting_readers.  */
+          int retval;
           if (glwthread_waitqueue_remove (&lock->waiting_readers, elt))
             retval = ETIMEDOUT;
           else
@@ -520,17 +510,15 @@ glwthread_timedrwlock_timedwrlock (glwthread_timedrwlock_t *lock,
       if (elt != NULL)
         {
           HANDLE event = elt->event;
-          struct timeval currtime;
-          DWORD timeout;
-          DWORD result;
-          int retval;
 
           LeaveCriticalSection (&lock->lock);
 
+          struct timeval currtime;
           gettimeofday (&currtime, NULL);
 
           /* Wait until another thread signals this event or until the
              abstime passes.  */
+          DWORD timeout;
           if (currtime.tv_sec > abstime->tv_sec)
             timeout = 0;
           else
@@ -562,7 +550,7 @@ glwthread_timedrwlock_timedwrlock (glwthread_timedrwlock_t *lock,
             {
               /* WaitForSingleObject
                  <https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject> */
-              result = WaitForSingleObject (event, timeout);
+              DWORD result = WaitForSingleObject (event, timeout);
               if (result == WAIT_FAILED)
                 abort ();
               if (result != WAIT_TIMEOUT)
@@ -579,6 +567,7 @@ glwthread_timedrwlock_timedwrlock (glwthread_timedrwlock_t *lock,
             }
           EnterCriticalSection (&lock->lock);
           /* Remove ourselves from the waiting_writers.  */
+          int retval;
           if (glwthread_waitqueue_remove (&lock->waiting_writers, elt))
             retval = ETIMEDOUT;
           else
index 9d7dc1316b942602030c6a9d2e88c52f5e1e4063..cf0f52991ff87a665e7b5dada96f21ededa6f0a3 100644 (file)
@@ -24,10 +24,8 @@ char *
 xasprintf (const char *format, ...)
 {
   va_list args;
-  char *result;
-
   va_start (args, format);
-  result = xvasprintf (format, args);
+  char *result = xvasprintf (format, args);
   va_end (args);
 
   return result;
index 230c747bab2da20f2504446d37afd9e6639c2a2c..a7ed7d85b4306ac185a701a29c7d4d97f414e2e0 100644 (file)
@@ -31,9 +31,7 @@ char *
 xconcatenated_filename (const char *directory, const char *filename,
                         const char *suffix)
 {
-  char *result;
-
-  result = concatenated_filename (directory, filename, suffix);
+  char *result = concatenated_filename (directory, filename, suffix);
   if (result == NULL)
     xalloc_die ();
 
index 8a7158077cf4349940b8aa15dfc85afada54cc7e..3d84797796d4c71ae3cb3feaf1bbc4ed114a20c2 100644 (file)
@@ -224,13 +224,13 @@ x2nrealloc (void *p, size_t *pn, size_t s)
 void *
 xpalloc (void *pa, idx_t *pn, idx_t n_incr_min, ptrdiff_t n_max, idx_t s)
 {
-  idx_t n0 = *pn;
-
   /* The approximate size to use for initial small allocation
      requests.  This is the largest "small" request for the GNU C
      library malloc.  */
   enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };
 
+  idx_t n0 = *pn;
+
   /* If the array is tiny, grow it to about (but no greater than)
      DEFAULT_MXFAST bytes.  Otherwise, grow it by about 50%.
      Adjust the growth according to three constraints: N_INCR_MIN,
index 8a9f681d28a0ece45d4641c4a318405306ea9c60..cf04cd86458f72ecf9372abc361a9fd440266a85 100644 (file)
@@ -27,9 +27,7 @@
 void *
 xmmalloca (size_t n)
 {
-  void *p;
-
-  p = mmalloca (n);
+  void *p = mmalloca (n);
   if (p == NULL)
     xalloc_die ();
   return p;
index 1863876eb07785abedfc83634c2a9e28439a4425..1c69dda3126a8762f1e213117fd50a26c13b23c2 100644 (file)
@@ -32,9 +32,8 @@ off64_t
 xprintf (char const *restrict format, ...)
 {
   va_list args;
-  off64_t retval;
   va_start (args, format);
-  retval = xvprintf (format, args);
+  off64_t retval = xvprintf (format, args);
   va_end (args);
 
   return retval;
@@ -54,9 +53,8 @@ off64_t
 xfprintf (FILE *restrict stream, char const *restrict format, ...)
 {
   va_list args;
-  off64_t retval;
   va_start (args, format);
-  retval = xvfprintf (stream, format, args);
+  off64_t retval = xvfprintf (stream, format, args);
   va_end (args);
 
   return retval;
index 252e318a56efc65970c77fdc11e2e90ab93de1f0..2f925b1dc07bd8fa3da110473a1cbe9c3db2f3e9 100644 (file)
@@ -42,10 +42,8 @@ int
 sb_xappendf (struct string_buffer *buffer, const char *formatstring, ...)
 {
   va_list args;
-  int ret;
-
   va_start (args, formatstring);
-  ret = sb_xappendvf (buffer, formatstring, args);
+  int ret = sb_xappendvf (buffer, formatstring, args);
   va_end (args);
   return ret;
 }
index 062ac929b19f279e000ee83613596f56ed02858d..2b3c56a6a9a9f7228d8daf1f116d605de98783e4 100644 (file)
@@ -43,10 +43,8 @@ sbr_xprependf (struct string_buffer_reversed *buffer,
                const char *formatstring, ...)
 {
   va_list args;
-  int ret;
-
   va_start (args, formatstring);
-  ret = sbr_xprependvf (buffer, formatstring, args);
+  int ret = sbr_xprependvf (buffer, formatstring, args);
   va_end (args);
   return ret;
 }
index ed85b790be5655ea029cde6e45a027936c9adb43..eb6773e8bb9cf4c0f188525189b41550875da07b 100644 (file)
@@ -44,14 +44,12 @@ bool
 XSTRTOD (char const *str, char const **ptr, DOUBLE *result,
          DOUBLE (*convert) (char const *, char **))
 {
-  DOUBLE val;
-  char *terminator;
-  bool ok = true;
-
   errno = 0;
-  val = convert (str, &terminator);
+  char *terminator;
+  DOUBLE val = convert (str, &terminator);
 
   /* Having a non-zero terminator is an error only when PTR is NULL. */
+  bool ok = true;
   if (terminator == str || (ptr == NULL && *terminator != '\0'))
     ok = false;
   else
index b11e0c4873acedddce31ef7c63408717fbde64d1..72d4de7993047a757ada7980fedc0987780effa8 100644 (file)
@@ -50,11 +50,7 @@ xstrtol_error (enum strtol_error err,
                char const *arg,
                int exit_status)
 {
-  char const *hyphens = "--";
   char const *msgid;
-  char const *option;
-  char option_buffer[2];
-
   switch (err)
     {
     case LONGINT_OK: default:
@@ -74,6 +70,9 @@ xstrtol_error (enum strtol_error err,
       break;
     }
 
+  char const *hyphens = "--";
+  char option_buffer[2];
+  char const *option;
   if (opt_idx < 0)
     {
       hyphens -= opt_idx;
index 8d4b6a4935afc6c4735bff4560431d3c2e011c04..6f903e706591b52c3c89bbea59351c9c7cf2105e 100644 (file)
@@ -117,16 +117,14 @@ __xstrtol (char const *nptr, char **endptr, int base,
 
   if (**p != '\0')
     {
-      int xbase = 1024;
-      int suffixes = 1;
-      strtol_error overflow;
-
       if (!strchr (valid_suffixes, **p))
         {
           *val = tmp;
           return err | LONGINT_INVALID_SUFFIX_CHAR;
         }
 
+      int xbase = 1024;
+      int suffixes = 1;
       switch (**p)
         {
         case 'E': case 'G': case 'g': case 'k': case 'K': case 'M': case 'm':
@@ -155,6 +153,7 @@ __xstrtol (char const *nptr, char **endptr, int base,
               }
         }
 
+      strtol_error overflow;
       switch (**p)
         {
         case 'b':
index a71d5aac537193f9c49e6de96624fc223945f135..e52e816bb65169a3a7e6abbdcc54d289b0d57ff9 100644 (file)
 static char *
 xstrcat (size_t argcount, va_list args)
 {
-  char *result;
-  va_list ap;
-  size_t totalsize;
-  char *p;
-
   /* Determine the total size.  */
-  totalsize = 0;
-  va_copy (ap, args);
-  for (size_t i = argcount; i > 0; i--)
-    {
-      const char *next = va_arg (ap, const char *);
-      totalsize = xsum (totalsize, strlen (next));
-    }
-  va_end (ap);
+  size_t totalsize = 0;
+  {
+    va_list ap;
+    va_copy (ap, args);
+    for (size_t i = argcount; i > 0; i--)
+      {
+        const char *next = va_arg (ap, const char *);
+        totalsize = xsum (totalsize, strlen (next));
+      }
+    va_end (ap);
+  }
 
   /* Test for overflow in the summing pass above or in (totalsize + 1)
      below.  */
@@ -54,16 +52,18 @@ xstrcat (size_t argcount, va_list args)
     xalloc_die ();
 
   /* Allocate and fill the result string.  */
-  result = XNMALLOC (totalsize + 1, char);
-  p = result;
-  for (size_t i = argcount; i > 0; i--)
-    {
-      const char *next = va_arg (args, const char *);
-      size_t len = strlen (next);
-      memcpy (p, next, len);
-      p += len;
-    }
-  *p = '\0';
+  char *result = XNMALLOC (totalsize + 1, char);
+  {
+    char *p = result;
+    for (size_t i = argcount; i > 0; i--)
+      {
+        const char *next = va_arg (args, const char *);
+        size_t len = strlen (next);
+        memcpy (p, next, len);
+        p += len;
+      }
+    *p = '\0';
+  }
 
   return result;
 }
@@ -71,7 +71,6 @@ xstrcat (size_t argcount, va_list args)
 char *
 xvasprintf (const char *format, va_list args)
 {
-  char *result;
 
   /* Recognize the special case format = "%s...%s".  It is a frequently used
      idiom for string concatenation and needs to be fast.  We don't want to
@@ -94,6 +93,7 @@ xvasprintf (const char *format, va_list args)
       }
   }
 
+  char *result;
   if (vaszprintf (&result, format, args) < 0)
     {
       if (errno == ENOMEM)
index f67af437beb0221fc7c7abd672245ab9f2350bf7..41a0dc958b84602ce8d5a2e1716484e76127b95d 100644 (file)
@@ -27,10 +27,8 @@ off64_t
 zprintf (const char *format, ...)
 {
   va_list args;
-  off64_t ret;
-
   va_start (args, format);
-  ret = vfzprintf (stdout, format, args);
+  off64_t ret = vfzprintf (stdout, format, args);
   va_end (args);
 
   return ret;