[SOLVED] warning: array index 1028888 is past the end of the array (which contains 1028888
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
warning: array index 1028888 is past the end of the array (which contains 1028888
Hello everyone! After a lot of research and testing I have opted to write my own id3 tag editor in C, I have wanted to write this for awhile actually; last night just gave me an excuse to do so. I have actually been up for hours debugging and could use some help. I have fixed a few bugs (mainly pointer stuff), but these I am just stumped on I have done some ddging and stack overflow pages; but honestly feel lost. Right now I am trying to do one thing, print out the id3 tag. I only want to do this one thing and after it works I am moving onto the next step and so on. I am trying my best to code from the heap and keep things dynamic (which I am not doing so well and could use some pointers on). I currently have this code:
and when I compile this I get errors which are as follows.
Code:
read.c:9:2: warning: array index 1028888 is past the end of the array (which contains 1028888 elements) [-Warray-bounds]
song_file[1028888] = strlcpy(song_file, argv[1], sizeof(song_file));
^ ~~~~~~~
read.c:8:2: note: array 'song_file' declared here
char song_file[1028888] = "\0";
^
1 warning and 11 errors generated.
I need some help. For
Code:
read.c:9:2: warning: array index 1028888 is past the end of the array (which contains 1028888 elements) [-Warray-bounds]
song_file[1028888] = strlcpy(song_file, argv[1], sizeof(song_file));
^ ~~~~~~~
read.c:8:2: note: array 'song_file' declared here
char song_file[1028888] = "\0";
^
no matter how big I make the array I keep getting this error. I thought initially it was due to all the 30s I I just made it huge for testing, but no luck. I have two questions here, how do I fix this error (why am I getting it) and how would I make this dynamic? All the arrays (especially for the title[] and such) I want to be dynamic IE no cap as those things can get really big in my experience.
no matter how big I make the array I keep getting this error.
Arrays in C are zero based, so an array, declared as containing (i.e.) 100 elements will use member indexes in the range 0 .. 99, you never can have an element with index equal to the array size, the highest element always is 1 less (as the first is the [0] one)
In looking at this on a screen versus on my phone. A far greater shortcut here is to not try to store argv[1] anywhere, but instead to inspect argv[1] to verify that it is a proper path+filename, and then just use argv[1] as the argument for your fopen() call.
How do you *know* that you need to go 30 characters into that string to find what you want? Is that you just truncating away the fully qualify path from it all? You can use the full path, I haven't played with it this much, but I believe you can even use a path like "../../subdir/filename.ext" But I'd have to write some test code.
Either case:[list=1]You selected 1028888. Why? Where'd you get that number, and for a passing argument which is supposed to be a path and name of a file on your system. 128 or 256 characters would seem to be plenty, but then again, my contention is that you do not need the array at all, you can just directly use argv[1]. If the reason you've selected an offset of 30 is because your argv contains, "/path/path/(30 characters worth)/filename, then I suggest just trying to use the path "as is".
In looking at this on a screen versus on my phone. A far greater shortcut here is to not try to store argv[1] anywhere, but instead to inspect argv[1] to verify that it is a proper path+filename, and then just use argv[1] as the argument for your fopen() call.
How do you *know* that you need to go 30 characters into that string to find what you want? Is that you just truncating away the fully qualify path from it all? You can use the full path, I haven't played with it this much, but I believe you can even use a path like "../../subdir/filename.ext" But I'd have to write some test code.
Either case:[list=1]You selected 1028888. Why? Where'd you get that number, and for a passing argument which is supposed to be a path and name of a file on your system. 128 or 256 characters would seem to be plenty, but then again, my contention is that you do not need the array at all, you can just directly use argv[1]. If the reason you've selected an offset of 30 is because your argv contains, "/path/path/(30 characters worth)/filename, then I suggest just trying to use the path "as is".
And how are you debugging? printf()? GDB? Both?
The number was just because I didn't know what was causing the issue and because I never called anything using 0 or even 1 I figured I must be passed the array, but your recommendation to remove it all together worked. Thank you so much
In looking at this on a screen versus on my phone. A far greater shortcut here is to not try to store argv[1] anywhere, but instead to inspect argv[1] to verify that it is a proper path+filename, and then just use argv[1] as the argument for your fopen() call.
How do you *know* that you need to go 30 characters into that string to find what you want? Is that you just truncating away the fully qualify path from it all? You can use the full path, I haven't played with it this much, but I believe you can even use a path like "../../subdir/filename.ext" But I'd have to write some test code.
Either case:[list=1]You selected 1028888. Why? Where'd you get that number, and for a passing argument which is supposed to be a path and name of a file on your system. 128 or 256 characters would seem to be plenty, but then again, my contention is that you do not need the array at all, you can just directly use argv[1]. If the reason you've selected an offset of 30 is because your argv contains, "/path/path/(30 characters worth)/filename, then I suggest just trying to use the path "as is".
And how are you debugging? printf()? GDB? Both?
Yes it works! onless the file has spaces, I'll fix that haha. Thank you again, gotta fix the printing and argv having spaces and then read.c should work!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.