cosmos 3.4.0 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b04a97dbca71b76b18ea80142176aa1546e4f505
4
- data.tar.gz: 33eff7d613a595b3680b7a10d37fce8c36beb1bb
3
+ metadata.gz: 347fbd93cb872161d7b92e30d62926f518dd70c8
4
+ data.tar.gz: 135bbd4fd436113705cd4be89618e104112ac085
5
5
  SHA512:
6
- metadata.gz: 9b37d0e0e7bdaec78e12fdaf98988209b0fdda1ff0a576f937dec3e237b0d9cfe5acf7068eebbf3743debc76ef9a89c9f9768711d574bf95199da6f99f002d05
7
- data.tar.gz: d4bbff05fb3fd13f8851603d6175833fec77758b8ca505fa7236730a9a2f84d4b5ee0dae1e1049a56e331bed2924c8181f31146b0fb18989564e0feaffa85d13
6
+ metadata.gz: fc8d30c9cda59b6f5fe8d29452ff72608aef066ce43304fd4b81b2694cda72c507dac9dcd3af451012850982ae57ba0d9e9bb4f2a368e5072b5b8a7da60cb770
7
+ data.tar.gz: 4c672f1f98fb0bda3da853f1b619465e8c7891796c7df99af4ebd1b6fa7db5220b63831de2c06233af3185cfc270547ad2831676b179d27e110a12e70600e6c8
@@ -234,7 +234,7 @@
234
234
  "lib/cosmos/tools/tlm_viewer/tlm_viewer.rb" 0x1D2090F6
235
235
  "lib/cosmos/system.rb" 0x735DFB42
236
236
  "lib/cosmos/conversions.rb" 0x43679D05
237
- "lib/cosmos/version.rb" 0x577222AD
237
+ "lib/cosmos/version.rb" 0x23E689C5
238
238
  "lib/cosmos/core_ext.rb" 0x1951B346
239
239
  "lib/cosmos/interfaces.rb" 0x7E3EA326
240
240
  "lib/cosmos/processors.rb" 0x5241327D
@@ -875,7 +875,8 @@ static VALUE binary_accessor_write(VALUE self, VALUE value, VALUE param_bit_offs
875
875
  bit_size = RSTRING_LEN(value) * 8;
876
876
  }
877
877
 
878
- if ((!check_bounds_and_buffer_size(bit_offset, bit_size, buffer_length, param_endianness, param_data_type, &lower_bound, &upper_bound)) && (given_bit_size > 0)) {
878
+ if ((!check_bounds_and_buffer_size(bit_offset, bit_size, buffer_length, param_endianness, param_data_type, &lower_bound, &upper_bound)) && (given_bit_size > 0))
879
+ {
879
880
  rb_funcall(self, id_method_raise_buffer_error, 5, symbol_write, param_buffer, param_data_type, param_bit_offset, param_bit_size);
880
881
  }
881
882
 
@@ -902,25 +903,31 @@ static VALUE binary_accessor_write(VALUE self, VALUE value, VALUE param_bit_offs
902
903
  if (given_bit_size <= 0) {
903
904
  end_bytes = -(given_bit_size / 8);
904
905
  old_upper_bound = buffer_length - 1 - end_bytes;
906
+ /* Lower bound + end_bytes can never be more than 1 byte outside of the given buffer */
907
+ if ((lower_bound + end_bytes) > buffer_length)
908
+ {
909
+ rb_funcall(self, id_method_raise_buffer_error, 5, symbol_write, param_buffer, param_data_type, param_bit_offset, param_bit_size);
910
+ }
911
+
905
912
  if (old_upper_bound < lower_bound) {
906
913
  /* String was completely empty */
907
914
  if (end_bytes > 0) {
908
915
  /* Preserve bytes at end of buffer */
909
916
  rb_str_concat(param_buffer, rb_str_times(ZERO_STRING, INT2FIX(value_length)));
910
917
  buffer = (unsigned char*) RSTRING_PTR(param_buffer);
911
- memmove((buffer + lower_bound + value_length), (buffer + lower_bound), value_length);
918
+ memmove((buffer + lower_bound + value_length), (buffer + lower_bound), end_bytes);
912
919
  }
913
920
  } else if (bit_size == 0) {
914
921
  /* Remove entire string */
915
922
  rb_str_update(param_buffer, lower_bound, old_upper_bound - lower_bound + 1, rb_str_new2(""));
916
923
  } else if (upper_bound < old_upper_bound) {
917
924
  /* Remove extra bytes from old string */
918
- rb_str_update(param_buffer, upper_bound + 1, old_upper_bound + 1, rb_str_new2(""));
925
+ rb_str_update(param_buffer, upper_bound + 1, old_upper_bound - upper_bound, rb_str_new2(""));
919
926
  } else if ((upper_bound > old_upper_bound) && (end_bytes > 0)) {
920
927
  /* Preserve bytes at end of buffer */
921
928
  rb_str_concat(param_buffer, rb_str_times(ZERO_STRING, INT2FIX(upper_bound - old_upper_bound)));
922
929
  buffer = (unsigned char*) RSTRING_PTR(param_buffer);
923
- memmove((buffer + upper_bound + 1), (buffer + old_upper_bound + 1), upper_bound - old_upper_bound);
930
+ memmove((buffer + upper_bound + 1), (buffer + old_upper_bound + 1), end_bytes);
924
931
  }
925
932
  } else {
926
933
  byte_size = bit_size / 8;
@@ -1,12 +1,12 @@
1
1
  # encoding: ascii-8bit
2
2
 
3
- COSMOS_VERSION = '3.4.0'
3
+ COSMOS_VERSION = '3.4.1'
4
4
  module Cosmos
5
5
  module Version
6
6
  MAJOR = '3'
7
7
  MINOR = '4'
8
- PATCH = '0'
9
- BUILD = '9a5a2f777b1122ed55b49caf2febf113a223eeaa'
8
+ PATCH = '1'
9
+ BUILD = '2ce089801e159a76caad0b207042e289c6ab3367'
10
10
  end
11
- VERSION = '3.4.0'
11
+ VERSION = '3.4.1'
12
12
  end
@@ -787,6 +787,122 @@ module Cosmos
787
787
  end
788
788
  end
789
789
 
790
+ context "when negative bit size" do
791
+ it "writes a block to an empty buffer" do
792
+ data = ''
793
+ 512.times do |index|
794
+ data << [index].pack("n")
795
+ end
796
+ buffer = ""
797
+ expect { BinaryAccessor.write(data, 0, -16, :BLOCK, buffer, :BIG_ENDIAN, :ERROR) }.to raise_error(ArgumentError, "0 byte buffer insufficient to write BLOCK at bit_offset 0 with bit_size -16")
798
+ end
799
+
800
+ it "handles a huge bit offset with small buffer" do
801
+ data = ''
802
+ 512.times do |index|
803
+ data << [index].pack("n")
804
+ end
805
+ buffer = ""
806
+ expect { BinaryAccessor.write(data, 1024, 0, :BLOCK, buffer, :BIG_ENDIAN, :ERROR) }.to raise_error(ArgumentError, "0 byte buffer insufficient to write BLOCK at bit_offset 1024 with bit_size 0")
807
+ end
808
+
809
+ it "handles an edge case bit offset" do
810
+ data = ''
811
+ 512.times do |index|
812
+ data << [index].pack("n")
813
+ end
814
+ buffer = "\x00" * 127
815
+ expect { BinaryAccessor.write(data, 1024, 0, :BLOCK, buffer, :BIG_ENDIAN, :ERROR) }.to raise_error(ArgumentError, "127 byte buffer insufficient to write BLOCK at bit_offset 1024 with bit_size 0")
816
+ end
817
+
818
+ it "writes a block to a small buffer preserving the end" do
819
+ data = ''
820
+ 512.times do |index|
821
+ data << [index].pack("n")
822
+ end
823
+ preserve = [0xBEEF].pack("n")
824
+ buffer = preserve.clone # Should preserve this
825
+ BinaryAccessor.write(data, 0, -16, :BLOCK, buffer, :BIG_ENDIAN, :ERROR)
826
+ expect(buffer[0..-3]).to eql data
827
+ expect(buffer[-2..-1]).to eql preserve
828
+ data = BinaryAccessor.read(0, data.length*8 + 16, :BLOCK, buffer, :BIG_ENDIAN)
829
+ expect(data).to eql buffer
830
+ end
831
+
832
+ it "writes a block to another small buffer preserving the end" do
833
+ data = ''
834
+ 512.times do |index|
835
+ data << [index].pack("n")
836
+ end
837
+ preserve = [0xBEEF0123].pack("N")
838
+ buffer = "\x00\x01" + preserve.clone # Should preserve this
839
+ BinaryAccessor.write(data, 16, -32, :BLOCK, buffer, :BIG_ENDIAN, :ERROR)
840
+ expect(buffer[0..1]).to eql "\x00\x01"
841
+ expect(buffer[2..-5]).to eql data
842
+ expect(buffer[-4..-1]).to eql preserve
843
+ data = BinaryAccessor.read(0, 16 + data.length*8 + 32, :BLOCK, buffer, :BIG_ENDIAN)
844
+ expect(data).to eql buffer
845
+ end
846
+
847
+ it "writes a block to a small buffer overwriting the end" do
848
+ data = ''
849
+ 512.times do |index|
850
+ data << [index].pack("n")
851
+ end
852
+ preserve = [0xBEEF].pack("n")
853
+ buffer = [0xDEAD].pack("n") # Should write over this
854
+ buffer << preserve.clone # Should preserve this
855
+ BinaryAccessor.write(data, 0, -16, :BLOCK, buffer, :BIG_ENDIAN, :ERROR)
856
+ expect(buffer[0..-3]).to eql data
857
+ expect(buffer[-2..-1]).to eql preserve
858
+ data = BinaryAccessor.read(0, data.length*8 + 16, :BLOCK, buffer, :BIG_ENDIAN)
859
+ expect(data).to eql buffer
860
+ end
861
+
862
+ it "writes a smaller block in the middle of a buffer" do
863
+ data = ''
864
+ buffer = ''
865
+ 256.times do |index|
866
+ data << [index].pack("n")
867
+ end
868
+ 512.times do
869
+ buffer << [0xDEAD].pack("n")
870
+ end
871
+ expected = buffer.clone
872
+ BinaryAccessor.write(data, 128*8, -128*8, :BLOCK, buffer, :BIG_ENDIAN, :ERROR)
873
+ expect(buffer.length).to eql (128 + 512 + 128)
874
+ expect(buffer[0...128]).to eql expected[0...128]
875
+ expect(buffer[128...-128]).to eql data
876
+ expect(buffer[-128..-1]).to eql expected[0...128]
877
+ end
878
+
879
+ it "writes a larger block in the middle of a buffer" do
880
+ data = ''
881
+ buffer = ''
882
+ 256.times do |index|
883
+ data << [index].pack("n")
884
+ end
885
+ 512.times do
886
+ buffer << [0xDEAD].pack("n")
887
+ end
888
+ expected = buffer.clone
889
+ BinaryAccessor.write(data, 384*8, -384*8, :BLOCK, buffer, :BIG_ENDIAN, :ERROR)
890
+ expect(buffer.length).to eql (384 + 512 + 384)
891
+ expect(buffer[0...384]).to eql expected[0...384]
892
+ expect(buffer[384...-384]).to eql data
893
+ expect(buffer[-384..-1]).to eql expected[0...384]
894
+ end
895
+
896
+ it "complains when the negative index exceeds the buffer length" do
897
+ data = "\x01"
898
+ buffer = ''
899
+ 16.times do
900
+ buffer << [0xDEAD].pack("n")
901
+ end
902
+ expect { BinaryAccessor.write(data, 0, -2024*8, :BLOCK, buffer, :BIG_ENDIAN, :ERROR) }.to raise_error(ArgumentError, "32 byte buffer insufficient to write BLOCK at bit_offset 0 with bit_size -16192")
903
+ end
904
+ end
905
+
790
906
  it "writes blocks with negative bit_offsets" do
791
907
  BinaryAccessor.write(@baseline_data[0..1], -16, 16, :BLOCK, @data, :BIG_ENDIAN, :ERROR)
792
908
  expect(@data[-2..-1]).to eql(@baseline_data[0..1])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cosmos
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Melton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-27 00:00:00.000000000 Z
12
+ date: 2015-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler