Skip to content

Commit

Permalink
Fix a Ruby warning and Style/PercentLiteralDelimiters (#38)
Browse files Browse the repository at this point in the history
* Turn on warning
* Add Style/PercentLiteralDelimiters back
* Fix(?) codeclimate issue
  • Loading branch information
david942j authored Mar 8, 2019
1 parent e6ada5c commit 9a453ac
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 20 deletions.
1 change: 1 addition & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins:
enabled: true
exclude_paths:
- spec/
- lib/elftools/constants.rb
checks:
method-lines:
enabled: false
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*.gem
/.yardoc/
/coverage/
/doc/
/.yardoc/
/pkg/

Gemfile.lock
4 changes: 4 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--color
--order rand
--require spec_helper
--warning
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,3 @@ Naming/UncommunicativeMethodParamName:

Style/FormatStringToken:
Enabled: false

Style/PercentLiteralDelimiters:
Enabled: false
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
language: ruby
sudo: required
os:
- linux
- osx
Expand Down
5 changes: 1 addition & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ RuboCop::RakeTask.new(:rubocop) do |task|
task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
end

RSpec::Core::RakeTask.new(:spec) do |task|
task.pattern = './spec/**/*_spec.rb'
task.rspec_opts = ['--color', '--require spec_helper', '--order rand']
end
RSpec::Core::RakeTask.new(:spec)

YARD::Rake::YardocTask.new(:doc) do |t|
t.files = ['lib/**/*.rb']
Expand Down
2 changes: 1 addition & 1 deletion lib/elftools/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def initialize(header, stream, offset)
# Name of this note.
# @return [String] The name.
def name
return @name if @name
return @name if defined?(@name)

stream.pos = @offset + SIZE_OF_NHDR
@name = stream.read(header.n_namesz)[0..-2]
Expand Down
12 changes: 6 additions & 6 deletions spec/elf_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
end

it 'names' do
expect(@elf.sections.map(&:name)).to eq [''] + %w(
expect(@elf.sections.map(&:name)).to eq [''] + %w[
.interp .note.ABI-tag .note.gnu.build-id .gnu.hash
.dynsym .dynstr .gnu.version .gnu.version_r
.rela.dyn .rela.plt .init .plt .plt.got .text
.fini .rodata .eh_frame_hdr .eh_frame .init_array
.fini_array .jcr .dynamic .got .got.plt .data .bss
.comment .shstrtab .symtab .strtab
)
]

expect(@elf.section_by_name('.shstrtab')).to be @elf.strtab_section
expect(@elf.section_by_name('no such section')).to be nil
Expand All @@ -50,15 +50,15 @@
it 'symbols' do
# symbols from .dynsym
section = @elf.section_by_name('.dynsym')
expect(section.symbols.map(&:name)).to eq [''] + %w(
expect(section.symbols.map(&:name)).to eq [''] + %w[
puts __stack_chk_fail printf __libc_start_main
fgets __gmon_start__ scanf stdin
)
]

# symbols from .symtab
section = @elf.section_by_name('.symtab')
# Too many symbols, only test non-empty names
expect(section.symbols.map(&:name).reject(&:empty?)).to eq %w(
expect(section.symbols.map(&:name).reject(&:empty?)).to eq %w[
crtstuff.c __JCR_LIST__ deregister_tm_clones register_tm_clones
__do_global_dtors_aux completed.7588 __do_global_dtors_aux_fini_array_entry
frame_dummy __frame_dummy_init_array_entry source.cpp _ZZ4funcvE4test
Expand All @@ -70,7 +70,7 @@
_Z4funcv __gmon_start__ __dso_handle _IO_stdin_used __libc_csu_init
_end _start s __bss_start main scanf@@GLIBC_2.2.5 _Jv_RegisterClasses
__TMC_END__ _ITM_registerTMCloneTable _init
)
]

# can use 'be' here becauase they should always refer to same object
expect(section.symbol_by_name('_init')).to be section.symbols.last
Expand Down
6 changes: 3 additions & 3 deletions spec/full_test/relro_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
section = @partial.section_by_name('.rela.plt')
symtab = @partial.section_at(section.header.sh_link)
symbols = section.relocations.map(&:r_info_sym).map { |c| symtab.symbol_at(c).name }
expect(symbols).to eq %w(puts __stack_chk_fail printf __libc_start_main fgets scanf)
expect(symbols).to eq %w[puts __stack_chk_fail printf __libc_start_main fgets scanf]

section = @nrelro.section_by_name('.rela.plt')
symtab = @nrelro.section_at(section.header.sh_link)
Expand All @@ -51,11 +51,11 @@
section = @partial.section_by_name('.rela.dyn')
symtab = @partial.section_at(section.header.sh_link)
symbols = section.relocations.map(&:r_info_sym).map { |c| symtab.symbol_at(c).name }
expect(symbols).to eq %w(__gmon_start__ stdin)
expect(symbols).to eq %w[__gmon_start__ stdin]

section = @frelro.section_by_name('.rela.dyn')
symtab = @frelro.section_at(section.header.sh_link)
frelro_symbols = section.relocations.map(&:r_info_sym).map { |c| symtab.symbol_at(c).name }
expect(frelro_symbols).to eq %w(puts __stack_chk_fail printf __libc_start_main fgets __gmon_start__ scanf stdin)
expect(frelro_symbols).to eq %w[puts __stack_chk_fail printf __libc_start_main fgets __gmon_start__ scanf stdin]
end
end

0 comments on commit 9a453ac

Please sign in to comment.