[llvm-commits] [llvm] r158841 - /llvm/trunk/lib/Support/MemoryBuffer.cpp

David Blaikie dblaikie at gmail.com
Wed Jun 20 13:26:51 PDT 2012


On Wed, Jun 20, 2012 at 1:21 PM, Kaelyn Uhrain <rikka at google.com> wrote:
> Author: rikka
> Date: Wed Jun 20 15:21:33 2012
> New Revision: 158841
>
> URL: http://llvm.org/viewvc/llvm-project?rev=158841&view=rev
> Log:
> Check that a file is not a directory before reading it into a MemoryBuffer.
>
> Modified:
>    llvm/trunk/lib/Support/MemoryBuffer.cpp
>
> Modified: llvm/trunk/lib/Support/MemoryBuffer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/MemoryBuffer.cpp?rev=158841&r1=158840&r2=158841&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/MemoryBuffer.cpp (original)
> +++ llvm/trunk/lib/Support/MemoryBuffer.cpp Wed Jun 20 15:21:33 2012
> @@ -17,6 +17,7 @@
>  #include "llvm/Config/config.h"
>  #include "llvm/Support/MathExtras.h"
>  #include "llvm/Support/Errno.h"
> +#include "llvm/Support/FileSystem.h"
>  #include "llvm/Support/Path.h"
>  #include "llvm/Support/Process.h"
>  #include "llvm/Support/Program.h"
> @@ -214,6 +215,14 @@
>                                  OwningPtr<MemoryBuffer> &result,
>                                  int64_t FileSize,
>                                  bool RequiresNullTerminator) {
> +  // First check that the "file" is not a directory
> +  bool is_dir = false;
> +  error_code err = sys::fs::is_directory(Filename, is_dir);
> +  if (err)
> +    return err;
> +  else if (is_dir)

nitpick http://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return

(oh, hey, look, the coding standards are in new sphinxy stuff. Though
I still think the dragon head logo & color schemes look a bit goofy -
that'll just take some getting used to)

> +    return make_error_code(errc::is_a_directory);
> +
>   int OpenFlags = O_RDONLY;
>  #ifdef O_BINARY
>   OpenFlags |= O_BINARY;  // Open input file in binary mode on win32.
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list