Ошибка 139 компилятор c

Выдает ошибку при решение задачи входные данные 3 1 1 2 1 3 0 #include #include using namespace std; vector<vector> arr; vect...

Выдает ошибку при решение задачи
входные данные
3 1
1 2
1 3
0

    #include <iostream>
    #include <vector>

    using namespace std;

    vector<vector<int>> arr;
    vector<bool> used;

    void dfs(int v) {
        used[v] = true;
        for (auto to : arr[v]) {
            if (!used[to]) {
                dfs(to);
            }
        }
    }

    int main() {
        int n, k;
        cin >> n >> k;
        int z, t;
        arr.resize(n);
        while (true) {
            cin >> z;
            if (z == 0) {
                break;
            }
            cin >> t;
            arr[z - 1].push_back(t - 1);
        }
        dfs(k - 1);
        for (auto i : used) {
            if (!i) {
                cout << "No";
                return 0;
            }
        }
        cout << "Yes";
        return 0;
    }

задан 8 янв 2020 в 18:51

Samyrai's user avatar

1

SIGSEGV — Это ошибка по защите памяти. Т.е. ваша программв пытается обратиться к участку памяти, который ей не принадлежит. В 99% процентах случаев, такая ошибка возникает по двум причинам:

  1. Индекс массива выходит за допустимый диапазон
  2. Указатель получает некое «левое» (или вообще — никакого) значение.

У вас указателей нет, но есть два массива (вектора) с индексами которых далеко не всё очевидно.

Разбираться с ними глядя на код — скучно. Поэтому рекомендую скомпилировать Вашу программу с ключом -g и запустить под отладчиком gdb. Он Вам покажет конкретное место ошибки.

ответ дан 9 янв 2020 в 4:47

Sergey's user avatar

SergeySergey

12.9k12 серебряных знаков26 бронзовых знаков

  • Forum
  • General C++ Programming
  • Error Code 139

Error Code 139

Hello, I am implementing a Hash Table based on a given function. I have coded most of it, but whenever I try to add something to the hash table, I get an error code of 139. I’ve narrowed it down to where it crashes (HashTab.cpp in the add() function), and I would appreciate if someone looked over my code and offered suggestions or a solution to make it not crash anymore. Here is the code:

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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include "HashTab.h"


using namespace std;

void runPrompt();
void addelm(int num);
void remelm(int num);
void search(int num);
void printelm();
void error(string s);

HashTab* hashTab;

//this is where i will store the string tokens
string strarray[10];

int main()
{
	runPrompt();
}

void runPrompt()
{
	string input = "";
	int index;

	while(input != "quit")
	{
	    index = 0;
		cout << "set> ";
		//get the input and split into iss stream
		getline(cin,input);
		istringstream iss(input);

		while(iss)
		{
			//gather strings delimited by ' ' and store in array
			//index starts at 0, so increment after
			iss >> strarray[index];
			index++;
		}

		if(input.find("add") != string::npos)
		{

			//add num aka strarray[1]
           int numadd = atoi(strarray[1].c_str());
            addelm(numadd);
		}

		if(input.find("delete") != string::npos)
		{
			//remove
			//strarray[0] = remove
			//[1] = num
            int numrem = atoi(strarray[1].c_str());
            remelm(numrem);
		}


		if(input.find("print") != string::npos)
		{
			printelm();
		}

        if(input.find("search") != string::npos)
        {
            int searchnum = atoi(strarray[1].c_str());
            search(searchnum);
        }

		if(input.find("quit") != string::npos)
        {
			break;
		}

		if(input.find("quit") == string::npos && input.find("print") == string::npos
                && input.find("delete") == string::npos && input.find("add") == string::npos
                && input.find("search") == string::npos)
		{
			error(input);
		}
	}
}



void printelm()
{
    hashTab->print();
}

void addelm(int num)
{
    hashTab->add(num);
}

void remelm(int num2)
{
    hashTab->rem(num2);
}

void search(int num)
{
    hashTab->search(num);
}

void error(string input)
{
		cout << "Error!  Command not found: " << input <<endl;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "Element.h"

class HashTab
{
    public:
        HashTab();
        void print();
        void add(int);
        bool rem(int);
        bool search(int);
    private:
        Element* elarray[7];
};
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
#include <iostream>

#include "Element.h"
#include "HashTab.h"

using namespace std;

HashTab::HashTab()
{

}

void HashTab::add(int num)
{


    //Error checking to see if number is within range
    if(num < 0 || num > 10)
    {
        cout << "Error! number is out of range (0-9)" << endl;
        return;
    }

    //hash x^2 mod B where B=7
    else
    {
        int key = (num*num) % 7;
        cerr << key << endl;

        for(int i = 0; i < 9; i++)
        {
            if(elarray[key]->getindex(i) == -1)
            {
                cerr << "this is where it faultsn";
                elarray[key]->setindex(i);
                break;
            }

            else
            {
                cout << "Bucket full.n";
            }
        }

    }

}
bool HashTab::rem(int num)
{
    for(int i = 0; i < 6; i++)
    {
        if(elarray[i]->search(num))
        {
            elarray[i]->del(num);
            return true;
        }
    }
    //no match
    return false;
}

bool HashTab::search(int num)
{
    for(int i = 0; i < 6; i++)
    {
        if(elarray[i]->search(num))
        {
            cout << "true" << endl;
        }
    }
}

void HashTab::print()
{
    for(int i = 0; i < 9; i++)
    {
        cout << "(";
        elarray[i]->printinfo();
        cout << ")n";
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef ELEMENT_H
#define ELEMENT_H

#include <iostream>
#include <string>


using namespace std;

class Element
{
    public:
        Element();
        void setindex(int);
        void printinfo();
        void del(int);
        bool search(int);
        int getindex(int);

    private:
        int idarray[10];
};

#endif // ELEMENT_H 
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
#include "Element.h"

using namespace std;

Element::Element()
{
    for(int i = 0; i < 9; i++)
    {
        cerr << i << endl;
        idarray[i] = -1;
    }

}

int Element::getindex(int num)
{
    return idarray[num];
}

void Element::printinfo()
{
    for( int i =0; i < 9; i++)
    {
        if(idarray[i] == -1)
        {
            cout << " ,";
        }

        else
        {
            cout << idarray[i] << ",";
        }
    }
}

bool Element::search(int num)
{
    bool flag = false;
    for(int i = 0; i < 9; i++)
    {
        if(idarray[i] == num)
        {
            flag =  true;
        }
    }

    return flag;
}

void Element::del(int num)
{
    for(int i = 0; i < 9; i++)
    {
        if(idarray[i] == num)
        {
            idarray[i] = -1;
        }
    }
}

void Element::setindex(int num)
{
    bool fullflag = true;
    for(int i = 0; i < 9; i++)
    {
        //not used
        if(idarray[i] == -1)
        {
            idarray[i] = num;
            fullflag = false;
            break;
        }

        if(fullflag)
        {
            cout << "Error!  The bucket for number "<< num << " is full!" << endl;
            break;
        }
    }
}


Please let me know what I am doing wrong.

«Error 16» is meaningless. Error numbers are different for every compiler.

You also don;t make clear if this is a compiler error, or a run time error.

Please post the full error text of the message including the source filename and line number where the error occurred.

Sorry! It’s a run time error. The program itself executes fine. Here is the output when I try to use the add() function.

1
2
3
set>add 1

Program exited with code 139

HashTab* hashTab;
This defines a pointer to a

HashTab

. Later you dereference the pointer without ever making it point to anything valid.

1
2
3
4
5
6
class HashTab
{
    // ...
    private:
        Element* elarray[7];
};

This defines an array of pointers to

Element

in each HashTab instance. Later you use this array without making those pointers point to anything valid.

So just do something like this?
HashTab* hashTab = new HashTab():
and
Element* elarray = new Element[7];

Pointers are still very new to me, and I was under the impression that
HasTab* hashTab
would declare and create a valid pointer to use.

So just do something like this?
HashTab* hashTab = new HashTab();

Something like it.

and
Element* elarray = new Element[7];

elarray

as defined in the code above is an array of 7 pointers-to-

Element

. You could change the definition to something like described here, or you could keep it as you previously had it and make those pointers point to objects, or you could just use a normal array of 7

Element

objects.

Pointers are still very new to me, and I was under the impression that
HasTab* hashTab
would declare and create a valid pointer to use.

It defines a pointer. Given that it is defined at global scope, it is zero-initialized. It is not valid to dereference as it does not point to an existing object.

The thing to remember about pointers is that you shouldn’t use them unless you can’t get around it.

Last edited on

Cool. I kept the HashTab as a pointer and made my Element array out of objects instead. Works like a charm, thank you cire and AbstractionAnon!

Topic archived. No new replies allowed.

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account


Closed

hez2010 opened this issue

Apr 30, 2018

· 14 comments


Closed

error MSB6006: «csc.dll» exited with code 139

#26505

hez2010 opened this issue

Apr 30, 2018

· 14 comments

Assignees

@jcouv

Comments

@hez2010

Version Used:
the version embedded in the dotnet SDK version 2.2.100-preview1-008633 (daily build)

Steps to Reproduce:

  1. edit nuget.config file:
  2. navigate to any folder u like and using «dotnet new console» to create a .net core 2.1 console application
  3. dotnet build

note: my system is ubuntu 16.04 ARM64

Expected Behavior:
successfully build.

Actual Behavior:
…/sdk/2.2.100-preview1-008633/Roslyn/Microsoft.CSharp.Core.targets(52,5): error MSB6006: «csc.dll» exited with code 139. [/home/nvidia/Desktop/test/test.csproj]

build log:s (with -v diag)
log.txt

@jcouv

@hez2010 Here’s what I’d recommend you try:

Here are some steps to see the reason for the compilation failing:

  1. run the problematic build command, but add the option for binary logging /bl (for example, dotnet build /bl)
  2. assuming this reproduced the issue, open the msbuild.binlog file with the binary log viewer.
  3. the log viewer should show the failed Csc task (as shown below)
  4. you can view and copy the command-line arguments to a text file repro.rsp, removing the first two chunks (the first one for «dotnet.exe» and the second one for «csc.dll»)
  5. re-use those two chunks to run dotnet.exe csc.dll @repro.rsp
  6. this should repro, but also print out the compiler diagnostics

image

Tagging @livarcocc, in case he has something to add. Livar, are there any known issues where CLI doesn’t print out the compiler diagnostics? I thought there was one, but it had been fixed.

@jcouv

I didn’t hear back on my request for additional information, so I’ll go ahead and close the issue.
The problem of the error details not getting displayed was fixed in the compiler (#27349) and we’ll have to wait for that fix to make its way into the CLI.
If the problem still occurs, please open an issue with more details. Thanks

@xclud

@jcouv I have the same issue and i did the steps you have wrote above.

The output is:

Microsoft (R) Visual C# Compiler version 2.8.1.62915 (ff873b4b)
Copyright (C) Microsoft Corporation. All rights reserved.

warning CS2023: Ignoring /noconfig option because it was specified in a response file
Segmentation fault (core dumped)

I am running on openSUSE Tumbleweed (JeOS 4.16.6-1-default, aarch64) on a Raspberry PI 3B+. I use .NET Core SDK 2.1.300.

@kxxt

@jcouv

@xclud I will try to find out how to get a stacktrace from a crashed process on Linux.
Is there any chance you could try and repro on windows? (the troubleshooting experience is easier there)

@kxxt Would you be able to share a crash dump of this crash (since you said it was on Windows)? Here are some instructions for turning that one. Then you can share via any online drive. Thanks

@hez2010

@jcouv Actually this issue only occurs on Linux ARM64 system and currently I don’t have the environment to repo it. You can try executing «dotnet build» on Linux ARM64, I think this issue will 100% repo.

@maxbl4

Have the same issue. Just installed dotnet sdk 2.1.302 on a fresh Debian 9 arm64. And any try to build a project results in error from this topic

@gauravagarwal28

I have the same issue on my Jetson TX2 (arm64 — ubuntu 16.04).

@xclud

@jcouv I do not face any issues on Windows. I compile for windows on windows and also cross-compile on windows for linux (x64 and arm64). No problem at all.

To me, the problem happens only when i compile on my raspberry pi.

@jcouv

This is likely an ARM64 runtime issue. Tagging @RussKeldorph for that.

@olgierdd

I have the same issue on ROCK64 V2 4G RAM. I can build project, run dotnet restore. When I run dotnet run for console application I am getting: /home/rock64/dotnet/sdk/2.1.402/Roslyn/Microsoft.CSharp.Core.targets(52,5): error MSB6006: «csc.dll» exited with code 139. [/home/rock64/dev/myApp/myApp.csproj]

The build failed. Please fix the build errors and run again.

@ghost

/opt/dotnet-sdk-2.1.402/sdk/2.1.402/Roslyn/Microsoft.CSharp.Core.targets(52,5): error MSB6006: "csc.dll" exited with code 139.

Build FAILED.

Ubuntu 16.04 AARCH64

@gauravagarwal28

@hyzx86

I have the same problem ,my project run on androd Linux Deploy

Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.9.65-perf+ armv8l)

  • Documentation: https://help.ubuntu.com/
    Ubuntu 16.04 LTS [running via Linux Deploy]
    Last login: Thu Oct 4 13:24:51 2018 from 127.0.0.1
    root@localhost:~#

build error:

Restore completed in 63.74 ms for /home/android/gitCodes/myGit/OrchardCore/test/OrchardCore.Tests.Pages/OrchardCore.Application.Pages/OrchardCore.Application.Pages.csproj.
/home/dotnet/sdk/2.1.403/Roslyn/Microsoft.CSharp.Core.targets(52,5): error MSB6006: «csc.dll» exited with code 139. [/home/android/gitCodes/myGit/OrchardCore/src/OrchardCore/OrchardCore.BackgroundTasks.Abstractions/OrchardCore.BackgroundTasks.Abstractions.csproj]
/home/dotnet/sdk/2.1.403/Roslyn/Microsoft.CSharp.Core.targets(52,5): error MSB6006: «csc.dll» exited with code 139. [/home/android/gitCodes/myGit/OrchardCore/src/OrchardCore/OrchardCore.Data.Abstractions/OrchardCore.Data.Abstractions.csproj]
/home/dotnet/sdk/2.1.403/Roslyn/Microsoft.CSharp.Core.targets(52,5): error MSB6006: «csc.dll» exited with code 139. [/home/android/gitCodes/myGit/OrchardCore/src/OrchardCore/OrchardCore.XmlRpc.Abstractions/OrchardCore.XmlRpc.Abstractions.csproj]
/home/dotnet/sdk/2.1.403/Roslyn/Microsoft.CSharp.Core.targets(52,5): error M

Понравилась статья? Поделить с друзьями:
  • Ошибка 139 ивеко дейли
  • Ошибка 139 iveco daily
  • Ошибка 13868 ошибка сопоставления групповой политики
  • Ошибка 1382 шевроле реззо
  • Ошибка 138102 bmw