1

I wrote a big program in pike, and suddenly it gives me an error it didn't give me before:

bad argument 1 to sizeof().

Does someone know the problem? what can I do? it worked before. That's the code:

int main()
{
  string path;
  path=Stdio.Readline()->read("enter a path");   
  add_module_path(path);
  array fileArr=get_dir(path);
  int i=0;
  int j=0;
  while (j != sizeof(fileArr))
  {
    // ... 
  }
}
Bentaye
  • 9,403
  • 5
  • 32
  • 45
  • `add_module_path(path);` seems unrelated to the example given here. i'd remove it from the example code. – eMBee May 15 '18 at 18:49

1 Answers1

1

if the given path does not exist, then get_dir() will return 0.

0 is an invalid argument to sizeof().

check the relevant values before passing them on.

the simplest in this case:

while (arrayp(fileArr) && j != sizeof(fileArr))

you could also stat() the path before passing it to get_dir()

eMBee
  • 793
  • 6
  • 16