Has triggered a breakpoint c ошибка

Zusul

1 / 1 / 1

Регистрация: 22.10.2012

Сообщений: 9

1

21.10.2013, 23:41. Показов 14349. Ответов 2

Метки нет (Все метки)


Студворк — интернет-сервис помощи студентам

Парни C++ только начал изучать как пол года назад. Ссори если не правильно высказываюсь.
Делаю задачку. Не могу врубиться почему компилятор выдает ошибку app.exe has triggered a breakpoint. Компилятор Visual Studio 2013.

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef HEAD_H_
#define HEAD_H_
 
#include<iostream>
 
class String
{
private:
    char * str;
    int len;
 
public:
    String(const char * s);
    String();
    String(const String & s);
    ~String();
    friend String operator+(const String & s1,const String & s2);
    friend std::ostream & operator<<(std::ostream & os, const String & s);
};
#endif
 
 
 
#include"Head.h"
#include<iostream>
#include<cstring>
 
String::String(const char * s)
{
    len = strlen(s);
    str = new char[len + 1];
    strcpy_s(str, len + 1, s);
}
String::String()
{
    str = new char[1];
    str[0] = '';
    len = 0;
}
String::String(const String & st)
{
    
    len = st.len;
    str = new char[len + 1]; 
    strcpy(str, st.str);
}
String::~String()
{
    
    delete [] str;
}
String  operator+(const String & s1, const String & s2)
{
    
    String s3;
    s3.len = strlen(s1.str) + strlen(s2.str);
    strncat_s(s3.str, s3.len + 1, s1.str, strlen(s1.str) );
    strncat_s(s3.str, s3.len + 1, s2.str, strlen(s2.str));
    return s3;
}
 
std::ostream & operator<<(std::ostream & os, const String & s)
{
    os << "The str = " << s.str << std::endl;
    return os;
}
 
#include"Head.h"
#include<iostream>
 
int main()
{
    String First = String("Vovan");
    String Second = String("Anus");
    String Third = String(First + Second);
    std::cout << Third;
    std::cin.get();
    return 0;
}

Заранее благодарен.



0



Убежденный

Ушел с форума

Эксперт С++

16459 / 7423 / 1186

Регистрация: 02.05.2013

Сообщений: 11,617

Записей в блоге: 1

21.10.2013, 23:56

2

Цитата
Сообщение от Zusul
Посмотреть сообщение

C++
1
2
3
4
5
6
7
8
String operator+(const String & s1, const String & s2)
{
String s3;
 s3.len = strlen(s1.str) + strlen(s2.str);
 strncat_s(s3.str, s3.len + 1, s1.str, strlen(s1.str) );
 strncat_s(s3.str, s3.len + 1, s2.str, strlen(s2.str));
 return s3;
}

Не вижу здесь выделения памяти под новую строку.

Кстати, у этого класса еще не хватает оператора присваивания.



1



Zusul

1 / 1 / 1

Регистрация: 22.10.2012

Сообщений: 9

22.10.2013, 13:58

 [ТС]

3

Спасибо большое разобрался!!!
Все теперь работает!

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef HEAD_H_
#define HEAD_H_
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
 
class String
{
private:
    char * str;
    int len;
 
public:
    String(const char * s);
    String();
    String(const String & s);
    ~String();
    String & operator=(const String &) ;
    friend String operator+(const String & s1,const String & s2);
    friend std::ostream & operator<<(std::ostream & os, const String & s);
};
#endif
 
#include"Head.h"
#include<iostream>
#include<cstring>
#define _CRT_SECURE_NO_WARNINGS
String::String(const char * s)
{
    len = strlen(s);
    str = new char[len + 1];
    strcpy_s(str, len + 1, s);
}
String::String()
{
    str = new char[1];
    str[0] = '';
    len = 0;
}
String::String(const String & st)
{
    
    len = st.len;
    str = new char[len + 1]; 
    strcpy(str, st.str);
}
String::~String()
{
    
    delete [] str;
}
String & String::operator=(const String & st)
{
    if (this == &st)
        return *this;
    delete []str;
    len = st.len;
    str = new char[len + 1];
    strcpy_s(str, len + 1, st.str);
    return *this;
}
String  operator+(const String & s1, const String & s2)
{
    
    String s3;
    s3.len = strlen(s1.str) + strlen(s2.str);
    s3.str = new char[s3.len + 1];
    strcpy_s(s3.str, s3.len + 1, s1.str); //strlen(s1.str) + 1);
    strncat_s(s3.str, s3.len + 1, s2.str, strlen(s2.str));// + 1);
    return s3;
}
 
std::ostream & operator<<(std::ostream & os, const String & s)
{
    os << "The str = " << s.str << std::endl;
    return os;
}
 
 
#include"Head.h"
#include<iostream>
 
int main()
{
    String First = String("Vovan");
    String Second = String("Vazilinchik");
    String Third;
    Third = First + Second;
    std::cout << Third;
    std::cin.get();
    return 0;
}



0



I’ve been always working on my software C++ & Java (build with Microsoft Visual Studio 2008 & Eclipse), and I’ve been trying to move it from a 32-bit system to a 64-bit one.

The compilation phase is alright, but on execution I get an error that says:

«Windows has triggered a breakpoint in javaw.exe. This may be due to
corruption of the heap, which indicates a bug in javaw.exe or any of
the DLLs it has loaded-.
This may also be due to user pressing F12 while javaw.exe has focus.
The output window may have more diagnostic information.
[BREAK] [CONTINUE] [IGNORE]»

You can see a snapshot of the error here:

enter image description here

Have you any idea of what this error means?
What does «corruption of the heap» mean?
Have you evere had any experience with this kind of error before?

Thank you so much!

asked Apr 16, 2012 at 10:29

DavideChicco.it's user avatar

DavideChicco.itDavideChicco.it

3,30013 gold badges55 silver badges84 bronze badges

1

It is a very nice feature of the Windows heap allocator, available since Vista. It tells you that your code has a pointer bug. Well, hopefully it is your code and not the JVM that has the bug :) You’d better assume it is your code.

The actual cause ranges somewhere between mild, like trying to free memory that was already freed or allocated from another heap (not uncommon when you interop with another program), to drastically nasty, like having blown the heap to pieces earlier by overflowing a heap allocated buffer.

The diagnostic is not fine-grained enough to tell you exactly what went wrong, just that there’s something wrong. You typically chase it down with a careful code review and artificially disabling chunks of code until the error disappears. Such are the joys of explicit memory management. If the 32-bit version is clean (check it) then this can be associated with 64-bit code due to assumptions about pointer size. A 64-bit pointer doesn’t fit in an int or long, so it is going to get truncated. And using the truncated pointer value is going to trigger this assert. That’s the happy kind of problem, you’ll find the trouble code back in the Call Stack window.

Cody Gray - on strike's user avatar

answered Apr 16, 2012 at 12:48

Hans Passant's user avatar

Hans PassantHans Passant

919k145 gold badges1681 silver badges2525 bronze badges

0

This unfortunately usually means a memory corruption. Some double freeing of memory, function that should return but doesn’t or any other type of undefined behavior.

Your best bet of solving this, unless you have a clue as to where this corruption is, is to use a memory analysis tool.

answered Apr 16, 2012 at 10:38

Luchian Grigore's user avatar

Luchian GrigoreLuchian Grigore

253k64 gold badges457 silver badges621 bronze badges

1

I got it!
Thanks to you all, I understood it was a problem of memory, and maybe of malloc()
In fact, I read here:

The bucket-sizing factor must be a multiple of 8 for 32-bit implementations and
a multiple of 16 for 64-bit implementations in order to guarantee that addresses
returned from malloc subsystem functions are properly aligned for all data types.

IBM.com:

So, I changed the malloc() sizing in the problem point. I went from:

(int**) malloc (const * sizeof(int))

to:

(int**) malloc (const * sizeof(int64_t))

And now it works!

Thanx a lot!

answered Apr 19, 2012 at 12:20

DavideChicco.it's user avatar

DavideChicco.itDavideChicco.it

3,30013 gold badges55 silver badges84 bronze badges

1

Typically that kind of errors occurs when you trying to access the memory you didn’t allocate. Check out all of your allocations (and freeing), especially pointer-to-pointer, and code that can access dinamically allocated memory. In your case size of poiners is 64bit insdead of 32bit, that should be prime cause.

answered Apr 16, 2012 at 10:41

tukaef's user avatar

2

Проблема: Проект состоит из основной программы и дополнительных библиотек. При отладке дополнительных библиотек выскакивает сообщение об ошибке: *.exe has triggered a breakpoint

exe has triggered a breakpoint

Application.exe has triggered a breakpoint

Инструментарий: Visual Studio, C++

Решение: В моем случае, сообщение: .exe has triggered a breakpoint , отобразилось из за того что в основной программе были некритические в данный момент для меня исключения. Для того чтобы отключить данное уведомление нужно:

  • Открыть настройки проекта (Project -> Properties)
  • Изменить свойство «Debugger Type» из «Auto» на «Mixed» (Configuration Properties -> Debugging -> Debugger Type : Mixed)

Visual Studio Project Property Page

Visual Studio Project Property Page

  • Remove From My Forums
  • Question

  • Hello. I have the following problem. When my application is starting the following error occurs: «DelaunayWin32.exe has triggered a breakpoint». Where DelaunayWin32 is the name of my project. This error occurs on ShowWindow(hWnd,
    nCmdShow) function call. But this error does not always appear, but only from time to time, since often my application starts normally. If this error occurs and I click «Retry» button in the error message dialog then I can see the following
    picture:

    I apologize for the Russian-language comments in the source code of the application. Sometimes when I start my application, an error of a slightly different kind appears. Here it is.

    But again, I repeat, such things do not always happen. Sometimes, my application starts up normally. In Stackoverflow, MSDN, and other forums, I read several posts on this topic. But the discussions are so specific to each specific application that
    it is difficult to navigate them. If possible, please direct me in the right direction, that is, in what place of my application should I look for the cause of the error I’m talking about. Of course, I understand that this is not a simple thing,
    since, figuratively speaking, my application does not consist of ten lines of source code. Sometimes a similar error occurs when processing a WM_CLOSE message on a call to the DestroyWindow (hWnd) function. But again, I repeat, this does not always happen.
    Sometimes my application closes normally. If possible, please tell me what is the reason for this error. And from what place in the program I should start searching for the causes of this error. Thanks in advance.

    • Moved by

      Monday, June 29, 2020 1:37 AM

Solution 1

It is a very nice feature of the Windows heap allocator, available since Vista. It tells you that your code has a pointer bug. Well, hopefully it is your code and not the JVM that has the bug :) You’d better assume it is your code.

The actual cause ranges somewhere between mild, like trying to free memory that was already freed or allocated from another heap (not uncommon when you interop with another program), to drastically nasty, like having blown the heap to pieces earlier by overflowing a heap allocated buffer.

The diagnostic is not fine-grained enough to tell you exactly what went wrong, just that there’s something wrong. You typically chase it down with a careful code review and artificially disabling chunks of code until the error disappears. Such are the joys of explicit memory management. If the 32-bit version is clean (check it) then this can be associated with 64-bit code due to assumptions about pointer size. A 64-bit pointer doesn’t fit in an int or long, so it is going to get truncated. And using the truncated pointer value is going to trigger this assert. That’s the happy kind of problem, you’ll find the trouble code back in the Call Stack window.

Solution 2

This unfortunately usually means a memory corruption. Some double freeing of memory, function that should return but doesn’t or any other type of undefined behavior.

Your best bet of solving this, unless you have a clue as to where this corruption is, is to use a memory analysis tool.

Solution 3

I got it!
Thanks to you all, I understood it was a problem of memory, and maybe of malloc()
In fact, I read here:

The bucket-sizing factor must be a multiple of 8 for 32-bit implementations and
a multiple of 16 for 64-bit implementations in order to guarantee that addresses
returned from malloc subsystem functions are properly aligned for all data types.

IBM.com:

So, I changed the malloc() sizing in the problem point. I went from:

(int**) malloc (const * sizeof(int))

to:

(int**) malloc (const * sizeof(int64_t))

And now it works!

Thanx a lot!

Related videos on Youtube

Windows has triggered a breakpoint in Matthias.exe

01 : 25

Windows has triggered a breakpoint in Matthias.exe

Debugging with Breakpoints in Visual Studio

16 : 16

Debugging with Breakpoints in Visual Studio

Assertion failure Visual C++ Runtime Library. Application has encountered a user-defined breakpoint

01 : 30

Assertion failure Visual C++ Runtime Library. Application has encountered a user-defined breakpoint

Fix Microsoft Visual C++ Runtime Library Error In Windows 10 / 11 - 2022

01 : 18

Fix Microsoft Visual C++ Runtime Library Error In Windows 10 / 11 — 2022

Breakpoint will not currently be hit. No symbols loaded for this document in visual studio

01 : 44

Breakpoint will not currently be hit. No symbols loaded for this document in visual studio

Fix lỗi the code execution cannot proceed because msvcp110 dll

03 : 43

Fix lỗi the code execution cannot proceed because msvcp110 dll

🧬 Hướng dẫn khắc phục lỗi không cài được Microsoft Visual C++ 2015

02 : 49

🧬 Hướng dẫn khắc phục lỗi không cài được Microsoft Visual C++ 2015

Fix error: Python Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build

06 : 31

Fix error: Python Microsoft Visual C++ 14.0 is required. Get it with «Microsoft Visual C++ Build

Fix the following components are required to run this program microsoft visual c++ runtime | 2022

02 : 54

Fix the following components are required to run this program microsoft visual c++ runtime | 2022

Hướng dẫn fix"Microsoft Visual C++ Runtime Library"- fix"Microsoft Visual C++ Runtime Library Error"

06 : 25

Hướng dẫn fix»Microsoft Visual C++ Runtime Library»- fix»Microsoft Visual C++ Runtime Library Error»

How to Solved Microsoft Visual C++ Problem in Desktop/Laptop Computer

03 : 22

How to Solved Microsoft Visual C++ Problem in Desktop/Laptop Computer

How to Fix Microsoft Visual C++ 2015 Redistributable Setup Failed error 0x80240017

06 : 15

How to Fix Microsoft Visual C++ 2015 Redistributable Setup Failed error 0x80240017

Comments

  • I’ve been always working on my software C++ & Java (build with Microsoft Visual Studio 2008 & Eclipse), and I’ve been trying to move it from a 32-bit system to a 64-bit one.

    The compilation phase is alright, but on execution I get an error that says:

    «Windows has triggered a breakpoint in javaw.exe. This may be due to
    corruption of the heap, which indicates a bug in javaw.exe or any of
    the DLLs it has loaded-.
    This may also be due to user pressing F12 while javaw.exe has focus.
    The output window may have more diagnostic information.
    [BREAK] [CONTINUE] [IGNORE]»

    You can see a snapshot of the error here:

    enter image description here

    Have you any idea of what this error means?
    What does «corruption of the heap» mean?
    Have you evere had any experience with this kind of error before?

    Thank you so much!

    • This exception can also happen by simply allocating N slots of data (Of any kind) and actually using M>N slots. Everything compiles, but raises an error when ran. Avner

  • I think accessing memory you don’t own would rather break the runtime with an access violation exception.

  • Process may very well own the memory as unallocated part of a heap, I guess that’s what he meant.

  • Neither of your constructs are correct. The general form for invoking malloc is (T*)malloc(count*sizeof(T)). In your specific case, the correct form is (int**)malloc(count*sizeof(int*)).

Recents

Related

Возможно, вам также будет интересно:

  • Harvia электропечь для сауны ошибки
  • Harvia ошибка error 3
  • Harvia ошибка er 3 устранение
  • Harvia xafir cs110 ошибка е3
  • Harvia e9 ошибка ремонт

  • Понравилась статья? Поделить с друзьями:
    0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии