Opened 3 years ago

Closed 3 years ago

#597 closed ожидается проверка (задача сдана)

lab_12 = exceptions

Reported by: petrov.vladimir Owned by: Святослав Власов
Component: WW_exceptions Version: 3.0
Keywords: Cc:

Description


Change History (5)

comment:1 Changed 3 years ago by Святослав Власов

Type: ожидается проверкаожидаются исправления

Не собралось

[501][svloyso:lab_12]$ make
mkdir -p bin
g++ -std=c++98 -Wall -pedantic -c -o bin/matrix.o -Iinclude src/matrix.cpp
src/matrix.cpp: In constructor ‘Matrix::Matrix(std::size_t, std::size_t)’:
src/matrix.cpp:23:26: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
   23 |         for(int i = 1; i < _rows; i ++) {
      |                        ~~^~~~~~~
src/matrix.cpp: In copy constructor ‘Matrix::Matrix(const Matrix&)’:
src/matrix.cpp:48:26: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
   48 |         for(int i = 1; i < _rows; i ++) {
      |                        ~~^~~~~~~
src/matrix.cpp: In member function ‘void Matrix::print(FILE*)’:
src/matrix.cpp:77:22: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
   77 |     for(int i = 0; i < _rows; i++) {
      |                    ~~^~~~~~~
src/matrix.cpp:78:26: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
   78 |         for(int j = 0; j < _cols; j++) {
      |                        ~~^~~~~~~
src/matrix.cpp: In member function ‘Matrix& Matrix::operator+=(const Matrix&)’:
src/matrix.cpp:97:20: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
   97 |   for(int i = 0; i < _rows; i ++) {
      |                  ~~^~~~~~~
src/matrix.cpp:98:24: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
   98 |       for(int j = 0; j < _cols; j++) {
      |                      ~~^~~~~~~
src/matrix.cpp: In member function ‘int** Matrix::multiply_array(const Matrix&, const Matrix&)’:
src/matrix.cpp:128:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘const size_t’ {aka ‘const long unsigned int’} [-Wsign-compare]
  128 |         for (int i = 0; i < m1._rows; i++) {
      |                         ~~^~~~~~~~~~
src/matrix.cpp:132:31: warning: comparison of integer expressions of different signedness: ‘int’ and ‘const size_t’ {aka ‘const long unsigned int’} [-Wsign-compare]
  132 |             for (int j = 0; j < m2._cols; j++) {
      |                             ~~^~~~~~~~~~
src/matrix.cpp:134:38: warning: comparison of integer expressions of different signedness: ‘int’ and ‘const size_t’ {aka ‘const long unsigned int’} [-Wsign-compare]
  134 |                 for(int pos = 0; pos < m1._cols; pos++) {
      |                                  ~~~~^~~~~~~~~~
g++ -std=c++98 -Wall -pedantic -o lab_12 -Iinclude src/main.cpp bin/*
src/main.cpp: In function ‘int main(int, char**)’:
src/main.cpp:18:36: error: ‘to_string’ is not a member of ‘std’; did you mean ‘wstring’?
   18 |       std::string arg = "$" + std::to_string(i);
      |                                    ^~~~~~~~~
      |                                    wstring
src/main.cpp:30:26: error: cannot convert ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} to ‘const char*’
   30 |             my_file.open(arg2, std::ios::in);
      |                          ^~~~
      |                          |
      |                          std::string {aka std::__cxx11::basic_string<char>}
In file included from src/main.cpp:6:
/usr/include/c++/10.2.0/fstream:658:24: note:   initializing argument 1 of ‘void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::ios_base::openmode]’
  658 |       open(const char* __s, ios_base::openmode __mode = ios_base::in)
      |            ~~~~~~~~~~~~^~~
src/main.cpp:67:32: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
   67 |               for(int i = 0; i < rows; i++) {
      |                              ~~^~~~~~
src/main.cpp:68:34: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
   68 |                 for(int j = 0; j < cols; j++) {
      |                                ~~^~~~~~

comment:2 Changed 3 years ago by petrov.vladimir

Type: ожидаются исправленияожидается проверка
Version: 1.02.0

comment:3 Changed 3 years ago by Святослав Власов

Type: ожидается проверкаожидаются исправления

Теперь валгринд детектит лики в каждом тесте

  1. Не все bad_alloc ловишь и оборачиваешь
  2. FILE* и printf -- это прошлый век семестр. Сегодня мы используем ofstream
  3. Зачем так сложно??
    std::vector<size_t> dimensions;
        while (dimensions.size() < 2) {
          size_t d;
          my_file >> d;
          if (my_file.eof())
            break;
          dimensions.push_back(d);
        }
        if(dimensions.size() < 2) {
          my_file.close();
          throw MatrixException("LOAD: invalid file format.");
        }
    
        size_t rows = dimensions[0], cols = dimensions[1];
    

Это всё переписывается двумя строчками:

if (!(my_file >> rows >> cols;))
  throw MatrixException(...);

То же самое касается дальнейшей фигни с каунтерами.
Когда поток пытается что-то прочитать и у него не получается, он переходит в состояние fail, из которого обратно уже не возвращается (если только у него явно не вызвать clear). Поэтому проверять поток после каждого чтения бессмысленно. Можно сделать это в конце один раз. Если поток в порядке, то значит все чтения прошли успешно, а если нет -- то где-то мы сломались и можно швыряться эксепшенами.

comment:4 Changed 3 years ago by petrov.vladimir

Type: ожидаются исправленияожидается проверка
Version: 2.03.0

comment:5 Changed 3 years ago by Святослав Власов

Resolution: задача сдана
Status: assignedclosed

Валгринд по прежнему детектит утечки в каждом тесте, потому что ты матрицы в регистрах перед выходом из программы не освободил.

Вообще, у тебя бы сильно упростился код, если бы ты заюзал вектора.

В остальном вроде всё ок, 9/10

Note: See TracTickets for help on using tickets.