Bus Error Mac
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us
What Is Bus Error 10
Learn more about Stack Overflow the company Business Learn more about hiring developers or bus error 10 c++ posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up bus error in simple Mac OSX C program up vote 1 down vote favorite I am writing a simple C program to create a twelve tone matrix. The code compiles, but I get run time error 'Bus Error'. In the debugger it says EXC_BAD_ACCESS. int main () { int j,k,l; int twelve[13][13]; void mat(int twelve[13][13]); printf("input original tone row \n"); for(j=0;j<=11;j++) { scanf("%2i",&twelve[j][0]); } mat(twelve); for(k=0;k<=11;k++) { for(l=0;l<=11;l++) { printf("%i ",twelve[l][k]); } printf("\n"); } return 0; } void mat(twelve) int twelve[13][13]; { int j,k,l; int temp; /*inversion*/ for(j=1;j<=11;j++) { twelve[0][j] = 12 - twelve[j][0]; } /*fill in columns*/ /*this sections seems to be what's crashing it */ for(k=1;k<=11;k++) { for(l=1;1<=11;l++) { temp = twelve[0][k] + twelve[l][0]; if(temp >= 12) { twelve[k][l] = temp - 12; } else { twelve[k][l] = temp; } } } } c xcode osx exc-bad-access share|improve this question edited Oct 10 '12 at 16:48 athspk 4,97872549 asked Jan 14 '10 at 0:42 Levi 613 Compile with -g or use XCode's debugger, and let us know what line of code has the crash ;v) . –Potatoswatter Jan 14 '10 at 0:46 1 this code gives me the willies. –Stephen Canon Jan 14 '10 at 0:46 Wow, I haven't seen K&R C in ages... –R Samuel Klatchko Jan 14 '10 at 1:13 add a comment| 2 Answers 2 active oldest votes up vote 11 down vote There is a typo in the inner loop condition of the mat() subroutine. This is why I don't like 'l' (el) as an index. for(l=1;1<=11;l++) you meant "l < 11" (el) not "1 < 11" (one) One is always less than eleven, so the
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Mac OS X assembly and sys call causing Bus http://stackoverflow.com/questions/2061445/bus-error-in-simple-mac-osx-c-program Error 10 up vote 0 down vote favorite Trying to run assembly on my Macbook Pro (Intel i7, 64-bit) and have encountered a weird bug. It's a basic "Hello, world!" program only using system calls. SECTION .text global start start: mov rax, 2 shl rax, 24 add al , 4 mov rdi, 1 mov rsi, Msg mov rdx, Len syscall mov al , 1 mov rdi, 0 syscall http://stackoverflow.com/questions/21129890/mac-os-x-assembly-and-sys-call-causing-bus-error-10 SECTION .data Msg db `Hello, world!\n` Len: equ $-Msg Assembled with NASM 2.11 Console commands: nasm -f macho64 -o main.o main.s ld main.o It prints "Hello, world" and the newline character but then returns a Bus Error: 10 (wrong memory address). But if I do: mov rax, 2 shl rax, 24 add al , 1 I don't get a bus error. QUESTION IS: Why can't I change the first byte of rax for the different call using "mov al, 1" osx assembly share|improve this question asked Jan 15 '14 at 5:41 pmbotter 32 Unsure: maybe syscall doesn't preserve rax? –PMF Jan 15 '14 at 5:51 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted The rax register is not preserved by the first syscall so simply setting al to 1 won't give you the right value for the next syscall in rax since it leaves all the upper bits untouched. The method which doesn't give you the bus error is one which re-populates all bits of rax. Since write is meant to return the number of bytes actually written, that comes back in rax, ensuring that you will need to populate it fully for
challenged and removed. (July 2015) (Learn how and when to remove this template message) In computing, a bus error is a fault raised by hardware, notifying an operating system (OS) that a process is trying to access memory that the CPU cannot physically address: https://en.wikipedia.org/wiki/Bus_error an invalid address for the address bus, hence the name. In modern use on most https://forum.openframeworks.cc/t/bus-error-10-segmentation-fault-conversion-from-string-literal-to-char/13282 architectures these are much rarer than segmentation faults, which occur primarily due to memory access violations: problems in the logical address or permissions. On POSIX-compliant platforms, bus errors usually result in the SIGBUS signal being sent to the process that caused the error. SIGBUS can also be caused by any general device fault that the computer detects, though a bus error bus error rarely means that the computer hardware is physically broken—it is normally caused by a bug in a program's source code.[citation needed] Bus errors may also be raised for certain other paging errors; see below. Contents 1 Causes 1.1 Non-existent address 1.2 Unaligned access 1.3 Paging errors 2 Example 3 References Causes[edit] There are at least three main causes of bus errors: Non-existent address[edit] Software instructs the CPU to read or write a specific physical memory address. bus error 10 Accordingly, the CPU sets this physical address on its address bus and requests all other hardware connected to the CPU to respond with the results, if they answer for this specific address. If no other hardware responds, the CPU raises an exception, stating that the requested physical address is unrecognized by the whole computer system. Note that this only covers physical memory addresses. Trying to access an undefined virtual memory address is generally considered to be a segmentation fault rather than a bus error, though if the MMU is separate, the processor can't tell the difference. Unaligned access[edit] Most CPUs are byte-addressable, where each unique memory address refers to an 8-bit byte. Most CPUs can access individual bytes from each memory address, but they generally cannot access larger units (16 bits, 32 bits, 64 bits and so on) without these units being "aligned" to a specific boundary (the x86 platform being a notable exception). For example, if multi-byte accesses must be 16 bit-aligned, addresses (given in bytes) at 0, 2, 4, 6, and so on would be considered aligned and therefore accessible, while addresses 1, 3, 5, and so on would be considered unaligned. Similarly, if multi-byte accesses must be 32-bit aligned, addresses 0, 4, 8, 12, and so on would be considered aligned and therefore accessible, and all addresses in between would be considered unaligne
it works its great but it often crashes on launch. The most common error is Bus error: 10 but I have also had Segmentation fault: 11 and debug always says "Couldn't set thread priority." I think it might be something to do with the Conversion from string literal to 'char *' being deprecated. I think there are probably a few examples of this in my code and that could be causing problems. For example is this wrong. It works but maybe its causing memory issues. void testApp::drawNumbers(){char dataStr[20]; // an array of charssprintf(dataStr, "%d %d %d %d %d %d %d %d", tape[7], tape[6], tape[5], tape[4], tape[3], tape[2], tape[1], tape[0]);franklinBook.drawString(dataStr, 105,335);} All my code seemed much more stable on OSX 10.5.8 and now I seem to have more problems. Are there some core changes I should be aware of. The AddOns I am using areofxOscofxXmlSettingsofxBeatTracking Any tips would really be appreciated. Many thanks Simon trentbrooks 2013-09-20 06:26:26 UTC #2 Hey Simon, I would guess it's the buffer size of 20. You are storing 8 ints and 7 spacer chars, if each int is 2 digits long that's 16 + 7 chars total. You could make the buffer bigger, or just use a stringstream instead... stringstream dataStr;dataStr << tape[7] << " " << tape[6] << " " << endl;franklinBook.drawString(dataStr.str(), 105,335); simonblackmore 2013-09-20 21:00:11 UTC #3 Thanks, Trent I am sure this helps. I seem to have a heap of other troubles.I hate upgrading Cheers Simon Home Categories FAQ/Guidelines Terms of Service Privacy Policy Powered by Discourse, best viewed with JavaScript enabled